combineReducers
const reactInit = '@@react/Init'
const combineReducers = (reducers) => {
const finalReducers = {}
for (let key in reducers) {
const reducer = reducers[key]
if (typeof reducer === 'undefined') {
console.error(`reducer${key}的值是undefined`)
}
if (typeof reducer === 'function') {
finalReducers[key] = reducer
}
}
for (let key in finalReducers) {
const reducer = finalReducers[key]
const state = reducer(undefined, reactInit)
if (typeof state === 'undefined'){
throw new Error(`reducer${key}的返回值为undefined`)
}
}
return (state={}, action) => {
for (let key in finalReducers) {
const reducer = finalReducers[key]
const newState = reducer(state[key], action)
state[key] = newState
}
return state
}
}
combineReducers的更多相关文章
- [Redux] Reducer Composition with combineReducers()
Previous, we do composition with objects: const todoApp = (state = {}, action) => { return { todo ...
- [Redux] Implementing combineReducers() from Scratch
The combineReducers function we used in previous post: const todoApp = combineReducers({ todos, visi ...
- Redux源码分析之combineReducers
Redux源码分析之基本概念 Redux源码分析之createStore Redux源码分析之bindActionCreators Redux源码分析之combineReducers Redux源码分 ...
- [Redux] redux之combineReducers
combineReducers combineReducer 是将众多的 reducer 合成通过键值映射的对象,并且返回一个 combination 函数传入到 createStore 中 合并后的 ...
- redux源码学习笔记 - combineReducers
上一篇有了解到,reducer函数的两个为:当前state和此次dispatch的action. state的结构是JavaScript对象,每个key都可以代表着不同意义的数据.比如说 { list ...
- React-使用combineReducers完成对数据对拆分管理
数据都放在reducer.js下不利于对数据进行管理,可以把一个大的reducer.js拆分成多个小的reducer.js. 小的reducer.js const defaultState={ foc ...
- combineReducers 对数据进行拆分管以及使用immutable.js
1 使用combineReaducers 整合reducers import { combineReducers } from 'redux-immutable'; import { reducer ...
- 使用combineReducers注意事项
一.从‘redux’包中引入combineReducers方法: import { combineReducers } from 'redux'; 二.针对state的不同属性写不同的reducer, ...
- Redux API之combineReducers
combineReducers(reducers) 随着应用变得复杂,需要对 reducer 函数 进行拆分,拆分后的每一块独立负责管理 state 的一部分. combineReducers 辅助函 ...
随机推荐
- 如何把一个vue组件改为ionic/angular组件
同是mvvm框架,他们之间是很相似的,如何你已经熟悉其中的一个,那么另一个也就基本上也就会的差不多了. 一.动态属性.值.事件绑定 vue中使用v-bind:或者之间分号:进行绑定 ng中左括号[]进 ...
- 2PC/3PC/Paxos
在分布式系统中,一个事务可能涉及到集群中的多个节点.单个节点很容易知道自己执行的事务成功还是失败,但因为网络不可靠难以了解其它节点的执行状态(可能事务执行成功但网络访问超时). 若部分节点事务执行失败 ...
- java -cp通配符
JDK6支持java -cp后面跟通配符'*',试了一下发现还是需要注意: 错误方式(Wrong way): java -cp /data/apps/lib/*.jar com.chinacache ...
- python摸爬滚打之----tcp协议的三次握手四次挥手
TCP协议的三次握手, 四次挥手 三次握手过程 1, 服务器时刻准备接受客户端进程的连接请求, 此时服务器就进入了LISTEN(监听)状态; 2, 客户端进程然后向服务器发出连接请求报文, 之后客户端 ...
- 【Python全栈-JavaScript】jQuery事件
jQuery事件 一.页面载入 当DOM载入就绪可以查询及操纵时绑定一个要执行的函数. 这是事件模块中最重要的一个函数,因为它可以极大地提高web应用程序的响应速度. 简单地说,这个方法纯粹是对向 w ...
- mybatis 分页插件
博客地址http://www.jianshu.com/nb/5226994 引言 对于使用Mybatis时,最头痛的就是写分页,需要先写一个查询count的select语句,然后再写一个真正分页查询的 ...
- requests库的基本使用
1.发送get请求 import requests # response=requests.get('http://www.baidu.com') # 查看响应内容,返回的是已经解码的内容 # res ...
- (.NET高级课程笔记)泛型总结
泛型总结 1.引入泛型:延迟声明,即在声明的时候没有指定参数类型,只有当调用的时候才会确定 其参数类型(架构师的理念:推迟一切可以推迟的) 2.如何声明和使用泛型 3.泛型的好处和原理 4.泛型类.泛 ...
- C++——简单数据类型及布尔类型
一. 简单数据类型 数据类型描述了对象在内存存储区中占据的空间大小,描述了对象能够表示的数据范围 和类型.C++语言中常用的数据类型有整型.实型.字符型(这3种类型也被称之为简单数 据类型).数组类型 ...
- oracle之在java中调用
1.给java项目添加oracle的驱动包ojdbc6.jar 2.添加包ojdbc6.jar,这个包在安装的服务版oracle11g的这个目录下: 3.使用.