[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 ...
随机推荐
- 存储过程修改产品描述页图片alt描述信息
今天修改了所有产品的图片信息,用到了存储过程.在参考下面存储过程以后,终于搞定了. 1 BEGIN 2 DECLARE Done INT DEFAULT 0; 3 4 DECLARE CurrentL ...
- thinkphp使用问题
下面总结一些,我在使用中遇到的问题,以后遇到了再补充 一.<a>标签的跳转问题 问题:我在控制器Home/Index/index里面使用了Public里面的index.html模板,ind ...
- sublime支持显示中文
Sublime Text 2是一个非常不错的源代码及文本编辑器,但是不支持GB2312和GBK编码在很多情况下会非常麻烦.不过Sublime Package Control所以供的插件可以让Subli ...
- jQuery组件写法
知识点: 什么是插件 jQuery插件的模式 jQuery插件的Lightweight Start模式(入门级插件模式) 8.1 插件(Plug-in) “插件”这个关键字,估计大家在日常生活中经常有 ...
- R统计软件真有意思哈,以后我怕要用得着,先自学
呵呵,作数据分析是数据监控后的动作. 思路是用监控系统产生数据, 如果监控本身提供统计最好,如果不提供,则可以用R来作分析统计和预测. 如果数据不符合规范,则用PYTHON进行处理转换. ~~~~~~ ...
- 【POI2003/2004 stage I】
[原题在此] Let us consider a game on a rectangular board m x 1 consisting of m elementary squares number ...
- 【POJ1021】Intervals (最短路解差分约束)
题目: Sample Input 5 3 7 3 8 10 3 6 8 1 1 3 1 10 11 1 Sample Output 6 题意: 我们选数,每个数只能选一次.给定n个条件[ai,bi]和 ...
- 15个网页设计必备的Google Chrome 扩展
2011年第一篇,翻译自freelancefolder的一篇文章.以下为译文内容: 最近,我将Google Chrome作为了我的主力浏览器,同时,将其作为我设计和开发网页的工具,尽管我还时常会去Fi ...
- Spring MVC 解读——View,ViewResolver(转)
上一篇文章(1)(2)分析了Spring是如何调用和执行控制器方法,以及处理返回结果的,现在我们就分析下Spring如何解析返回的结果生成响应的视图. 一.概念理解 View ---View接口表示一 ...
- RESTful, 说说 http 的 patch method
最早的时候,我们只需要 GET 和 POST 方法,POST 方法的引入也只是为了消除 URL 过长,参数隐藏,上传文件的问题,完全和语义无关.接触到 RESTful 之后,我们开始思考 GET 和 ...