Skip to content

Commit

Permalink
Merge pull request #63 from richardcrng/faqs
Browse files Browse the repository at this point in the history
Faqs
  • Loading branch information
richardcrng committed Apr 17, 2019
2 parents cf55195 + c4a2b89 commit 53fa882
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ Manage every leaf of your state tree with *pleasure*, *precision* and *predictab
- [Action creators: `create`](https://github.com/richardcrng/redux-leaves/tree/master/docs/create)
- [Custom action creators via `customLogic`](https://github.com/richardcrng/redux-leaves/tree/master/docs/customLogic.md)

#### [FAQs](#faqs)
- [What actions can I dispatch to the store?](#what-actions-can-i-dispatch-to-the-store)
- [Will dispatched actions mutate the store state?](#will-dispatched-actions-mutate-the-stores-state)

## 30 second demo

### 1. Pleasingly little boilerplate
Expand Down Expand Up @@ -76,13 +80,13 @@ store.dispatch(actions.nested.state.manageable.create.apply(state => state.toUpp

### Problem

I have found that [Redux](https://redux.js.org/) and [Redux DevTools](https://github.com/zalmoxisus/redux-devtools-extension) both work great for following what is happening in your app.<sup>1</sup>
[Redux](https://redux.js.org/) and [Redux DevTools](https://github.com/zalmoxisus/redux-devtools-extension) both work great for following what is happening in your app.<sup>1</sup>

However, there are three pain points that I encountered:
However, there are three pain points that at least one developer has encountered:

1. **Ugly boilerplate maintenance**: one more slice of state = another load of action types, creators and reducers to write.
2. **Unhelpfully named constants**: what was `NONTRIVIAL_THING_HAPPENED` meant to do, again...?
3. **Repetitive reducer logic**: an action that updates some slice of state to true? *How novel!*
3. **Repetitive reducer logic**: an action that updates some slice of state to `true`? *How novel!*

<sup>1</sup> *cf. what you* intended *to happen in your app...*

Expand All @@ -105,7 +109,21 @@ dispatch(actions.distressingly.and.foolishly.deeply.nested.counter.create.increm
'distressingly/and/foolishly/deeply/nested/counter/asNumber.INCREMENT'
```

#### API reference
## FAQs

### What actions can I dispatch to the store?

The `reducer` produced by `reduxLeaves` only knows how to update state in response to the `actions` produced by `reduxLeaves` - but there's a full [`create` API](https://github.com/richardcrng/redux-leaves/tree/master/docs/create) which shows what actions you can dispatch (including [`create.apply`](https://github.com/richardcrng/redux-leaves/tree/master/docs/create#createapplycallback), which takes a callback function to update state).

If you desire further customisation, you can add custom action creators to the `actions` returned by `reduxLeaves`, via an optional [`customLogic`](https://github.com/richardcrng/redux-leaves/tree/master/docs/customLogic.md) argument.


### Will dispatched actions mutate the store's state?

Even if you dispatch an action that looks like it will mutate state (e.g. `create.apply(n => n++)`), `reduxLeaves`'s reducer enforces immutability (using [Immer](https://github.com/immerjs/immer)).


## API reference
- [Core: `reduxLeaves(initialState, [customLogic = {}])`](https://github.com/richardcrng/redux-leaves/tree/master/docs)
- [Action creators: `create`](https://github.com/richardcrng/redux-leaves/tree/master/docs/create)
- [Custom action creators via `customLogic`](https://github.com/richardcrng/redux-leaves/tree/master/docs/customLogic.md)

0 comments on commit 53fa882

Please sign in to comment.