Skip to content
This repository was archived by the owner on Sep 21, 2018. It is now read-only.

Commit 3171428

Browse files
aegyed91MikeRyanDev
authored andcommitted
feat(reducer): Add ngrx-store-freeze to guarantee immutability
1 parent 28ddbae commit 3171428

3 files changed

Lines changed: 10 additions & 2 deletions

File tree

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
"karma-sourcemap-loader": "^0.3.7",
8484
"karma-typescript-preprocessor": "0.0.21",
8585
"karma-webpack": "^1.7.0",
86+
"ngrx-store-freeze": "^0.1.0",
8687
"promise-loader": "^1.0.0",
8788
"raw-loader": "0.5.1",
8889
"source-map-loader": "^0.1.5",

src/reducers/index.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ import { compose } from '@ngrx/core/compose';
2323
*/
2424
import { storeLogger } from 'ngrx-store-logger';
2525

26+
/**
27+
* storeFreeze prevents state from being mutated. When mutation occurs, an
28+
* exception will be thrown. This is useful during development mode to
29+
* ensure that none of the reducers accidentally mutates the state.
30+
*/
31+
import { storeFreeze } from 'ngrx-store-freeze';
32+
2633
/**
2734
* combineReducers is another useful metareducer that takes a map of reducer
2835
* functions and creates a new reducer that stores the gathers the values
@@ -63,7 +70,7 @@ export interface AppState {
6370
* wrapping that in storeLogger. Remember that compose applies
6471
* the result from right to left.
6572
*/
66-
export default compose(storeLogger(), combineReducers)({
73+
export default compose(storeFreeze, storeLogger(), combineReducers)({
6774
search: searchReducer,
6875
books: booksReducer,
6976
collection: collectionReducer

src/reducers/search.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export default function(state = initialState, action: Action): SearchState {
2323
case BookActions.SEARCH: {
2424
const query = action.payload;
2525

26-
return Object.assign(state, {
26+
return Object.assign({}, state, {
2727
query,
2828
loading: true
2929
});

0 commit comments

Comments
 (0)