• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

sebmarkbage/ecmascript-immutable-data-structures

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

sebmarkbage/ecmascript-immutable-data-structures

开源软件地址:

https://github.com/sebmarkbage/ecmascript-immutable-data-structures

开源编程语言:


开源软件介绍:

Immutable Records, Vectors, Maps and Sets for ECMAScript

Immutability and referential transparency has many known benefits and ability for optimization. Several modern JavaScript libraries take advantage of this, and many more functional compile-to-JS languages.

This is based upon the Value Types proposal (Typed Objects / Explainer).

All these types provide value equality for both == and ===.

Record

Records are a new value type that represents the value type analogy of an immutable object.

const xy = #{ x: 1, y: 2 }; // frozen value type
const xyz = #{ ...xy, z: 3 }; // functional extension

Immutable Vector

ImmutableVector is a new value type that represents the value type analogy of an immutable array, without holes. It cannot be sparse.

const xy = #[ x, y ]; // frozen value type
const xyz = #[ ...xy, z ]; // functional extension

Immutable Map

ImmutableMap is an immutable version of Map. Any mutable operation returns a new ImmutableMap instead of mutating the existing reference.

const a = ImmutableMap([['x', 1], ['y', 2]]);
const b = a.set('y', 3);
a.get('y'); // 2
b.get('y'); // 3

Immutable Set

ImmutableSet is an immutable version of Set. Any mutable operation returns a new ImmutableSet instead of mutating the existing reference.

const a = ImmutableSet([1, 2]);
const b = a.add(3);
a.size; // 2
b.size; // 3

Status of this Proposal

This was presented to TC39 in 2015 but the value of having it in the engine is still unproven and this is a large implementation burden for VMs. It effectively doubles the existing data structures. Therefore, we need to gather more arguments for why it needs to be included in the language and how it would be used.

Known Issues

See why this matters.




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap