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

  • Mastering Immutable.js
  • Adam Boduch
  • 126字
  • 2021-07-08 10:30:09

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.

主站蜘蛛池模板: 运城市| 永丰县| 景洪市| 大竹县| 周宁县| 眉山市| 临颍县| 图木舒克市| 阿图什市| 梧州市| 肃北| 双辽市| 罗平县| 潼关县| 黎城县| 沈丘县| 大邑县| 南溪县| 白玉县| 阿图什市| 车致| 兴义市| 米脂县| 景谷| 霍山县| 商河县| 永定县| 平阳县| 平定县| 安平县| 化德县| 平泉县| 阿克苏市| 刚察县| 宜君县| 北流市| 盈江县| 镇平县| 南投市| 永福县| 广平县|