The Immutable.js Map() is analogous to a Javascript Object or Hash since it is comprised of key-value pairs. The Immutable.js List() is analogous to a Javascript Array and contains many of the same native methods. Let's compare the two and dive into the basics of List().

Map: From Javascript plain object

Add item to the immtuable map:

let todo  = {
id: 10,
title: "Immutable,js"
}; let todos = Immutable.Map();
todo.set(todo.id, todo);

get item from Immtuable Map:

let selectedTodo = todos.get(todo.id);

List: From Javascript plain array

Add item to the Immutable List:

let shoppingList = Immutable.List();

let item = "Milk";

shoppingList.push(item);

get item from the Immutable List:

let selectedItem = shoppingList.get(0);

create List() from series of values:

// bad:
let list = Immutable.List.of("Milk", "Eggs", "Detergent", "Bread", "Steak"); // hard code a list of iterms // good:
const todoItems = ["Milk", "Eggs", "Detergent", "Bread", "Steak"];
let list = Immutable.List.of(...todoItems); var count = 0;
_.each(todoItems, (item) => {
expect(list.get(count)).to.equal(item);
count++;
})

[Immutable.js] Differences between the Immutable.js Map() and List()的更多相关文章

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

  2. js 定义像java一样的map方便取值【转】

    js 定义像java一样的map方便取值.  百度有位大神说"js对象本身就是一种Map结构",这真是一段让人欢天喜地的代码. <script> //定义一个全局map ...

  3. JS中集合对象(Array、Map、Set)及类数组对象的使用与对比

    原文地址 在使用js编程的时候,常常会用到集合对象,集合对象其实是一种泛型,在js中没有明确的规定其内元素的类型,但在强类型语言譬如Java中泛型强制要求指定类型. ES6引入了iterable类型, ...

  4. js实现table排序-sortable.js

    方案一.引用sortable.js包 /* <th class="thcss" style="width: 40px;" onclick="so ...

  5. 理清JS数组、json、js对象的区别与联系

    最近在敲代码时,遇上了一个关于JS数组的问题,由此引发了关于对象和json的联想,曾经觉得很畅顺的知识点突然模糊了.于是,为了理清这些东西,有了如下这篇文章.觉得没问题的猿们可以当复习,而那些带着疑问 ...

  6. h5 录音 自动生成proto Js语句 UglifyJS-- 对你的js做了什么 【原码笔记】-- protobuf.js 与 Long.js 【微信开发】-- 发送模板消息 能编程与会编程 vue2入坑随记(二) -- 自定义动态组件 微信上传图片

    得益于前辈的分享,做了一个h5录音的demo.效果图如下: 点击开始录音会先弹出确认框: 首次确认允许后,再次录音不需要再确认,但如果用户点击禁止,则无法录音: 点击发送 将录音内容发送到对话框中.点 ...

  7. JavaScript(js)对象常用操作,JS操作JSON总结

    数据类型判断可以通过一元操作符typeof,此操作符可以判断大部分JS数据类型. 也可以通过instanceof来判断.如: var a = []; alert(typeof a); // objec ...

  8. 如何用js定义数组,用js来拼接json字段

    定义js数组的方式有: var arr = (); var arr = []; var arr = new Array(); 如何拼接成一个json字段. <!DOCTYPE HTML PUBL ...

  9. PHPStorm 调式JS /同时调式PHP和jS

    PHPStorm 调式JS /同时调式PHP和jS 一.PHPStorm 调式Javascript 在PHP Storm中创建test.html <!DOCTYPE html> <h ...

随机推荐

  1. .net中将DataTable导出到word、Excel、txt、htm的方法

    dt:DataTable strFile:fileName strExt:type private void GridExport(DataTable dt, string strFile, stri ...

  2. C#获取时间戳的方法

    获取时间戳的方法 /// <summary>        /// 获取时间戳        /// </summary>        /// <param name= ...

  3. timed out waiting for input: auto-logout

    The ssh "timed out waiting for input: auto-logout" messages is generated by ssh upon reach ...

  4. VSIM生成fsdb波形文件(VERILOG)

    VSIM生成fsdb波形文件(verilog) 两步主要的设置 testbench加入函数 运行库调用 1.testbench加入函数 initial begin $fsdbDumpfile(&quo ...

  5. SqlDbHelper备份,做项目时方便应用(目前不太全,把自己项目中的逐渐转移过来)

    ****************************************** 这是官网新闻左侧类别那部分用到的 **************************************** ...

  6. onblur判断数字

    window.onload = function () { document.getElementById('text1').onblur = function () { if (isNaN(docu ...

  7. Nginx Configure时配置

    Configure Arguments Configure arguments common for nginx binaries from pre-built packages for stable ...

  8. tomcat 支持https

    HTTP是平时浏览网页时候使用的一种协议.HTTP协议传输的数据都是未加密的,也就是明文的,因此使用HTTP协议传输隐私信息非常不安全.为了保证 这些隐私数据能加密传输,于是网景公司设计了SSL(Se ...

  9. iOS的属性声明:retain和strong的区别

    声明属性时用strong或者retain效果是一样的(貌似更多开发者更倾向于用strong).不过在声明Block时,使用strong和retain会有截然不同的效果.strong会等于copy,而r ...

  10. memcached在Windows下的安装

    memcached简介详情请谷歌.这里介绍如何在windows下安装. 1.下载     下载地址:http://download.csdn.net/detail/u010562988/9456109 ...