[Javascript] Manage Application State with Immutable.js
Learn how Immutable.js data structures are different from native iterable Javascript data types and why they provide an excellent foundation on which to build your application's state.
Instead of them being mutable, they're always immutable, meaning they don't change from underneath you. The reference to them can change, but the data inside them cannot, which means you can build predictable and reliable state models on top of them. It becomes a lot easier to manage your application's state.
console.clear(); const ary = ["todo1", "todo2"];
const ary2 = ary;
console.log(ary[0]); // todo1 ary2[0] = "done1";
console.log(ary[0]); // done1 // Immutable function updateState(immutable, pos, value) {
return immutable.set(pos, value);
} const immutableState = Immutable.List(["foo1", "foo2"]);
const immutableState2 = immutableState.set(0, "bar1"); console.log(immutableState.get(0)); // foo1
console.log(immutableState2.get(0)); // bar1
Every time you use set() to set a new value, Immutable will return a new array.
[Javascript] Manage Application State with Immutable.js的更多相关文章
- [React] Use React Context to Manage Application State Through Routes
We’ll create a Router component that will wrap our application and manage all URL related state. We’ ...
- Immutable.js – JavaScript 不可变数据集合
不可变数据是指一旦创建就不能被修改的数据,使得应用开发更简单,允许使用函数式编程技术,比如惰性评估.Immutable JS 提供一个惰性 Sequence,允许高效的队列方法链,类似 map 和 f ...
- [Javascript] Creating an Immutable Object Graph with Immutable.js Map()
Learn how to create an Immutable.Map() through plain Javascript object construction and also via arr ...
- [Immutable.js] Converting Immutable.js Structures to Javascript and other Immutable Types
Immutable.js provides several conversion methods to migrate one structure to another. Each Immutable ...
- [Immutable.js] Using fromJS() to Convert Plain JavaScript Objects into Immutable Data
Immutable.js offers the fromJS() method to build immutable structures from objects and array. Object ...
- 大话immutable.js
为啥要用immutable.js呢.毫不夸张的说.有了immutable.js(当然也有其他实现库)..才能将react的性能发挥到极致!要是各位看官用过一段时间的react,而没有用immutabl ...
- Redux进阶(Immutable.js)
更好的阅读体验 更好的阅度体验 Immutable.js Immutable的优势 1. 保证不可变(每次通过Immutable.js操作的对象都会返回一个新的对象) 2. 丰富的API 3. 性能好 ...
- Immutable.js 以及在 react+redux 项目中的实践
来自一位美团大牛的分享,相信可以帮助到你. 原文链接:https://juejin.im/post/5948985ea0bb9f006bed7472?utm_source=tuicool&ut ...
- React+Immutable.js的心路历程
这段时间做的项目开发中用的是React+Redux+ImmutableJs+Es6开发,总结了immutable.js的相关使用姿势: Immutable Data 顾名思义是指一旦被创造后,就不可以 ...
随机推荐
- smarty 模板 数字自动添加
section: section的产生是为解决foreach的不足的,与foreach一样,它用于设计模板内的循环块,它较为复杂,可极大程序上满足程序需要,所以在程序中我习惯使用它而不使用foreac ...
- ab基本用法
ab的全称是ApacheBench,是 Apache 附带的一个小工具,专门用于 HTTP Server 的benchmark testing,可以同时模拟多个并发请求.前段时间看到公司的开发人员也在 ...
- Xcode-01ARC / Block
1.nonatomic 2.assign 3.strong 4.weak 5.instancetype 6.@class @property 使部分类在编译时不使用ARC -(可以让这们支持 reta ...
- 转载:如何避免代码中的if嵌套
http://top.jobbole.com/4960/ http://stackoverflow.com/questions/24430504/how-to-avoid-if-chains 在Sta ...
- jquery学会的
1.$("#id") $("xxxxx") (input, body) $(".class") 2. $("#id xxx ...
- 使用spm build 批量打包压缩seajs 代码
一,安装环境 1.安装spm spm工具是基于node(nodejs的服务平台)的,因此我们需要先安装 node 和 npm 下载地址:http://nodejs.org/#download.下载完成 ...
- ireport常见问题
$V{PAGE_NUMBER} 表示当前是第几页 ,在text field 的 选项evaluation time选report是共几页,now表是当前页.页码可在ireport里直接设置. &quo ...
- rest开发
http://www.mkyong.com/webservices/jax-rs/download-json-from-jax-rs-with-jaxb-resteasy/ http://blog.j ...
- Android List<Map<String,String>转json(例子)
package com.armslee.json.test.cases; import java.util.ArrayList; import java.util.HashMap; import ja ...
- Git简明手册
文/AbnerKang(简书作者)原 文链接:http://www.jianshu.com/p/d7a7ba4f2341?utm_campaign=maleskine& utm_content ...