Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/brandonroberts/ngrx-store-freeze
@ngrx/store meta reducer that prevents state from being mutated.
https://github.com/brandonroberts/ngrx-store-freeze
angular ngrx
Last synced: 2 days ago
JSON representation
@ngrx/store meta reducer that prevents state from being mutated.
- Host: GitHub
- URL: https://github.com/brandonroberts/ngrx-store-freeze
- Owner: brandonroberts
- License: mit
- Created: 2016-07-30T12:37:28.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-06-06T03:35:10.000Z (over 6 years ago)
- Last Synced: 2024-12-19T20:24:48.574Z (4 days ago)
- Topics: angular, ngrx
- Language: TypeScript
- Size: 58.6 KB
- Stars: 200
- Watchers: 9
- Forks: 10
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## ngrx-store-freeze
[![npm version](https://badge.fury.io/js/ngrx-store-freeze.svg)](https://badge.fury.io/js/ngrx-store-freeze)
[![CircleCI](https://circleci.com/gh/brandonroberts/ngrx-store-freeze/tree/master.svg?style=svg&circle-token=6ba0f6b74d2186f7896a58377b8607346c07cee6)](https://circleci.com/gh/brandonroberts/ngrx-store-freeze/tree/master)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
```sh
npm i --save-dev ngrx-store-freeze
```OR
```sh
yarn add ngrx-store-freeze --dev
```### Setup
```ts
import { StoreModule, MetaReducer, ActionReducerMap } from '@ngrx/store';
import { storeFreeze } from 'ngrx-store-freeze';
import { environment } from '../environments/environment'; // Angular CLI environmentexport interface State {
// reducer interfaces
}export const reducers: ActionReducerMap = {
// reducers
}export const metaReducers: MetaReducer[] = !environment.production ? [storeFreeze]: [];
@NgModule({
imports: [
StoreModule.forRoot(reducers, { metaReducers }),
]
})
export class AppModule {}
```## Additional Documentation
* [Usage with `@ngrx/router-store`](./docs/docs.md#router-store-compatibility)
## Credits
[redux-freeze](https://github.com/buunguyen/redux-freeze) - Redux middleware that prevents state from being mutated
[Attila Egyed](https://github.com/tsm91) - The original maintainer of this project