redux - How to access global state from redux-loop combineReducers?
问题描述
I'm using react-loop, and I'm trying to use its combineReducers but extend it to pass as a third parameter the global state, basically implementing an API similar to https://github.com/Velenir/combine-reducers-global-state
Combine reducers basically invokes the childReducers as we can find in its code
let currentChild = childReducer(prev[key], action, ...args);
The idea is to pass there a third parameter, so , action, plainState, ...args
so that the reducer receive it as parameter. The problem is how to produce that plainState, since the rootState is basically a combination of array of the form ([state, Cmd]) instead I need only the plain state, without redux-loop handler variables.
解决方案
您必须编写自己的 combineReducers 版本。所提供的预计不会在最简单的情况之外工作。不过,您可以将其作为提供的基础。https://github.com/redux-loop/redux-loop/blob/master/src/combine-reducers.js。我想你可以像你提到的库一样实现它。
但是,如果您正在寻找一种将其他状态值注入减速器的方法,请查看我已经使用 redux-loop 几年的这个中间件。https://github.com/bdwain/redux-action-enhancer
免责声明:我同时维护 redux-loop 和 redux-action-enhancers。
推荐阅读
- javascript - Firebase Cloud Function 中的异步返回语句?
- python - 如何从 Selenium 中动态生成的页面中获取 HTML 元素?
- apache - 将旧网站重定向到新地址,但将一页重定向到新 URL
- dependency-injection - 使用 CDI Produces 获取注入的对象
- html - 如何为单击的按钮制作 0.5 秒的平滑发光效果?
- wordpress - wordpress 测验创建者响应问题
- java - 什么是责任驱动设计?
- ruby-on-rails - 多对多关系别名
- vb.net - 使用实体 (EF6) 从 BindingSource.List 中删除 DbContext 中的所有位置
- firebase - Flutter - 如何获取当前上下文?