1.0.0 • Published 6 years ago

@warren-bank/redux-compose-reducers v1.0.0

Weekly downloads
-
License
GPL-2.0
Repository
github
Last release
6 years ago

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):

Related Works:

Legal: