Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WithCalls new props callWith and defaultResult #151

Open
gabrielguerrero opened this issue Dec 21, 2024 · 1 comment
Open

WithCalls new props callWith and defaultResult #151

gabrielguerrero opened this issue Dec 21, 2024 · 1 comment

Comments

@gabrielguerrero
Copy link
Owner

Add to new properties to the typedCallConfig of withCalls

  • defaultResult, will allow the user to initialize the result property of the call, and makes the result prop non nullable

  • callWith: Allow to reactively execute the call with the provided params.Supports the following:

    • A direct parameter value. Which execute the call once on init.
    • A Signal or Observable emitting the parameter of the call or undefined.
    • A function returning the parameter or undefined.By default, when withCall is function or signalor observable that returns a falsy value it will skip the call.To override this behavior, the user can define a skipWhen with its own rule or skipWhen: () => false to always execute on any value.

    Examples

    withCalls((store) => ({
    loadProducts: typedCallConfig({
      call: () => inject(ProductService).getProducts(),
      storeResult: false,
      // initial to an empty array
      defaultResult: { resultList: [], total: 0 },
      onSuccess: (result) => {
        patchState(store, setEntities(result.resultList, { collection }));
      },
      // call on init without any arguments
      callWith: undefined,
    }),
    })),
    withCalls(({ productsEntitySelected }) => ({
    loadProductDetail: typedCallConfig({
      call: ({ id }: { id: string }) =>
        inject(ProductService).getProductDetail(id),
      resultProp: 'productDetail',
     // call when a product is selected, or skip the call if undefined
      callWith: () =>
        productsEntitySelected()
          ? { id: productsEntitySelected()!.id }
          : undefined,
    }),
    checkout: () => inject(OrderService).checkout(),
    })),
gabrielguerrero pushed a commit that referenced this issue Dec 21, 2024
new callWithParams prop allows reactively call the method when other signals or observables change

Fix #151
gabrielguerrero pushed a commit that referenced this issue Dec 21, 2024
…p to initialize result

new callWithParams prop allows reactively call the method when other signals or observables change

Fix #151
gabrielguerrero pushed a commit that referenced this issue Jan 13, 2025
…p to initialize result

new callWithParams prop allows reactively call the method when other signals or observables change

Fix #151
gabrielguerrero pushed a commit that referenced this issue Jan 25, 2025
…p to initialize result

new callWithParams prop allows reactively call the method when other signals or observables change

Fix #151
gabrielguerrero pushed a commit that referenced this issue Jan 25, 2025
…p to initialize result

new callWithParams prop allows reactively call the method when other signals or observables change

Fix #151
gabrielguerrero pushed a commit that referenced this issue Jan 25, 2025
…p to initialize result

new callWithParams prop allows reactively call the method when other signals or observables change

Fix #151
Copy link

🎉 This issue has been resolved in version 19.0.0-beta.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant