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()的更多相关文章

  1. [Javascript] Querying an Immutable.js Map()

    Learn how to query an Immutable.Map() using get, getIn, has, includes, find, first and last. These a ...

  2. [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 ...

  3. [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 ...

  4. [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 ...

  5. [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 ...

  6. Immutable.js – JavaScript 不可变数据集合

    不可变数据是指一旦创建就不能被修改的数据,使得应用开发更简单,允许使用函数式编程技术,比如惰性评估.Immutable JS 提供一个惰性 Sequence,允许高效的队列方法链,类似 map 和 f ...

  7. [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 ...

  8. [Javascript] Manage Application State with Immutable.js

    Learn how Immutable.js data structures are different from native iterable Javascript data types and ...

  9. [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 ...

随机推荐

  1. Ubuntu系统、开发环境配置

    在VMware10下安装成功了Ubuntu 13.10桌面版,刚安装完需要配置很多内容,下面为记录: 1. 更新源: 想了解更新地址的可以查看apt-get的源列表文件 $ sudo gedit /e ...

  2. ASP.NET 后台不识别ASPX中的控件

    请问后台不识别ASPX中的控件,怎么解决 这个程序是在网上下载的 C# code <asp:DataGrid runat="server" ID="dgList1& ...

  3. Python 学习之urllib模块---用于发送网络请求,获取数据

    1.urllib urllib是Python标准库的一部分,包含urllib.request,urllib.error,urllib.parse,urlli.robotparser四个子模块. (1) ...

  4. JQUERY 插件开发——LAZYLOADIMG(预加载和延迟加载图片)

    开发背景 本插件开发是近期写的最后一个插件了,接下来我想把最近研究的redis最为一个系列阐述下.当然Jquery插件开发是我个人爱好,我不会停止,在将来的开发中我会继续完善,当然也会坚持写这个系列的 ...

  5. 微软HoloLens技术解谜

    HoloLens 是什么? HoloLens 是微软发布的可穿戴式增强现实计算设备,它拥有这么几个关键要素: 它是增强现实产品,即 Augmented Reality(AR),AR 技术将计算机生成的 ...

  6. 【Database】MongoDB教程

    MongoDB是一个基于分布式文件存储的数据库.旨在为WEB应用提供可扩展的高性能数据存储解决方案.

  7. 【UVA11019】Matrix Matcher

    Description Given an N × M matrix, your task is to find the number of occurences of an X × Y pattern ...

  8. 【 POJ - 3801】Crazy Circuits(有源汇、上下界最小流)

    Description You’ve just built a circuit board for your new robot, and now you need to power it. Your ...

  9. input text 不可编辑的解决办法

    <div class="inp bg"> <input id="inp-query" type="text" name=& ...

  10. [cocos2d]关于CCSprite的若干问题与误区

    文章 [cocos2d] 利用texture atlases生成动画 中介绍了如何生成动画并绑定在CCSprite实例上. 使用该代码遇到了几个问题,值得mark下 问题1.多实例 问题描述: 新建一 ...