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

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.

主站蜘蛛池模板: 慈利县| 平度市| 英超| 二手房| 肃宁县| 安达市| 会同县| 汝城县| 长泰县| 连城县| 曲沃县| 凉城县| 陵川县| 河间市| 祁连县| 南华县| 瓮安县| 武宣县| 蚌埠市| 秀山| 崇州市| 庆云县| 桐庐县| 黔东| 宾阳县| 芦山县| 新沂市| 昆明市| 金坛市| 渝北区| 汽车| 长沙市| 靖宇县| 大悟县| 监利县| 瑞丽市| 榆社县| 扎赉特旗| 乡城县| 白银市| 定边县|