Skip to content

chains together a series of reducer functions through functional composition

License

Notifications You must be signed in to change notification settings

warren-bank/redux-compose-reducers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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:

About

chains together a series of reducer functions through functional composition

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published