redux-cond
v2.0.0
Published
Redux reducer with cond function
Downloads
14
Readme
redux-cond
Redux reducer with cond function
Installation
// or yarn add
npm i --save redux-cond
Use
redux-cond inspired by clojure cond
Easy-to-use :smiley:
Return cond function in your reducer
// const cond = require('redux-cond')
import cond from 'redux-cond'
function reducer(state, action) {
return cond(
type1, f1,
type2, f2,
...
)(state, action)
}
e.g.
import cond from 'redux-cond'
const initialState = {
count: 0
}
cond(
'INCREMENT', state => Object.assign(state, { count: state.count + 1 }),
'DECREMENT', state => Object.assign(state, { count: state.count - 1 })
)(initialState, { type: 'INCREMENT' }) // => { count: 1 }
f (f1, f2, ...) is a function which receive two arguments, state and action.
const f = (state, action) => { return newState }
License
MIT © g1eny0ung