redux-actions有两大法宝createActionhandleActions.

createAction

http://www.jianshu.com/p/6ba5cd795077

原来创建action:

const startAction = () => ({ type: START });

使用redux-actions创建action:

import { createAction } from 'redux-actions';
const startAction = createAction(START);

handleActions

原来reducer操作state写法要使用switchif else来匹配:

function timer(state = defaultState, action) {
switch (action.type) {
case START:
return { ...state, runStatus: true };
case STOP:
return { ...state, runStatus: false };
case RESET:
return { ...state, seconds: 0 };
case RUN_TIMER:
return { ...state, seconds: state.seconds + 1 };
default:
return state;
}
}

使用redux-actions``reducer操作state:

const timer = handleActions({
START: (state, action) => ({ ...state, runStatus: true }),
STOP: (state, action) => ({ ...state, runStatus: false }),
RESET: (state, action) => ({ ...state, seconds: 0 }),
RUN_TIMER: (state, action) => ({ ...state, seconds: state.seconds + 1 }),
}, defaultState); http://blog.csdn.net/sinat_17775997/article/details/70176723

最新文章

  1. PHP 生成验证码
  2. Maven Eclipse (m2e) SCM connector for subclipse 1.10 (svn 1.8) 无法检测
  3. 学习笔记:Twitter核心数据类库团队的Hadoop优化经验
  4. Google Code Jam 2010 Round 1A Problem A. Rotate
  5. Request Session生命周期及struts1 中service的编写
  6. T—SQL用法剪辑,方便以后查看
  7. Stopwatch 类【转】
  8. 传统web和mvc的区别
  9. stl中的容器、迭代器和算法----vector中的find实现
  10. Day-17: 网络编程
  11. 【福大软工】 W班级总成绩排名2
  12. T-SQL动态查询(2)——关键字查询
  13. 213. House Robber II(动态规划)
  14. Oracle SQL 优化规则
  15. Spring-IOC实现【01-XML配置方式】
  16. [转载]AngularJS 指令 用法
  17. Nodejs学习笔记(十二)—定时任务(node-schedule)
  18. JavaScript浏览器对象模型(BOM)之window对象
  19. BZOJ3675 Apio2014 序列分割 【斜率优化】
  20. 蓝桥杯 历届试题 PREV-1 核桃的数量

热门文章

  1. jquery简易的三级导航
  2. Django2.1集成xadmin管理后台所遇到的错误集锦,解决填坑
  3. 为什么选择Redis
  4. 17.VUE学习之- v-for指令的使用方法
  5. mem_init()
  6. 洛谷 P3740 [HAOI2014]贴海报
  7. HDU2586 How far away ?
  8. CodeForces 781D Axel and Marston in Bitland DP
  9. 使用code::blocks编译windows的dll链接库
  10. PAT1021