immutable-js-objects
v1.0.1
Published
change your objects innner state safely using immutable objects
Downloads
3
Maintainers
Readme
Immutable objects
sometimes you come across a situation where you need to copy a variable content of type object (Object, Array) into an other one and work with both copies in the same module or in the same document. When you try to immute the state of one variable the change is immediately incorporated into the other copy as javascript is also a language where objects are passed by reference. So here comes immutable objects to solve immutability issue and it's a good match when you have a complex object structure containing multiple objects and arrays.
Installation && usage
npm install --save immutable-js-objects
- then using commonJs or ES6 import statement
var immutableObjects= require('immutable-js-objects')
// or
import immutableObjects from 'immutable-js-objects'
Code Demo
// considering you have this object
var object= {
name: 'cloud',
age: 20,
identity: {
number: 'NO123',
city: 'Boston',
adress: 'xxxxx123'
},
hobbies: [{id: 0, label: 'hockey'},{id: 1, label: 'tennis'},{id: 2, label: 'football'}]
}
// in the normal case you would do
var object2= object
// using immutable-objects
var object2= immutableObjects(object)
// Now you will have a new Object whose objects references points at new values with new adresses in memory
Tests
npm test
// Or
grunt test