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

withEntitiesHybridFilter #160

Open
gabrielguerrero opened this issue Jan 31, 2025 · 1 comment
Open

withEntitiesHybridFilter #160

gabrielguerrero opened this issue Jan 31, 2025 · 1 comment

Comments

@gabrielguerrero
Copy link
Owner

withEntitiesHybridFilter is intended to fill a use case not well handled by withEntitiesLocalFilter or withEntitiesRemote filter, where the we have a filter that have some properties that should trigger a remote filter some that have do a local filter.
For example a product list that has a search box to filter products name locall but it also has a dropdown with product categories, that on change will reload the list from the backend with a different set of products

export const store = signalStore(
  withEntities({ entity, collection }),
  withCallStatus({ prop: collection, initialValue: 'loading' }),
  withEntitiesHybridFilter({
    entity,
    collection,
    defaultFilter: { name: '' , category: ''},
    filterFn: (entity, filter) =>
       (!filter.name || entity.name.toLowerCase().includes(filter.name.toLowerCase()))
    // in this case the filter will call setProductsLoading() if the category changes, othewise
    // it will filter the entities locally using the filterFn
    isRemoteFilter: (previous, current) => {
         return previous.category !== current.category;
    }
  }),
  // after you can use withEntitiesLoadingCall to connect the filter to
  // the api call, or do it manually as shown withEffect or withCalls
   withEntitiesLoadingCall({
    collection,
    fetchEntities: ({ productsFilter }) => {
      return inject(ProductService)
        .getProducts({
          category: productsFilter().category,
        })
    },
  }),
 }));
gabrielguerrero pushed a commit that referenced this issue Jan 31, 2025
New store feature to handle filter cases where some of the filter props should trigger a remote filter and some a local filter

Fix #160
gabrielguerrero pushed a commit that referenced this issue Feb 1, 2025
New store feature to handle filter cases where some of the filter props should trigger a remote filter and some a local filter

Fix #160
gabrielguerrero pushed a commit that referenced this issue Feb 1, 2025
New store feature to handle filter cases where some of the filter props should trigger a remote filter and some a local filter

Fix #160
gabrielguerrero pushed a commit that referenced this issue Feb 1, 2025
New store feature to handle filter cases where some of the filter props should trigger a remote filter and some a local filter

Fix #160
Copy link

github-actions bot commented Feb 1, 2025

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

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