博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[Javascript] Creating an Immutable Object Graph with Immutable.js Map()
阅读量:5164 次
发布时间:2019-06-13

本文共 1568 字,大约阅读时间需要 5 分钟。

Learn how to create an Immutable.Map() through plain Javascript object construction and also via array tuples.

 

console.clear();// Can be an objectvar map = Immutable.Map({key: "value"});console.log(map.get("key")); //"value"// Can be an arrayvar map = Immutable.Map([["key", {"name": "Zhentian"}]]);console.log(map.get("key").name); //"Zhentian"// size propconsole.log(map.size); //1

 

mocha.setup('bdd');const expect = chai.expect; function createObjTodos(numTodos) {    var obj = {}  _.each(_.range(numTodos), (index) => {    const todoSequence = String(index+1);    obj['todo'+todoSequence] = {      title: 'Todo '+todoSequence,       value: `Make ${todoSequence} happen`    };  });   return obj;         } describe('Creating an Immutable Object Graph with Immutable.js Map()', () => {    it('should create Map() with matching keys', () => {    const data = {      "todo1": {        title: "Todo 1",        value: "Make it happen"      },      "todo2": {        title: "Todo 2",        value: "Make it happen"      }    }    let map = Immutable.Map(data);    expect(map.get("todo1").title).to.equal("Todo 1");      });  it('should create Map() with keys from array tuples', () => {    let map = Immutable.Map([["todo1", {title: "Todo 1"}]]) // Note the array within array    expect(map.get("todo1").title).to.equal("Todo 1");      });    it('should create Map() with matching size to number of keys', () => {    let map = Immutable.Map(createObjTodos(3))    expect(map.size).to.equal(3);      });  });mocha.run();

 

转载于:https://www.cnblogs.com/Answer1215/p/4889941.html

你可能感兴趣的文章
写接口请求类型为get或post的时,参数定义的几种方式,如何用注解(原创)--雷锋...
查看>>
【OpenJ_Bailian - 2287】Tian Ji -- The Horse Racing (贪心)
查看>>
Java网络编程--socket服务器端与客户端讲解
查看>>
List_统计输入数值的各种值
查看>>
学习笔记-KMP算法
查看>>
Timer-triggered memory-to-memory DMA transfer demonstrator
查看>>
跨域问题整理
查看>>
[Linux]文件浏览
查看>>
64位主机64位oracle下装32位客户端ODAC(NFPACS版)
查看>>
获取国内随机IP的函数
查看>>
今天第一次写博客
查看>>
江城子·己亥年戊辰月丁丑日话凄凉
查看>>
IP V4 和 IP V6 初识
查看>>
Spring Mvc模式下Jquery Ajax 与后台交互操作
查看>>
(转)matlab练习程序(HOG方向梯度直方图)
查看>>
『Raid 平面最近点对』
查看>>
【ADO.NET基础-数据加密】第一篇(加密解密篇)
查看>>
C语言基础小结(一)
查看>>
STL中的优先级队列priority_queue
查看>>
UE4 使用UGM制作血条
查看>>