Using ngrx store freeze

  • The problem with mutability is that if we do it in the reducer, there won’t be any error, but the store subscribers and selectors won’t be triggered. Hence it’s imp. to enforce immutability of store, so that mutating throws compile time error allowing us to fix it and make reducers pure functions and store immutable.
  • This is not recommended in prod, as it uses Object.freeze, which is not supported by all browsers.

Slides:

code changes:

import { storeFreeze } from 'ngrx-store-freeze';
StoreModule.provideStore(compose(storeFreeze, reducer))

ref: https://angular-university.io/lesson/angular-ngrx-immutability-in-reducer-functions-how-to-use-the-ngrx-store-freeze-library

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s