@warren-bank/redux-compose-reducers
v1.0.0
Published
chains together a series of reducer functions through functional composition
Downloads
4
Readme
redux-compose-reducers
Summary:
chains together a series of reducer functions through functional composition
Installation:
npm install --save '@warren-bank/redux-compose-reducers'
Usage Example:
const composeReducers = require('@warren-bank/redux-compose-reducers')
const reducer_1 = (state, action) => state + 1
const reducer_2 = (state, action) => state - 1
const reducer_chain_1 = composeReducers(reducer_1, reducer_2) // (state, action) => state + 1 - 1
const reducer_chain_2 = composeReducers(reducer_chain_1, reducer_1) // (state, action) => state + 1 - 1 + 1
const reducer_chain_3 = composeReducers(reducer_chain_1, reducer_2) // (state, action) => state + 1 - 1 - 1
const reducer_chain_4 = composeReducers(reducer_chain_2, reducer_chain_3) // (state, action) => state + 1 - 1 + 1 + 1 - 1 - 1
expect( reducer_1( 5, {}) ).toBe(6)
expect( reducer_2( 5, {}) ).toBe(4)
expect( reducer_chain_1(5, {}) ).toBe(5)
expect( reducer_chain_2(5, {}) ).toBe(6)
expect( reducer_chain_3(5, {}) ).toBe(4)
expect( reducer_chain_4(5, {}) ).toBe(5)
Browser Build (transpiled to ES5):
files in repo:
files hosted in CDN:
run the usage example:
global variable(s):
- window.composeReducers
Related Works:
https://github.com/micro-js/compose-reducers
- same outcome
- different methodology
- calls each reducer in a loop
- doesn't use functional composition
- calls each reducer in a loop
https://github.com/palantir/redoodle
- nearly identical to
@micro-js/compose-reducers
- adds TypeScript definitions
- restricts input/output value types
- disallows the "composed" reducer to be used for initialization
state
cannot beundefined
- disallows the "composed" reducer to be used for initialization
- restricts input/output value types
- nearly identical to
Legal:
- copyright: Warren Bank
- license: GPL-2.0