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. 正确的安装qwtplot3D开发库

    1.从网上下载qwtplot3D的最新版本:http://qwtplot3d.sourceforge.net/ 2.解压qwtplot3d-0.2.7.zip到C盘根目录下(注意:路径中不能带有中文汉 ...

  2. DotNet加密方式解析--散列加密

    没时间扯淡类,赶紧上车吧. 在现代社会中,信息安全对于每一个人都是至关重要的,例如我们的银行账户安全.支付宝和微信账户安全.以及邮箱等等,说到信息安全,那就必须得提到加密技术,至于加密的一些相关概念, ...

  3. [CSAPP笔记][第十二章并发编程]

    第十二章 并发编程 如果逻辑控制流在时间上是重叠,那么它们就是并发的(concurrent).这种常见的现象称为并发(concurrency). 硬件异常处理程序,进程和Unix信号处理程序都是大家熟 ...

  4. 做量化模型Matlab、R、Python、F#和C++到底选择哪一个?

    MATLAB是matrix&laboratory两个词的组合,意为矩阵工厂(矩阵实验室).是由美国mathworks公司发布的主要面对科学计算.可视化以及交互式程序设计的高科技计算环境.它将数 ...

  5. NVelocity引擎

    NVelocity引擎输出HTML流***(一般处理程序中) VelocityEngine vltEngine = new VelocityEngine(); vltEngine.SetPropert ...

  6. SQL获取选中时间的交集

    如上图:t1,t2代表要选择的时间段,t3,t4代表系统时间. 那么如果要获取选中时间段所有的交集为: 条件1 and ((t3>t1 and t1>t2) or (t3<t2 an ...

  7. UIView /  UIView的布局

    //! 一个视图可以有n个子视图,但是一个视图只能有一个父视图 struct CGRect {   CGPoint origin;   CGSize size; }; CGRectMake(CGFlo ...

  8. BZOJ 2243 SDOI 2011染色

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2243 算法讨论: 树链剖分把树放到线段树上.然后线段树的每个节点要维护的东西有左端点的颜色 ...

  9. 在windows中搭建php开发环境

    一.wampserver wampserver是一个安装集成包,包含了开发所需的apache,mysql,php,简单方便. 下载地址 http://www.xiazaiba.com/html/279 ...

  10. :before与:after伪类的应用

    1.小三角样式