reduxLeaves(initialState, [reducersDict = {}])
Returns a reducer function and an actions object.
See the 30 second demo for usage.
Parameters
initialState
(object): the state shape and initial values for your Redux storereducersDict
(object, optional): a collection of leaf reducers keyed by their creator keys
initialState
(object)
This is the state shape and initial values for your Redux store.
It is described as having state 'branches' and 'leaves'.
Example
const initialState = {
todos: {
byId: {},
allIds: []
},
visibilityFilter: "SHOW_ALL"
}
reducersDict
(object)
This is an object where every key
-value
pair is such that:
value
(function | object) is a leaf reducer;key
is a creator key for that leaf reducer.
Example
const reducersDict = {
increment: (state, { payload }) => state + payload,
slice: {
argsToPayload: (begin, end) => [begin, end]
reducer: (state, { payload }) => state.slice(payload[0], payload[1])
}
}
Returns
array
, with two elements:
- 0th:
reducer
(function): a reducer function to pass to redux'screateStore
- 1st:
actions
(object): an object with same shape asinitialState
reducer
The root reducer for your Redux store.
It listens to actions created through actions
at a given leaf for a given creator key, and updates that leaf's state using the leaf reducer keyed by the creator key.
actions
See documentation on the actions
object.