NgRx Store Mutation Quirks

    • We know that Reducer needs the current state, and the action (with Payload) to create the new state
    • Note that while dispatching the action, we don’t pass it the current state, but instead only the action type and the payload.
    • The job of providing the reducer with the current state resides with ngRx.
    • Similarly, the reducer only returns the new state, and doesn’t interact with the store. The job of updating the store also is done by ngRx implicitly.
    • If the reducer doesn’t emit a new Store, and instead mutates a deep property of the store, then the subscriber observing that property of the store doesn’t get notified…
    • Hence always use the spread operator or object.assign to clone the original store before updating it inside the reducer

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s