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 辅助函 ...
随机推荐
- 召回率(Recall),精确率(Precision),平均正确率
https://blog.csdn.net/yanhx1204/article/details/81017134 摘要 在训练YOLO v2的过程中,系统会显示出一些评价训练效果的值,如Recall, ...
- Charles 使用
一.设置域名焦点 View->Focused Hosts…-> 二.抓包https:配置证书 1. 电脑安装SSL证书 选择 “Help” -> “SSL Proxying” -&g ...
- linux 对MTD分区nand flash的烧写和读取
使用mtd-utils工具实现对flash的升级分区的烧写yaffs2 yaffs2的格式是根据所使用的nandflash来制作的,不同的nandflash,得到的yaffs2是不一样的,具体可以参考 ...
- 11、jeecg 笔记之 界面常用整理 - 方便复制粘贴
1.datagrid 操作按钮(按钮样式) 操作按钮的显示主要依赖于 <t:dgCol title="操作" field="opt" ></ ...
- C#博客目录
基础加强 1.索引器 2.密闭类.静态类及扩展方法 3.值.引用类型及结构体 4.秒懂IL.CTS.CLS和CLR 5.装箱与拆箱 6.引用相等与运算符重载 7.ref与out 8.委托和事件 9.对 ...
- python函数带()与否
一.不带括号时,调用的是这个函数本身 ,是整个函数体,是一个函数对象,不须等该函数执行完成二.带括号(参数或者无参),调用的是函数的执行结果,须等该函数执行完成的结果 进程和线程的target=fun ...
- python-soap接口请求
一.环境准备 方法一: >pip3 install suds >pip3 install suds-jurko 因在线安装报错,所以直接下载安装包. 方法二: 1.suds库下载地址:ht ...
- 用原生js+canvas实现五子棋
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...
- Your password does not satisfy the current policy requirements问题解决方法
运行 mysql>set validate_password_policy=0; 目的是,可以设置弱密码.
- css 快捷修改 checkbox 及 radio的背景图
在CSS内选择要修改的input input[type=checkbox]:disabled{ //input类型等于复选框并且是disabled状态的所有(根据情况自由指定) -webkit-app ...