1. immutable相当于 JSON.parse 和 JSON.stringify;

2.引入redux中,除了

在最外层 reducer中  import { combineReducers } from 'redux-immutable';

涉及到修改 (1)reducer 两个文件  (2)组件

2.1 对于reducer:

首先对默认状态:

import { fromJS } from 'immutable';
const defaultState = fromJS({
'requireFlag':true
})

对于简单的处理state,直接return即可:

case actionTypes.CHANGE_MORE_FLAG:
return state.set('requireFlag',!state.get('requireFlag'));

对于需要复杂处理的,一般将state传入自定义函数,最后返回:

export default (state=defaultState, action)=>{
switch (action.type) {
case actionTypes.INIT_LISTS:
return handleInitList(state,action);
}
} const handleInitList = (state,action)=>{
state.get('nav').map((item,index)=>{ //所有涉及到获取state,使用get方法,这里改变了state
item.checked = false;
});
state.set('page',1); //后续改变其他值,单个是使用 state.set('page',1)
return state.merge({ //改变多个值,需要使用merge函数,最后一定要 return出 merge函数
activeIndex:action.tabIndex,
cardId:action.cardId,
})
//return state; 不要使用merge之后,在这里return state
}

数组合并:

state.get('lifeRights').concat(action.initData.lifeRights);

2.2 组件:

function mapStateToProps(state, ownProps) {
return {
userStatus:state.getIn(['bottom','userStatus']), //注意此处有 中括号,第一个 reducer的名字
}
}

如果该reducer中 只有一层级,如reducer中的状态定义为:

const defaultState = fromJS([])

则在组件中调用使用 get : rightsList: state.get('hotRight')

immutable.js使用总结的更多相关文章

  1. 深度浅出immutable.js

    这篇文章将讲述immutable.js的基本语法和用法. 1.fromJs()  Deeply converts plain JS objects and arrays to Immutable Ma ...

  2. 大话immutable.js

    为啥要用immutable.js呢.毫不夸张的说.有了immutable.js(当然也有其他实现库)..才能将react的性能发挥到极致!要是各位看官用过一段时间的react,而没有用immutabl ...

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

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

  4. Immutable.js尝试(node.js勿入)

    最近做一些复杂html常常需要在页面做一些数据处理,常常在想如果 js有list 这种数据结构多少,今天逛github时 发现有Immutable.js 这个项目https://github.com/ ...

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

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

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

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

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

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

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

  10. [Immutable,js] Immutable.Record() as data models

    The Immutable.js Record() allows you to model your immutable data much like you would model data wit ...

随机推荐

  1. python腾讯语音合成

    一.腾讯语音合成介绍 腾讯云语音合成技术(TTS)可以将任意文本转化为语音,实现让机器和应用张口说话. 腾讯TTS技术可以应用到很多场景,比如,移动APP语音播报新闻:智能设备语音提醒:依靠网上现有节 ...

  2. 个人爱好:idea 项目结构呈现风格

  3. 代码覆盖率-JaCoCo

    代码覆盖率 在做单元测试时,代码覆盖率常常被拿来作为衡量测试好坏的指标,甚至,用代码覆盖率来考核测试任务完成情况,比如,代码覆盖率必须达到80%或 90%. JaCoCo Jacoco从多种角度对代码 ...

  4. Vue:(四)Ajax(Vue-Resource)

    Vue 要实现异步加载需要使用到 vue-resource 库.(挂载到vue实例上) (一)Vue-Resource引入 <script src="https://cdn.stati ...

  5. Servlet的5种方式实现表单提交

    http://www.cnblogs.com/zhanghaoliang/p/5622900.html

  6. BOM&DOM

    BOM(浏览器对象模型) 1. location相关 . location.href 获取当前url . location.href="http://www.sogo.com" 跳 ...

  7. mst总结

     1.jsonp跨域 Jsop的原理:利用script不存在跨域的问题,动态创建script标签,把需要请求的数据源地址赋值给其src属性,并且指定一个回调函数,从而接受到我们想要的数据 后台设置下 ...

  8. haxe相关的计划安排

    用多少写多少.先从入门开始,再到怎么写DSL解析器.最后自举(只是做个示范而已 在深入haxe的过程中,多少会跟typescript有交集,这些会边走边总结. 因为只是for example,所以这个 ...

  9. js计算时间差

    <!doctype html> <html lang="en"> <head> <meta http-equiv="Conten ...

  10. firstPage

    自己写的科比的一个简单介绍的网页,画面,布局还是太垃圾了,图片放大缩小标签不知道,简直难受. <!DOCTYPE html><html> <head> <me ...