- match
- withDefaultState
- concat
- combine
- handleAction
- handleActions
- updateStateAt
- mapState
- filterState
- constantState
- decorate
- Updater
Syntax
match(predicateUpdater, leftUpdater)match(predicateUpdater, leftUpdater, rightUpdater)match(predicateUpdater)(leftUpdater)match(predicateUpdater)(leftUpdater, rightUpdater)Description
Creates a proxy updater that:
- calls
leftUpdaterifpredicateUpdaterreturns true, or - calls
rightUpdaterifpredicateUpdaterreturns false andrightUpdateris defined, or - returns the state unchanged if
predicateUpdaterreturns false andrightUpdateris undefined.
Parameters
predicateUpdaterfunction (action: any): function (state: any): booleanleftUpdaterUpdaterrightUpdaterUpdater?
Examples
match(p, t, f)
// Is equivalent to
action => state => p(action)(state) ? t(action)(state) : f(action)(state)match(p, t)
// Is equivalent to
action => state => p(action)(state) ? t(action)(state) : stateReturns Updater
Syntax
withDefaultState(defaultState, updater)withDefaultState(defaultState)(updater)Description
Creates a proxy updater that:
calls updater with defaultState if incoming state is undefined, or calls it with the incoming state.
Parameters
defaultStateanyupdaterUpdater
Examples
withDefaultState(0, add)
// Is equivalent to
action => (state = 0) => add(action)(state)Returns Updater
Syntax
concat(...updaters)Description
Creates a proxy updater that:
calls each updater with the preceding updater's outgoing state (left-to-right).
Parameters
updaters...Updater
Examples
concat(f, g, h)
// Is equivalent to
action => state => h(action)(g(action)(f(action)(state)))Returns Updater
Syntax
combine(pathFragmentUpdaterMap)Description
Like combineReducers, but for updaters.
Parameters
pathFragmentUpdaterMapObject
Examples
combine({
foo: fooUpdater,
bar: barUpdater
})
// Is equivalent to
concat(
updateStateAt('foo', fooUpdater),
updateStateAt('bar', barUpdater)
)Returns Updater
Syntax
handleAction(actionType, updater)handleAction(actionType)(updater)Description
Creates a proxy updater that:
calls updater if actionType matches incoming action's type, or returns the state unchanged.
Parameters
Examples
handleAction('SOME_ACTION', someUpdater)
// Is equivalent to
match(action => () => action.type === 'SOME_ACTION', someUpdater)Returns Updater
Syntax
handleActions(actionTypeUpdaterMap)Description
Creates a proxy updater that:
delegates to a matching updater from actionTypeUpdaterMap based on the incoming action's type, or returns the state unchanged.
Parameters
actionTypeUpdaterMapObject
Examples
handleActions({
ACTION_ONE: updaterOne,
ACTION_TWO: updaterTwo
})
// Is equivalent to
concat(
handleAction('ACTION_ONE', updaterOne),
handleAction('ACTION_TWO', updaterTwo)
)Returns Updater
Syntax
updateStateAt(path, updater)updateStateAt(path)(updater)Description
Creates a proxy updater that:
calls updater with incoming state focused at path, then merges the result into outgoing state.
Parameters
Examples
const updater = updateStateAt('a.b', () => state => state + 1)
const state = { a: { b: 1 }, c: 0 }
updater()(state)
// Result: `{ a: { b: 2 }, c: 0 }`Returns Updater
Syntax
mapState(updater)Description
Creates a proxy updater that:
maps incoming state via updater as iteratee.
Parameters
updaterUpdater
Examples
mapState(action => state => state + action)
// Is equivalent to
action => state => state.map(item => item + action)Returns Updater
Syntax
filterState(updater)Description
Creates a proxy updater that:
filters incoming state via updater as predicate.
Parameters
updaterfunction (action: any): function (state: any): boolean
Examples
filterState(action => state => action > state)
// Is equivalent to
action => state => state.filter(item => action > item)Returns Updater
Syntax
constantState(value)Description
Creates an updater that always returns value.
Parameters
valueany
Examples
constantState('foo')
// Is equivalent to
() => () => 'foo'Returns Updater
Syntax
decorate(...fns, value)Description
Applies to value a function created by composing ...fns.
Parameters
fns...Functionvalueany
Examples
decorate(f, g, h, value)
// Is equivalent to
f(g(h(value)))decorate(
withDefaultState(0),
handleAction('ADD'),
action => state => state + action.payload
)
// Is equivalent to
withDefaultState(0, handleAction('ADD', action => state => state + action.payload))Returns any
Action-first curried reducer.
Type: function (action: any): function (state: any): any