Immutable.js offers the fromJS() method to build immutable structures from objects and array. Objects are converted into maps. Arrays are converted into lists. The fromJS() method can also take a reviver function for custom conversions.

 Object to Immutable Map:
 
check by isMap():
    const plainJSObject = {
title: "Go to grocery",
text: "I need milk and eggs",
completed: false,
category: {title: "House Duties", priority: 10}
}; const immutableTodo = Immutable.fromJS(plainJSObject); expect(Immutable.Map.isMap(immutableTodo)).to.be.true

We cat get value by getIn() method:

expect(immtableTodo.getIn(["category", "title"])).to.equal("House Duties");

Array to Immutable List:

check by isList():

    const plainJSArray = [
"Go to grocery",
"Buy milk and eggs",
"Help kids with homework",
["Buy Lemons", "Make Lemonade"]
]; const immutableTodoList = Immutable.fromJS(plainJSArray);
expect(Immutable.List.isList(immutableTodoList)).to.be.true;

get value by getIn():

expect(immutableTodoList.getIn([3, 1])).to.equal("Make Lemonade")

Convert a plain array to Immutable Map:

    const plainJSArray = [
"Go to grocery",
"Buy milk and eggs",
"Help kids with homework",
["Buy Lemons", "Make Lemonade"]
]; const immutableTodoList = Immutable.formJS(plainJSArray, (key, value)=>{ return value.toMap();
}); expect(immutableTodoList.getIn([3,1])).to.equal("Make Lemonade");

[Immutable.js] Using fromJS() to Convert Plain JavaScript Objects into Immutable Data的更多相关文章

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

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

  3. Immutable.js 以及在 react+redux 项目中的实践

    来自一位美团大牛的分享,相信可以帮助到你. 原文链接:https://juejin.im/post/5948985ea0bb9f006bed7472?utm_source=tuicool&ut ...

  4. React+Immutable.js的心路历程

    这段时间做的项目开发中用的是React+Redux+ImmutableJs+Es6开发,总结了immutable.js的相关使用姿势: Immutable Data 顾名思义是指一旦被创造后,就不可以 ...

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

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

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

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

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

  8. [Javascript] Modifying an Immutable.js Map()

    We will now look at five methods that modify an Immutable.Map(). set update delete clear merge //set ...

  9. Redux进阶(Immutable.js)

    更好的阅读体验 更好的阅度体验 Immutable.js Immutable的优势 1. 保证不可变(每次通过Immutable.js操作的对象都会返回一个新的对象) 2. 丰富的API 3. 性能好 ...

随机推荐

  1. C++设计模式---Strategy模式

    一.前言 学习的第一个设计模式!不知道理解的对不对,期望大家一起多交流~ Strategy模式:策略模式,定义了算法族,分别封装起来,此模式可以让算法的变化独立于使用算法的客户.Strategy模式将 ...

  2. web请求的处理流程

    web请求的处理流程如下: 1.客户发起请求到服务器网卡:2.服务器网卡接受到请求后转交给内核处理:3.内核根据请求对应的套接字,将请求交给工作在用户空间的Web服务器进程4.Web服务器进程根据用户 ...

  3. android studio 报ambiguous method call

    如题,在android studio中调用this.toString时,提示的错误信息是ambiguous method call. both get class () in object and g ...

  4. hdu 2438

    Problem Description Mr. West bought a new car! So he is travelling around the city. One day he comes ...

  5. static说明

    1.最基本用法:加static的全局变量或者函数,只能在本文件中使用.可见性只在本文件中. 当我们同时编译多个文件时,所有未加static前缀的全局变量和函数都具有全局可见性.为理解这句话,我举例来说 ...

  6. (原)10-folder交叉验证

    转载请注明出处: http://www.cnblogs.com/darkknightzh/p/6069731.html 参考网址: https://github.com/cmusatyalab/ope ...

  7. 清除大文本中的html标签

    public String clearHtmlText(String inputString) { if (StringUtils.isBlank(inputString)) { return &qu ...

  8. 使用spool命令从Oracle导出数据

    公司的网站用的是Oracle数据库,最近要导出里面的数据,使用mysql数据库 spool D:\DB\{文件名}.sql set heading off; set echo off; set fee ...

  9. [CSAPP]并发与并行

    学了这么久的计算机,并发与并行的概念理解的一直不够透彻.考研复习那会儿,以为自己懂了,然而直到看了CSAPP才算是真正明白了这俩个概念. 并发(concurrency) 流X和流Y并发运行是指,流X在 ...

  10. (摘) MDI登陆问题

    MDI编程中需要验证用户身份,那么登陆窗口就需要在验证密码后进行相关的隐藏处理. (1)隐藏登陆窗口(登陆窗体作为启动) 登陆按钮事件:this.Hide();//隐藏登陆窗口MDI_Name M = ...