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

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.
主站蜘蛛池模板: 玉树县| 清徐县| 宾阳县| 大荔县| 时尚| 普洱| 南康市| 论坛| 来宾市| 曲阳县| 永福县| 油尖旺区| 迁西县| 盐边县| 射阳县| 子长县| 牙克石市| 罗田县| 灵武市| 海伦市| 恩平市| 海晏县| 固安县| 汤原县| 绍兴县| 华阴市| 称多县| 澎湖县| 嘉义县| 伊宁市| 阿坝县| 三原县| 汶上县| 景德镇市| 绵阳市| 宣城市| 天津市| 织金县| 石渠县| 当阳市| 九寨沟县|