The problem with ngRx store is that it’s not immutable out of the box. Hence, when you use subscribe/select operators to get the state, you’ll always end up getting a reference and not a copy of the state.
Hence, on changing the local copy will actually end up mutating the store.
To fix this, following changes need to be made:
- Make the store immutable by using immutableJS or ngRx store freeze
- When you’re selecting/subscribing to the store, make sure that you Don’t change it (coz that’ll break at runtime coz immutableJS will not allow the reference to mutate) OR if you absolutely have to change it, then first make a deep copy of the state before changing the copy