For reusability, sometimes you might want to abstract out some custom reducer logic which can then be executed at arbitrary leaf state.

This can be done in two ways:

  1. Shorthand riducers
  2. Longhand riducers

Shorthand riducers

Shorthand 'riducers' are functions with the signature (leafState, action, treeState) => leafState.

When you pass a dictionary of these to riduce as a second argument, it automatically makes a corresponding action creator available.

By default, the action creator will take an optional single argument, that gets passed to your riducer logic as action.payload.

(This behaviour can be changed in a longhand riducer.)

Longhand riducers

Longhand riducer definitions benefit from being more strongly typed.