[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 顾名思义是指一旦被创造后,就不可以 ...
随机推荐
- 知识管理(knowledge Management)2
①找到生命的主轴 ②跨领域知识管理
- 不支持关键字: “userid”。
运行程序提示:不支持关键字: “userid”. 找了很久在一篇博客里面提示web.config数据库字符串链接出错.
- ios开发之C语言第一天
最近在学习ios开发,先学习C语言,再学习OC和swift.正所谓"万丈高楼平地起",打好基础是很重要的,所以C语言也必须好好学习.学习中所使用的操作系统是OS X,开发工具是Xc ...
- CALayer 为什么选择 cg 开头 而 不选择 UI 开头
CALayer 的属性 为什么选择 cg 开头 而 不选择 UI 开头 , 也就是说 为啥要选择 比如 .CGColor 等
- iOS: 填充数据表格
功能:创建一个列表并填充 // // main.m // Hello // // Created by lishujun on 14-8-28. // Copyright (c) 2014年 lish ...
- Ubuntu14.04 和 Windows7 双系统安装
用了一个暑假,我原来的Ubuntu终于挂了,连gnome桌面器都进不去了,索性重装整个Ubuntu.至少这次我知道什么都升级是一个很糟糕的行为. 由于笔者的电脑原来是Win8预装机,所以各种地方都是的 ...
- QQ 群也能接收告警啦!团队沟通力 Up Up!
截止到昨天,你已经可以通过 OneAlert 的「排班」和「分派」功能,来对告警进行有序地分发,解决团队协作效率低的问题了.然而 OneAlert 觉得自己还可以更进一步,把团队沟通困难的问题也解决掉 ...
- Delphi常用排序
1.冒泡排序 Delphi/Pascal code ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 procedure BubbleSort(var x:a ...
- Scanner 与 Readable 的read()方法
Readable接口中的read()方法实现了将字符串读入charBuffer中,但是只有在需要输出的时候才会调用. Scanner是文本扫描器类,利用Scanner扫描并输出charBuffer中的 ...
- ifstream文件尾最后一行读两次
看下面一段代码: ifstream m_fileConfig; string str; m_fileConfig.open(FILE_OPERATORS, ios::out ...