Parsing complex structures

The real power of the fromJS() function is its ability to turn complex JavaScript objects into complex immutable collections:

const myMap = fromJS({
a: {
b: ['c', 'd'],
e: {
f: 'g',
h: 'i'
}
}
});
console.log(
'myMap nested list',
myMap.getIn(['a', 'b']).toJS()
);
// -> myMap nested list [ 'c', 'd' ]

console.log('myMap nested value', myMap.getIn(['a', 'b', 1]));
// -> myMap nested value d

The fromJS() function will recursively transform native JavaScript structures into their immutable counterparts; this means for both lists and maps. One use case for this function is when the initial data that your application uses is based on JSON data, and you need a way to translate it into Immutable.js collections. Without fromJS(), this would be deceptively difficult.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.226.28.197