add documentation
This commit is contained in:
parent
64a36c4088
commit
91923bfd49
@ -1,5 +1,6 @@
|
|||||||
<!-- docs/_sidebar.md -->
|
<!-- docs/_sidebar.md -->
|
||||||
|
|
||||||
* [Home](/)
|
* [Home](/)
|
||||||
|
* [Concepts](concepts.md)
|
||||||
* API Reference
|
* API Reference
|
||||||
* [Updux](updux.md)
|
* [Updux](updux.md)
|
||||||
|
30
docs/concepts.md
Normal file
30
docs/concepts.md
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
# Updux concepts
|
||||||
|
|
||||||
|
## effects
|
||||||
|
|
||||||
|
Updux effects are a superset of redux middleware. I kept that format, and the
|
||||||
|
use of `next` mostly because I wanted to give myself a way to alter
|
||||||
|
actions before they hit the reducer, something that `redux-saga` and
|
||||||
|
`rematch` don't allow.
|
||||||
|
|
||||||
|
An effect has the signature
|
||||||
|
|
||||||
|
```js
|
||||||
|
const effect = ({ getState, dispatch, getRootState, selectors})
|
||||||
|
=> next => action => { ... }
|
||||||
|
```
|
||||||
|
|
||||||
|
The first argument is like the usual redux middlewareApi, except
|
||||||
|
for the availability of selectors and of the root updux's state.
|
||||||
|
|
||||||
|
Also, the function `dispatch` is augmented to be able to be called
|
||||||
|
with the allowed actions as props. For example, assuming that the action
|
||||||
|
`complete_todo` has been declared somewhere, then it's possible to do:
|
||||||
|
|
||||||
|
```js
|
||||||
|
updux.addEffect( 'todo_bankrupcy',
|
||||||
|
({ getState, dispatch }) => next => action => {
|
||||||
|
getState.forEach( todo => dispatch.complete_todo( todo.id ) );
|
||||||
|
}
|
||||||
|
)
|
||||||
|
```
|
@ -36,6 +36,23 @@ const { actions } = updux({
|
|||||||
|
|
||||||
actions.foo({ x: 1, y: 2 }); // => { type: foo, payload: { x:1, y:2 } }
|
actions.foo({ x: 1, y: 2 }); // => { type: foo, payload: { x:1, y:2 } }
|
||||||
actions.bar(1,2); // => { type: bar, payload: { x:1, y:2 } }
|
actions.bar(1,2); // => { type: bar, payload: { x:1, y:2 } }
|
||||||
|
|
||||||
|
|
||||||
|
#### selectors
|
||||||
|
|
||||||
|
Dictionary of selectors for the current updux. The updux also
|
||||||
|
inherit its dubduxes' selectors.
|
||||||
|
|
||||||
|
The selectors are available via the class' getter and, for
|
||||||
|
middlewares, the middlewareApi.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const todoUpdux = new Updux({
|
||||||
|
selectors: {
|
||||||
|
done: state => state.filter( ({done}) => done ),
|
||||||
|
byId: state => targetId => state.find( ({id}) => id === targetId ),
|
||||||
|
}
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
#### mutations
|
#### mutations
|
||||||
@ -332,3 +349,11 @@ baz(); // => { type: 'baz', payload: undefined }
|
|||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### selectors
|
||||||
|
|
||||||
|
Returns a dictionary of the
|
||||||
|
updux's selectors. Subduxes' selectors
|
||||||
|
are included as well (with the mapping to the sub-state already
|
||||||
|
taken care of you).
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user