Nietzsche's Preposterous Moustache
Unleash awesomeness. Private packages, team management tools, and powerful integrations. Get started with npm Orgs »

ngrx-store-freeze

0.2.4 • Public • Published

ngrx-store-freeze

npm version CircleCI

ngrx-store-freeze is a meta-reducer that prevents state from being mutated

  • Recursively freezes the current state, the dispatched action payload if provided and the new state.
  • When mutation occurs, an exception will be thrown.
  • Should be used only in development to ensure that the state remains immutable.

Installation

npm i --save-dev ngrx-store-freeze

OR

yarn add ngrx-store-freeze --dev

Setup

import { StoreModule, MetaReducer, ActionReducerMap } from '@ngrx/store';
import { storeFreeze } from 'ngrx-store-freeze';
import { environment } from '../environments/environment'; // Angular CLI environment
 
export interface State {
  // reducer interfaces
}
 
export const reducers: ActionReducerMap<State> = {
  // reducers
}
 
export const metaReducers: MetaReducer<State>[] = !environment.production ? [storeFreeze]: [];
 
@NgModule({
  imports: [
    StoreModule.forRoot(reducers, { metaReducers }),
  ]
})
export class AppModule {}

Additional Documentation

Credits

redux-freeze - Redux middleware that prevents state from being mutated
Attila Egyed - The original maintainer of this project

install

npm i ngrx-store-freeze

Downloadsweekly downloads

47,604

version

0.2.4

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
  • avatar
Report a vulnerability