官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 长葛市| 临猗县| 镶黄旗| 封开县| 石狮市| 合山市| 沁水县| 名山县| 南京市| 昆明市| 莱西市| 基隆市| 桑植县| 遂昌县| 湖南省| 姜堰市| 兰州市| 图片| 诸城市| 汝南县| 衡阳市| 宜昌市| 贵南县| 鹿泉市| 轮台县| 阿坝| 鄂尔多斯市| 湟中县| 北安市| 太仓市| 张家港市| 张家口市| 邮箱| 扶沟县| 罗源县| 巴马| 驻马店市| 顺义区| 大方县| 阿坝| 汝城县|