[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 ...
随机推荐
- apache2.4配置虚拟目录
刚开始学习,跟着韩顺平老师的视频课件学习ing~ 这是自己在配置虚拟目录时遇到的问题以及解决办法,记录下来~ ---------------------------分割线君-------------- ...
- phpmyadmin数据导入最大限制的解决方法
mysql导入文件最大限制更改解决方法:phpmyadmin库导入出错:You probably tried to upload too large file. Please refer to doc ...
- 【python】二进制、八进制、十六进制表示方法(3.0以上)
2进制是以0b开头的: 例如: 0b11 则表示十进制的3 8进制是以0o开头的: 例如: 0o11则表示十进制的9 (与2.0版本有区别) 16进制是以0x开头的: 例如: 0x11则表示十进制的1 ...
- ProfessionalKnowledgeArchitecture
- js 中文排序
/** * 比较函数 * @param {Object} param1 要比较的参数1 * @param {Object} param2 要比较的参数2 * @return {Number} 如果pa ...
- source insight 使用技巧
一.在所有文件中查找字符串 1.菜单栏选择“search project” 2.在随便一个工程文件中把所要查找的字符串输入到空白的地方,然后点连接
- 打造轻量级自动化测试框架WebZ
一.什么是WebZ WebZ是我用Python写的“关键字驱动”的自动化测试框架,基于WebDriver. 设计该框架的初衷是:用自动化测试让测试人员从一些简单却重复的测试中解放出来.之所以用“关键字 ...
- UFLDL教程(五)之self-taught learning
这里所谓的自学习,其实就是利用稀疏自编码器对无标签样本学习其特征 该自学习程序包括两部分: 稀疏自编码器学习图像特征(实现自学习)---用到无标签的样本集 softmax回归对样本分类---用到有标签 ...
- bzoj 3143: [Hnoi2013]游走 高斯消元
3143: [Hnoi2013]游走 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 1026 Solved: 448[Submit][Status] ...
- C语言中结构体对齐问题
C语言中结构体对齐问题 收藏 关于C语言中的结构体对齐问题 1,比如: struct{short a1;short a2;short a3;}A;struct{long a1;short a2;}B; ...