1

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.

4

1 回答 1

1

您必须编写自己的 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。

于 2020-12-18T00:57:50.617 回答