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的更多相关文章

  1. [Redux] Reducer Composition with combineReducers()

    Previous, we do composition with objects: const todoApp = (state = {}, action) => { return { todo ...

  2. [Redux] Implementing combineReducers() from Scratch

    The combineReducers function we used in previous post: const todoApp = combineReducers({ todos, visi ...

  3. Redux源码分析之combineReducers

    Redux源码分析之基本概念 Redux源码分析之createStore Redux源码分析之bindActionCreators Redux源码分析之combineReducers Redux源码分 ...

  4. [Redux] redux之combineReducers

    combineReducers combineReducer 是将众多的 reducer 合成通过键值映射的对象,并且返回一个 combination 函数传入到 createStore 中 合并后的 ...

  5. redux源码学习笔记 - combineReducers

    上一篇有了解到,reducer函数的两个为:当前state和此次dispatch的action. state的结构是JavaScript对象,每个key都可以代表着不同意义的数据.比如说 { list ...

  6. React-使用combineReducers完成对数据对拆分管理

    数据都放在reducer.js下不利于对数据进行管理,可以把一个大的reducer.js拆分成多个小的reducer.js. 小的reducer.js const defaultState={ foc ...

  7. combineReducers 对数据进行拆分管以及使用immutable.js

    1 使用combineReaducers 整合reducers import { combineReducers } from 'redux-immutable'; import { reducer ...

  8. 使用combineReducers注意事项

    一.从‘redux’包中引入combineReducers方法: import { combineReducers } from 'redux'; 二.针对state的不同属性写不同的reducer, ...

  9. Redux API之combineReducers

    combineReducers(reducers) 随着应用变得复杂,需要对 reducer 函数 进行拆分,拆分后的每一块独立负责管理 state 的一部分. combineReducers 辅助函 ...

随机推荐

  1. .net开发COM组件之组件签名&注册

    基于.net的COM组件开发时,若采用vs强命名方式,则完成后试图将组件注册到XP系统(确切的说是.net4.0以下版本的系统) REGASM c:\libcom\dotnet\myCom.dll / ...

  2. ES6的字符串和数值的扩展

    字符串扩展 对于处理大于两个字节(大于0xffff)的字符,let str =’\u{20bb7}abc’ ES5中的遍历  for(let i=0;i<str.length;i++){ con ...

  3. Mysql笔试题(二)

    (1)表名:购物信息购物人      商品名称     数量A            甲          2B            乙          4C            丙       ...

  4. Random-Forest-Python

    1. 近期目标,实现随机森林进行点云分类 1)学习阶段: [干货]Kaggle 数据挖掘比赛经验分享 Kaggle Machine Learning Competition: Predicting T ...

  5. Python环境——安装扩展库

    一.修改easy_install源 在操作用户家目录添加一个文件 cat >> ~/.pydistutils.cfg <<EOF [easy_install] index-ur ...

  6. Python学习笔记(Ⅰ)——Python程序结构与基础语法

    作为微软的粉丝,最后终于向Python低头了,拖了两三个月终于下定决心学习Python了.不过由于之前受到C/C#等语言影响的思维定式,前期有些东西理解起来还是很费了些功夫的. 零.先抄书: 1.Py ...

  7. 怎么让微信下载APK文件包,微信内置浏览器无法打开APP下载链接的解决方案

    ** 做微信营销活动或者APK下载推广时候,域名被经常被封,做到微信中正常使用呢?这就要借助一些工具来实现有效的操作.** 先来认识一下微信屏蔽的原理.按原理逐个攻破,本人做防封一年来自认为得心应手, ...

  8. JAVA多线程实现的四种方式(转自https://www.cnblogs.com/felixzh/p/6036074.html)

    Java多线程实现方式主要有四种:继承Thread类.实现Runnable接口.实现Callable接口通过FutureTask包装器来创建Thread线程.使用ExecutorService.Cal ...

  9. shell脚本中各类括号的作用(小结)

    技巧小结: 字符串比较用双中括号[[ ]]:算数比较用单中括号[ ]——左右留空格 算数运算用双小括号(( )) :shell命令及输出用小括号( )——左右不留空格 快速替换用花括号{ }——左右留 ...

  10. JAVA 11初体验

    JAVA 11初体验 随着JAVA没半年发布一次新版本,前几天JAVA 11隆重登场.在JAVA 11中,增加了一些新的特性和api, 同时也删除了一些特性和api,还有一些性能和垃圾回收的改进. 作 ...