add documentation

typescript
Yanick Champoux 2020-02-02 23:45:16 -05:00
parent 64a36c4088
commit 91923bfd49
3 changed files with 56 additions and 0 deletions

View File

@ -1,5 +1,6 @@
<!-- docs/_sidebar.md -->
* [Home](/)
* [Concepts](concepts.md)
* API Reference
* [Updux](updux.md)

30
docs/concepts.md Normal file
View 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 ) );
}
)
```

View File

@ -36,6 +36,23 @@ const { actions } = updux({
actions.foo({ x: 1, y: 2 }); // => { type: foo, 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
@ -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).