Immutable.js

Posted 不骄不傲

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Immutable.js相关的知识,希望对你有一定的参考价值。

Immutable.js它内部实现了一套完整的 Persistent Data Structure

 

fromJS()


将数组或者对象转换为Immutable

let map=Immutable.fromJS({
        a:1,
        b:2
    });
    let list=Immutable.fromJS([
        {
            a:1,
            b:2
        }
    ]);
    console.log(map);
    console.log(list);

 

is()


检测是否相等,和Object.is()是有区别的

let map1=Immutable.Map({a:1});
    let map2=Immutable.Map({a:1});
    console.log(map1===map2);   //false
    console.log(Object.is(map1,map2));  //false
    console.log(Immutable.is(map1,map2));   //true

  

List是个索引集合


 

List.isList() 判断是否为List集合

let list=Immutable.List([1,2,3]);
    console.log(Immutable.List.isList(list));   //true

List.of()创建一个集合

console.log(Immutable.List.of([1,2,3]));

List大小

let list=Immutable.List([1,2,3]);
    console.log(list.size); //3
    console.log(list.count());  //3

获取List索引元素

console.log(list.get(0));
    console.log(list.get(-1));  //反向索引

  

以上是关于Immutable.js的主要内容,如果未能解决你的问题,请参考以下文章

[Immutable.js] Converting Immutable.js Structures to Javascript and other Immutable Types

[Immutable.js] Exploring Sequences and Range() in Immutable.js

[Immutable.js] Working with Subsets of an Immutable.js Map()

[Immutable.js] Lightning Fast Immutable.js Equality Checks with Hash Codes

[Immutable.js] Differences between the Immutable.js Map() and List()

[Immutable.js] Transforming Immutable Data with Reduce