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

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.

主站蜘蛛池模板: 乌海市| 高清| 棋牌| 沂水县| 东平县| 文化| 达孜县| 临海市| 清水河县| 红桥区| 班玛县| 金堂县| 富裕县| 格尔木市| 山丹县| 曲阜市| 屏东市| 建宁县| 临泽县| 乐东| 东台市| 汝阳县| 恩施市| 兰州市| 桐乡市| 吉水县| 平罗县| 沧源| 磐石市| 孟津县| 洮南市| 松原市| 高清| 离岛区| 杭锦旗| 广平县| 扎鲁特旗| 潍坊市| 临安市| 绩溪县| 克东县|