Skip to content

Instantly share code, notes, and snippets.

@alexandrebodin
Last active August 4, 2016 19:17
Show Gist options
  • Save alexandrebodin/6a4901bec28b840baec8d963daa94be2 to your computer and use it in GitHub Desktop.
Save alexandrebodin/6a4901bec28b840baec8d963daa94be2 to your computer and use it in GitHub Desktop.
// Welcome! require() some modules from npm (like you were using browserify)
// and then hit Run Code to run your code on the right side.
// Modules get downloaded from browserify-cdn and bundled in your browser.
var Immutable = require('immutable');
const b = new Immutable.Record({
id: null,
name: null,
});
const newB = new b();
console.log(newB.toJS());
const newA = newB.set('id', 10);
console.log(newA.toJS());
console.log(newB.toJS());
const wrapper = (immutableData) => {
const history = [immutableData];
let currentVal = immutableData;
return {
history,
update: (fn) => {
const newVal = fn(currentVal);
history.push(newVal);
currentVal = newVal;
return this;
},
toJS: () => currentVal.toJS()
}
};
const myData = wrapper(newA);
state.update(record => {
return record.set('id', 100);
});
console.log(myData.toJS());
console.log(myData.history);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment