Guest User

Untitled

a guest
Jan 16th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. Record.constructor.prototype.fromJS = function(values) {
  2. var nested = fromJS(values, function(key, value){
  3. //See https://facebook.github.io/immutable-js/docs/#/fromJS for docs on custom reviver functions
  4. if(this.prototype[key] && this.prototype[key].constructor.prototype instanceof Record){
  5. return this.prototype[key].constructor.fromJS(value.toJS()); //use toJS() here if nest more than once
  6. }
  7. else {
  8. return value;
  9. }
  10. }.bind(this));
  11. console.log()
  12. return this(nested);
  13. };
  14.  
  15. import { fromJS, mergeDeep, OrderedMap, Record } from 'immutable'
  16.  
  17. // Putting the suggested function here doesn't seem to do anything
  18. // I must be missing some steps to get fromJS() to work with this
  19. // wrapper code.
  20.  
  21. const mergeEntities = (state, payload) => {
  22. return state.merge(payload.map( (id) => new Entity(id) ))
  23. }
  24.  
  25. return mergeEntities(state, fromJS(action.payload.entities));
Add Comment
Please, Sign In to add comment