[Javascript] Modifying an Immutable.js Map()
We will now look at five methods that modify an Immutable.Map().
- set
- update
- delete
- clear
- merge
//set()
var map = Immutable.Map();
var todo = {
id: +new Date(),
name: "todo1",
content: "learning Immutable"
}
map = map.set(todo.id, todo);
var task = map.get(todo.id);
console.log(task.content); //"learning Immutable" //update
var map = Immutable.Map();
var todo = {
id: +new Date(),
name: "todo1",
content: "learning Immutable"
}
map = map.set(todo.id, todo);
todo.content = "RxJS";
var task = map.update(todo.id, function(todo){
return todo;
});
console.log(task.get(todo.id).content); //"RxJS" //delete
var map = Immutable.Map();
var todo = {
id: +new Date(),
name: "todo1",
content: "learning Immutable"
};
map = map.delete(todo.id, todo);
console.log(map.size); // //clear
var map = Immutable.Map(); var todo1= {
id: +new Date(),
name: "todo1",
content: "learning Immutable"
}; var todo2= {
id: +new Date() + 1000,
name: "todo1",
content: "learning Immutable"
}; map = map.set(todo1.id, todo1);
map = map.set(todo2.id, todo2);
console.log(map.size); //
map = map.clear();
console.log(map.size); // //merge
var map1 = Immutable.Map({a: '10'});
var map2 = Immutable.Map({b: '20'}); map = map1.merge(map2);
console.log(map.toString()); //"Map { \"a\": \"10\", \"b\": \"20\" }" var map1 = Immutable.Map({a: '10'});
var map2 = Immutable.Map({a: '20'}); map = map1.merge(map2);
console.log(map.toString()); //"Map { \"a\": \"20\" }"
[Javascript] Modifying an Immutable.js Map()的更多相关文章
- [Javascript] Querying an Immutable.js Map()
Learn how to query an Immutable.Map() using get, getIn, has, includes, find, first and last. These a ...
- [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] Differences between the Immutable.js Map() and List()
The Immutable.js Map() is analogous to a Javascript Object or Hash since it is comprised of key-valu ...
- [Immutable.js] Working with Subsets of an Immutable.js Map()
Immutable.js offers methods to break immutable structures into subsets much like Array--for instance ...
- [Immutable,js] Iterating Over an Immutable.js Map()
Immutable.js provides several methods to iterate over an Immutable.Map(). These also apply to the ot ...
- Immutable.js – JavaScript 不可变数据集合
不可变数据是指一旦创建就不能被修改的数据,使得应用开发更简单,允许使用函数式编程技术,比如惰性评估.Immutable JS 提供一个惰性 Sequence,允许高效的队列方法链,类似 map 和 f ...
- [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 ...
- [Javascript] Manage Application State with Immutable.js
Learn how Immutable.js data structures are different from native iterable Javascript data types and ...
- [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 ...
随机推荐
- Python 手册——参数传递以及交互模式
我们先来看参数传递. 调用解释器时,脚本名和附加参数之传入一个名为sys.argv的字符串列表.没有脚本和参数时,它至少也有一个 元素:sys.argv[0]此时为空字符串.脚本名指定为‘ - ’(表 ...
- Meditation Guide
Meditation “Stop!!!” don’t we just scream[vi. 尖叫:呼啸:发出尖锐刺耳的声音:令人触目惊心 ] this in our minds when the da ...
- Python快速排序
快排,取一个key值,一般取第一个即可,将小于key的放到左边,大于key的放到右边,递归实现 import random def quicksort(data, low = 0, high = No ...
- Chain of Responsibility
比较经典的距离是请假申请(<大话设计模式>中的例子),请假是要逐级判断,只有级别到了才有权利审批,从构造上面其实"装饰"模式和"职责链"之间有相通的 ...
- id类型
id类型 在Objective-C 中,id 类型是一个独特的数据类型.在概念上,类似Java 的Object 类,可以转换为任何数据类型.换句话说,id 类型的变量可以存放任何数据类型的对象.在内部 ...
- Android Learning:多线程与异步消息处理机制
在最近学习Android项目源码的过程中,遇到了很多多线程以及异步消息处理的机制.由于之前对这块的知识只是浅尝辄止,并没有系统的理解.但是工程中反复出现让我意识到这个知识的重要性.所以我整理出这篇博客 ...
- struts2中的标签“# ”,“%{ }”,“%{# }”
理解值栈(ValueStack)与上下文(StackContext): Struts2中有值堆栈和堆栈上下文的概念,你用 <s:debug />可以看出. 值栈中的对 ...
- IIs工作原理
http://www.cnblogs.com/szhy222/archive/2008/07/14/1242576.html 问题: HTTP.SYS 的内置驱动程序 IIS 工作者进程
- hdu 2012 素数判定 Miller_Rabbin
素数判定 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- [BZOJ 1901] Dynamic Rankings 【树状数组套线段树 || 线段树套线段树】
题目链接:BZOJ - 1901 题目分析 树状数组套线段树或线段树套线段树都可以解决这道题. 第一层是区间,第二层是权值. 空间复杂度和时间复杂度均为 O(n log^2 n). 线段树比树状数组麻 ...