unnest-reducer
Utility to create a reducer from a nested object
Allows to write reducers in a nested fashion making them more readable when using long names, prefixes or suffixes.
Turns
ActionsTypesLOAD_PROFILE : {} {} {} {}
into a reducer function that works with reducer definitions similar to the following ones:
{} {} {} {}
Example
; const reducers = ActionsTypesLOAD_PROFILE : {} {} {} {}; const reducer = ;// ^^^^^^ -> Function that takes (state, action)// Will use `initialState` if `state` is omitted // The typical Redux stuff: const action = type: ActionsTypesSELECT_PROFILE payload: // ... ; const nextState = ;
API
The package exports one function:
reducers
- Object of reducer functions, will be flattened up to the first level using theglue
parameterinitialState
- Initial state to use, default isundefined
glue
- String used to join nested names, default is'_'
pre
- Pre-processing function(reducer function, key string) => function
that is passed the function and the (possibly nested) key of the reducer function. Must return a new function.