UNPKG

1.87 kBMarkdownView Raw
1---
2id: redux-leaves
3title: reduxLeaves
4hide_title: true
5sidebar_label: reduxLeaves
6---
7
8# `reduxLeaves(initialState, [reducersDict = {}])`
9
10Returns a reducer function and an actions object.
11
12**See the [30 second demo](examples/basicExample.md)** for usage.
13
14## Parameters
15- [`initialState`](#initialstate) *(object)*: the state shape and initial values for your Redux store
16- [`reducersDict`](#reducersdict) *(object, optional)*: a collection of [leaf reducers](api/leafReducers.md) keyed by their [creator keys](api/creatorKeys.md)
17
18### `initialState`
19*(object)*
20
21This is the state shape and initial values for your Redux store.
22
23It is described as having state 'branches' and 'leaves'.
24
25#### Example
26
27```js
28const initialState = {
29 todos: {
30 byId: {},
31 allIds: []
32 },
33 visibilityFilter: "SHOW_ALL"
34}
35```
36
37### `reducersDict`
38*(object)*
39
40This is an object where every `key`-`value` pair is such that:
41- `value` *(function | object)* is a [leaf reducer](api/leafReducers.md);
42- `key` is a [creator key](api/creatorKeys.md) for that leaf reducer.
43
44#### Example
45
46```js
47const reducersDict = {
48 increment: (state, { payload }) => state + payload,
49 slice: {
50 argsToPayload: (begin, end) => [begin, end]
51 reducer: (state, { payload }) => state.slice(payload[0], payload[1])
52 }
53}
54```
55
56## Returns
57`array`, with two elements:
58- 0th: `reducer` *(function)*: a reducer function to pass to redux's `createStore`
59- 1st: [`actions`](api/actions.md) *(object)*: an object with same shape as `initialState`
60
61### `reducer`
62
63The root reducer for your Redux store.
64
65It listens to actions created through [`actions`](api/actions.md) at a given leaf for a given [creator key](api/creatorKeys.md), and updates that leaf's state using the [leaf reducer](api/leafReducers.md) keyed by the creator key.
66
67### `actions`
68
69See documentation on the [`actions`](api/actions.md) object.
\No newline at end of file