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

  • 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.

主站蜘蛛池模板: 军事| 行唐县| 平潭县| 防城港市| 武穴市| 临猗县| 曲松县| 肥西县| 中宁县| 石楼县| 台前县| 广河县| 徐州市| 浪卡子县| 福州市| 内黄县| 郯城县| 澜沧| 专栏| 特克斯县| 安仁县| 革吉县| 六枝特区| 临沧市| 永年县| 清涧县| 镇安县| 阆中市| 巴中市| 江达县| 双流县| 崇信县| 聂拉木县| 威海市| 建平县| 孟连| 白水县| 钟祥市| 滦平县| 红河县| 察隅县|