NgRx/Entity - When to spread, when to not spread, that is the question... #3608
-
After I had an experience yesterday detailed in this discussion, I have a question about when it might be good to not spread the state. My state and reducers for entities looks like this:
Seeing as how the store of entities could be quite large, and nothing is changing with them, would it be a redux anti-pattern to decided to not spread the whole state? I know that NgRx uses distinctUntilChanged underneath the hood for its selectors. That will work great for the primitive values, but not so much for the entities dictionary. So theoretically would it be acceptable to modify the reducers to look something like this instead, so that distinctUntilChanged wouldn't fire for the entities?
I know that this technically breaks immutability, so I was thinking maybe this would be a viable option instead, to play more by the rules and create a new object, but still not trip the distinctUntilChanged:
What are your thoughts? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
From my understanding the entities will stay the same when doing the spread.
|
Beta Was this translation helpful? Give feedback.
From my understanding the entities will stay the same when doing the spread.
An explicit selector for the entities object, like provided by EntityAdapter, would not emit when spreading the state but reusing the entities.
actionA
selectFeature
: would be executed & emit new valueselectEntities
: would be executed because ofselectFeature
emission and because the entities reference changed it will emit as wellactionB
selectFeature
:…