Skip to content

NgRx/Entity - When to spread, when to not spread, that is the question... #3608

Answered by twittwer
mikerentmeister asked this question in Q&A
Discussion options

You must be logged in to vote

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.

const selectFeature = createFeatureSelector();
const { selectEntities } = entityAdapter.getSelectors(selectFeature);

on(actionA, state => ({ ...state, entities: { ...state.entities }, isLoading: true }))
on(actionB, state => ({ ...state, isLoading: true }))
  • actionA
    • selectFeature: would be executed & emit new value
    • selectEntities: would be executed because of selectFeature emission and because the entities reference changed it will emit as well
  • actionB
    • selectFeature:…

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@mikerentmeister
Comment options

@mikerentmeister
Comment options

@twittwer
Comment options

@mikerentmeister
Comment options

Answer selected by mikerentmeister
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants