ngrx / platform

Reactive State for Angular
https://ngrx.io
Other
8.01k stars 1.97k forks source link

Disable cache merging in favour of replacing with @ngrx/data #2749

Closed Nvveen closed 3 years ago

Nvveen commented 3 years ago

Currently, it's pretty unclear how to get @ngrx/data to replace the entity cache for various operations. I have an API endpoint that exposes /resource with for example an optional _search_ parameter, and it's unclear to me how to have theEntityCollectionService.getWithQuery` method result in the entities in the store simply being replaced, as the filtering is done server-side. There is the confusingly named Change Tracking but it's for local state changes.

What I would like to see is 1) Improved documentation or a how-to to replace default classes so replacing in the store is default behaviour. 2) A way to toggle the default merging of local and server-side collections by replacing local with remote outright.

Currently, the only solution I can see is overriding EntityCollectionBase.getWithQuery with a derived class that calls super.getWithQuery, but not before super.clearCache(), but this would have to be done for every service method.

P.S. I am using @ngrx/data for its boilerplate removing of actions, reducers, and selectors, but I currently have no need for change tracking and/or its caching behaviour.

timdeschryver commented 3 years ago

I'm closing this, I think this is a duplicate of #2730.