@warren-bank/redux-compose-reducers

1.0.0 • Public • Published

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:

Readme

Keywords

none

Package Sidebar

Install

npm i @warren-bank/redux-compose-reducers

Weekly Downloads

0

Version

1.0.0

License

GPL-2.0

Last publish

Collaborators

  • warren-r-bank