Immutable.js 2.3.0 发布,不可变数据集合
第29期OSC源创会#南京#开始报名,AngularJS、Netty 等
Immutable.js 2.3.0 发布,此版本现已提供下载,更新内容如下:
迭代器!
所有序列,包括 concrete collections (Map, Vector, Set) 和 lazy Sequences (mapped, filtered) 都可以被迭代。
API:
values()
returns an iterator object where each call to next()
provides the next value.
keys()
returns an iterator object where each call to next()
provides the next key.
entries()
returns an iterator object where each call to next()
provides the next entry as a [key, value] tuple.
示例:
var myMap = Immutable.Map([['A', 1], ['B', 2], ['C', 3]]);var entries = myMap.entries();entries.next() // { value: ['A', 1], done: false }entries.next() // { value: ['B', 2], done: false }entries.next() // { value: ['C', 3], done: false }entries.next() // { value: undefined, done: true }
所有的序列通过 @@iterator
和 Symbol.iterator
方法都可以进行迭代,所以可以在 ES6 中使用。
新特性
interpose()
Sequence documentation is easier to follow now that methods are categorized and alphabetized.
A number of lazy sequence optimizations. For example,
seq.flip().reverse().flip()
becomesseq.reverse()
.Optimizations that allow
get()
andhas()
to be O(1) on lazy sequences.
Bugs 修复
Equality checking via
Immutable.is
orseq.equals()
could throw or incorrectly return false.
Immutable 是 Facebook 开发的不可变数据集合。不可变数据一旦创建就不能被修改,是的应用开发更简单,允许使用函数式编程技术,比如惰性评估。Immutable JS 提供一个惰性 Sequence,
允许高效的队列方法链,类似 map
和 filter
,不用创建中间代表。
immutable
通过惰性队列和哈希映射提供 Sequence
, Range
, Repeat
, Map
, OrderedMap
, Set
和一个稀疏 Vector
。