redux-rereducers
A higher order reducer for performing state calculations after the initial reduction has completed.
Benefits
- Easier to reduce data that depends on multiple state values in the redux store.
- Processes all changes within the same reduction preventing state inconsistencies normally caused by side effects pattern.
- Cleanly decouple reductions based on data that may be affected by multiple actions.
- No need to replicate reductions in several action reducers.
Build Status
Install
npm install --save redux-rereducers
Usage
const rereducers = { ...state } rereducer2 rereducerN let store =
createRereducerHigherOrder(...rereducers)
Creates a higher order reducer that applies the rereducers after the initial primary reduction has been performed.
Arguments
...rereducers
(arguments): Functions that conform to the rereducers API. Each rereducer receives thestate
only and returnsstate
. The rereducer signature is(state) => state
.
Returns
Function
A higher order reducer that applies the given rereducers.
Example: Average of Multiple Increment Counters
const reducer = const rereducer = ...state average: const store = store store store // { counters: { a: 1, b: 1 }, average: 1 }