上QQ阅读APP看书,第一时间看更新
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.