@ngrx/data - Allow getWithQuery() to replace the whole state instead of merging into it #3088
Replies: 11 comments 12 replies
-
I would like to second this. In a more general sense, it's pretty hard to figure out how to replace the cache, or even not use it entirely in the store (the latter I still haven't figured out yet). I'm using @ngrx/data for its removing boilerplate concerning actions, reducers, and selectors, not necessarily client-side caching. |
Beta Was this translation helpful? Give feedback.
-
I'm no ngrx/data expert but have you tried the following? If that's not the case, I think you could (should?) write custom reducers https://ngrx.io/guide/data/entity-reducer#customizing-entity-reducer-behavior |
Beta Was this translation helpful? Give feedback.
-
@timdeschryver Yeah, it's possible to write own reducers, but I also have to write own effects and if I write everything by myself there is no point in using ngrx/data at all. Especially for a feature which is very common and adds only one option and maybe 2-3 lines of code in the sources of ngrx/data. Because the actions are already there. I only have no possibility to tell the |
Beta Was this translation helpful? Give feedback.
-
If it can be added to ngrx/data, I think you can create a PR for it and we can discuss there (or here). |
Beta Was this translation helpful? Give feedback.
-
Another possible solution is to inject a custom EntityChangeTracker that just overwrites the state. What would be nice to have in that case is to derive EntityChangeTrackerBase, but there's a possible obstacle with the merging query upserts, because they use the private function |
Beta Was this translation helpful? Give feedback.
-
I would also love to see this feature added. I can't think of a use case for the default behaviour. I always want to replace the cache with the query results, but maybe that's just me. In the meantime, as a quick and dirty way around it, I call |
Beta Was this translation helpful? Give feedback.
-
If someone wants to create a PR for this that provides some flexibility, that would be good. |
Beta Was this translation helpful? Give feedback.
-
I have just tested out setting the
So I feel like this is doing what the OP is asking for. |
Beta Was this translation helpful? Give feedback.
-
@tr1stan As the OP i can say it's not what I meant. There should be an option to replace ALL data, not only the entries that exist in the returned data. |
Beta Was this translation helpful? Give feedback.
-
I'm surprised this issue hasn't had more interest. Two issues arise from not having a load with query type function:
If there's no workaround other than clearCache (which is causing the second issue for me currently), is there a good idea of how best to tackle this problem? I'm willing to try myself, if I could get some pointers. I'm guessing a loadWithQuery method, that combines the functionality from load and getWithQuery. |
Beta Was this translation helpful? Give feedback.
-
I just ran into the same problem, has anyone found a proper workaround since? |
Beta Was this translation helpful? Give feedback.
-
When using
getWithQuery()
there are situations where I want to replace the whole state instead of extending it. For example if I have a table with filters or pagination and I use getWithQuery to send the new query params to the server. Then the response should replace the whole state, otherwise I can't filter which entries belong to the currently activated filters.Describe any alternatives/workarounds you're currently using
I couldn't find any good workaround for this. At first I thought the option
readonly mergeStrategy?: MergeStrategy;
does what I wanted to do, but no. This is just confusing because of the naming.If accepted, I would be willing to submit a PR for this feature
[x] Yes (Assistance is provided if you need help submitting a pull request)
[ ] No
Beta Was this translation helpful? Give feedback.
All reactions