Comments (4)
You can create a meta-reducer that wraps storeFreeze
to selectively freeze based on the action type. I'm going to add a built-in API to blacklist/whitelist freezing of state in future release. Working example with current code below to ignore actions dispatched by @ngrx/router-store
version 4.x.
import { Action, ActionReducer, MetaReducer } from '@ngrx/store';
import { storeFreeze } from 'ngrx-store-freeze';
export function freezer(reducer: ActionReducer<any>): ActionReducer<any> {
const exclusions: RegExp[] = [
/^ROUTER_/
];
return function(state: any, action: Action): any {
const excluded = exclusions.reduce((current, next) => {
const isExcluded = Boolean(action.type.match(next));
return current || isExcluded;
}, false);
if (excluded) {
return reducer(state, action);
}
return storeFreeze(reducer)(state, action);
};
}
export const metaReducers: MetaReducer<any>[] = !environment.production ? [freezer] : [];
from ngrx-store-freeze.
I have the same problem. some injectors are saved in the store. it should be mutable. I guess for those none serializable states, there is a possibility that they are mutable.
from ngrx-store-freeze.
There is no problem with saving mutable state in the store.
The problem is that you cannot deep freeze the part of state that is pure in development mode.
Thats what the issue is about.
By deactivating the deepfreeze you are good to go.
from ngrx-store-freeze.
I have in some of my actions a route object of the ActivatedRoute type, my solution in ngrx 7 thanks to @brandonroberts was the following:
export function freezer(reducer: ActionReducer<any>): ActionReducer<any> {
const exclusions: RegExp[] = [/^@ngrx\/router-store\//, /^\[Router\]/];
function hasActivatedRoute(action: Action & { payload?: any }) {
return (action.payload && action.payload.route) || false;
}
return function(state: any, action: Action): any {
const excluded = exclusions.reduce((current, next) => {
const isExcluded = Boolean(action.type.match(next)) || hasActivatedRoute(action);
return current || isExcluded;
}, false);
if (excluded) {
return reducer(state, action);
}
return storeFreeze(reducer)(state, action);
};
}
from ngrx-store-freeze.
Related Issues (20)
- Update to NgRx 4 HOT 22
- Project Adoption HOT 4
- Document in README how to create custom RouterStateSerializer HOT 1
- Cannot freeze array buffer views with elements HOT 1
- Freezing the payload can make application crash, expecially with RouterStore HOT 2
- Incorrect example in readme HOT 6
- wrongly freeze when an object which has a getter is in the store HOT 1
- Update Peer Dependency to NgRx 5.x
- The objects are getting frozen too soon HOT 7
- Should the storeFreeze replace an undefined state with an empty object?
- ngrx store freeze error HOT 3
- This library assumes that all Action's will have a 'payload' attribute HOT 1
- Why not use in production? HOT 1
- ngrx v6 compatibility HOT 3
- npm WARN [email protected] requires a peer of @ngrx/store@>=4.0.0 but none is installed. You must install peer dependencies yourself. HOT 1
- Required Ngrx/store version 6.0.0-beta.1 HOT 1
- TypeError: Cannot add property, object is not extensible HOT 3
- [Notice] This package will no longer be needed as of NgRx version 8
- Using isDevMode() throws error Function calls are not supported in decorators but 'isDevMode' was called in 'metaReducers'
- Cannot add property _resolvedData, object is not extensible HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ngrx-store-freeze.