Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Record.constructor.prototype.fromJS = function(values) {
- var nested = fromJS(values, function(key, value){
- //See https://facebook.github.io/immutable-js/docs/#/fromJS for docs on custom reviver functions
- if(this.prototype[key] && this.prototype[key].constructor.prototype instanceof Record){
- return this.prototype[key].constructor.fromJS(value.toJS()); //use toJS() here if nest more than once
- }
- else {
- return value;
- }
- }.bind(this));
- console.log()
- return this(nested);
- };
- import { fromJS, mergeDeep, OrderedMap, Record } from 'immutable'
- // Putting the suggested function here doesn't seem to do anything
- // I must be missing some steps to get fromJS() to work with this
- // wrapper code.
- const mergeEntities = (state, payload) => {
- return state.merge(payload.map( (id) => new Entity(id) ))
- }
- return mergeEntities(state, fromJS(action.payload.entities));
Add Comment
Please, Sign In to add comment