1 | # Redux Leaves
|
2 |
|
3 | Write once. Reduce anywhere.
|
4 |
|
5 | ![Travis (.org)](https://img.shields.io/travis/richardcrng/redux-leaves.svg)
|
6 | [![Coverage Status](https://coveralls.io/repos/github/richardcrng/redux-leaves/badge.svg?branch=buttons)](https://coveralls.io/github/richardcrng/redux-leaves?branch=buttons)
|
7 | ![David](https://img.shields.io/david/richardcrng/redux-leaves.svg)
|
8 | [![install size](https://packagephobia.now.sh/badge?p=redux-leaves)](https://packagephobia.now.sh/result?p=redux-leaves)
|
9 | [![npm version](https://badge.fury.io/js/redux-leaves.svg)](https://badge.fury.io/js/redux-leaves)
|
10 | [![Maintainability](https://api.codeclimate.com/v1/badges/371605931cb9f824e25c/maintainability)](https://codeclimate.com/github/richardcrng/redux-leaves/maintainability)
|
11 |
|
12 | ## Example
|
13 |
|
14 | ```js
|
15 | import { createStore } from 'redux'
|
16 | import reduxLeaves, { bundle } = from 'redux-leaves'
|
17 |
|
18 | // set up with initial state
|
19 | const initialState = {
|
20 | counter: 0,
|
21 | list: [],
|
22 | props: {}
|
23 | }
|
24 |
|
25 | const [reducer, actions] = reduxLeaves(initialState)
|
26 | const store = createStore(reducer)
|
27 |
|
28 | // setup complete! Now dispatch actions to your heart's content
|
29 |
|
30 | console.log(store.getState())
|
31 | // => { counter: 0, list: [], props: {} }
|
32 |
|
33 | store.dispatch(actions.counter.create.increment(10))
|
34 | console.log(store.getState())
|
35 | // => { counter: 10, list: [], props: {} }
|
36 |
|
37 | store.dispatch(actions.list.create.push('foo'))
|
38 | console.log(store.getState())
|
39 | // => { counter: 10, list: ['foo'], props: {} }
|
40 |
|
41 | const compoundAction = bundle([
|
42 | actions.counter.create.reset(),
|
43 | actions.list[0].create.concat('bar'),
|
44 | actions.props.at.arbitrary.path.create.update('here I am!')
|
45 | ])
|
46 |
|
47 | store.dispatch(compoundAction)
|
48 | console.log(store.getState())
|
49 | /*
|
50 | => {
|
51 | counter: 0,
|
52 | list: ['foobar'],
|
53 | props: { at: { arbitrary: { path: 'here I am!' } } }
|
54 | }
|
55 | */
|
56 | ```
|
57 |
|
58 | ## Documentation
|
59 | ```bash
|
60 | npm install --save redux-leaves
|
61 | ```
|
62 |
|
63 | [Main documentation website](https://redux-leaves.js.org)
|
64 |
|
65 | ### Getting started
|
66 | - [Overview](https://redux-leaves.js.org/docs/intro/overview)
|
67 | - [30 second demo](https://runkit.com/richardcrng/redux-leaves-playground/)
|
68 |
|
69 | ### API reference
|
70 | - [Core: `reduxLeaves(initialState, reducers)`](https://redux-leaves.js.org/docs/redux-leaves)
|
71 |
|
72 | ### Testing
|
73 |
|
74 | To run all tests locally:
|
75 |
|
76 | ```bash
|
77 | git clone git@github.com:richardcrng/redux-leaves.git
|
78 | cd redux-leaves && npm run test a
|
79 | ```
|
80 |
|
81 | Most tests are located alongside their relevant API documentation in the [docs](/docs) folder.
|