Open
Description
I am using ng-redux with angular 1 application and my store does not use immutable.js at this moment. I am wondering how to make the store immutable and do affect the performance with toJS calls in the controller. I especially concert with calling toJS on each store update in mapStateToProps function. I saw the in react community people use reselect to solve similar concerns. I am wondering if reselect can be also used with ng-redux?
As alternative I am currently playing with idea to use _.memoize in my mapToState function to check if specific slice on store in immutable store has been changed. I am wondering if somebody already use immutable.js with angular 1 and how?
//Let say i have the following store
let state = Immutable.fromJS({categories: {1: 'a',2: 'b'},links: [1,2,3]});
// my component has binding only to categories sub-store in html view
let key = 'categories';
// mapStateTpProp will call toJS ONLY then category has been changed.
let shouldBindingUpdate = _.memoize((sliceObj, fn) => fn());
function mapStateTpProp(state) {
return shouldBindingUpdate(state.get(key), () => {
console.log('toJS called');
return state.getIn([key]).toJS()
});
}
// the first time mapStateTpProp is called and toJS is called
mapStateTpProp(state);
// links subtree has been changed and therefore toJS should not be called since the component cares only about 'categories'
state = state.setIn(['links', '1'], 10);
mapStateTpProp(state);
// reducer changes categories substate in the store and toJS should be called to update view
state = state.setIn(['categories', '1'], 'new Value');
mapStateTpProp(state);
Metadata
Metadata
Assignees
Labels
No labels