Skip to content

Instantly share code, notes, and snippets.

@dmsnell
Created August 15, 2015 18:08
Show Gist options
  • Select an option

  • Save dmsnell/e2c0e437cce57c36c457 to your computer and use it in GitHub Desktop.

Select an option

Save dmsnell/e2c0e437cce57c36c457 to your computer and use it in GitHub Desktop.
var Immutable = require( 'immutable' );
var initialData,
updatedData,
partialData;
initialData = {
status: 200,
image: {
height: 64,
width: 64,
url: null
}
};
updatedData = {
status: 200,
image: {
height: 32,
width: 64,
url: 'https://www.gravatar.com/avatar/ad516503a11cd5ca435acc9bb6523536?s=32'
}
};
partialData = {
image: {
height: 32,
url: 'https://www.gravatar.com/avatar/ad516503a11cd5ca435acc9bb6523536?s=32',
comment: 'Lucky shot!'
}
}
var settings = Immutable.fromJS( initialData );
console.log( settings );
updatedSettings = settings.mergeDeep( updatedData );
console.log( updatedSettings );
partialSettings = updatedSettings.mergeDeep( partialData );
console.log( partialSettings );
console.log( updatedSettings === partialSettings );
setInSettings = settings.setIn( ['status'], 500 );
noSetSettings = settings.setIn( ['status'], 200 );
console.log( setInSettings );
console.log( setInSettings === settings );
console.log( noSetSettings );
console.log( noSetSettings === settings );
newSettings = settings.mergeDeep( { message: 'Hello, World!' } );
console.log( newSettings );
@dmsnell

dmsnell commented Aug 15, 2015

Copy link
Copy Markdown
Author

Run with node ImmutableTest.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment