Trigger execution chains based on the state of injected parameters.
If a function within the chain returns false the execution chain stops and
the next function will not be called.
Install
npm install state-handler --save
example
const StateHandler = require('state-handler')// some example stateconst state = { items: [], complete: false}const sh = StateHandler (state)// arguments can be an array or a list of parameterssh.on(// [ (s) => s.items.length === 2, (s) => alert(JSON.stringify(s.items)), (s) => {s.complete = true}, // {} prevent return of false (s) => s.items = [],// ])
StateHandler accepts an arbitrary length of parameters, e.g.:
const sh = StateHandler (state, dispatch)sh.on( (s) => s.completed === true, (s, dispatch) => dispatch(s))// modify statesh.exec()