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

Passing JavaScript collections

You can pass native JavaScript collections, such as objects and arrays, to Immutable.js collections, such as maps and lists. This is one way to provide immutable collections with initial values. For example, you can pass the list constructor an array, as follows:

const myList = List([1, 2, 3]);
console.log('myList', myList.get(1));
// -> myList 2

The Map constructors work the same way, except you pass it an object:

const myMap = Map({ a: 1, b: 2, c: 3 });
console.log('myMap', myMap.get('b'));
// -> myMap 2
Passing array or object literals to Immutable.js collections like this is fine. You should avoid passing in references to arrays or objects, however. The reason is that once you create an Immutable.js collection, the data is supposed to be immutable. If you have a reference to a mutable array or object in your code, this just leads to confusion.
主站蜘蛛池模板: 烟台市| 福海县| 南宁市| 都江堰市| 五家渠市| 乌海市| 汶川县| 商都县| 那坡县| 历史| 闵行区| 白朗县| 保德县| 洪雅县| 伊宁县| 肃南| 湟源县| 元江| 青海省| 礼泉县| 台湾省| 枣庄市| 财经| 田东县| 南召县| 定安县| 罗定市| 平湖市| 饶河县| 通道| 宾川县| 鲁山县| 哈尔滨市| 确山县| 顺平县| 犍为县| 池州市| 河津市| 汉阴县| 天台县| 吴川市|