You signed in with another tab or window.Reload to refresh your session.You signed out in another tab or window.Reload to refresh your session.You switched accounts on another tab or window.Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+10-6Lines changed: 10 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -53,24 +53,27 @@ Play with this example in [CodePen](https://codepen.io/alexfoxy/pen/gyNaYw).
53
53
For use with React see #use-with-react--react-native
54
54
55
55
## API
56
-
###`newJuicr({ initialState={}, dev=false })`
56
+
####`newJuicr({ initialState={}, dev=false })`
57
57
Initializes a new Juicr. Pass in an`initialState` object and an optional`dev` flag. When dev mode is enabled all changes to the state are printed to the console.
Adds a dispatchable **action** to the Juicr. Specify the`actionName` and a`function` that returns the state changes. The `data` is passed in from the **dispatch** call as well as the current Juicr `_state`. For example:
61
62
```javascript
62
63
juicr.action('delete', ({ id },_state)=> {
63
64
return { items:_state.items.filter(t=>t.id!== id ) }
64
65
})
65
66
```
66
67
67
-
### `juicr.dispatch('actionName', data)`
68
+
69
+
#### `juicr.dispatch('actionName', data)`
68
70
Dispatches an **action** with `data` on your Juicr. For example:
Reacts to changes in the state and returns new state changes, essentially like a computed property. Similar to **listen** you can react to changes on a single property, an array of properties, or any change using`*`.
Actions can return a`Promise` which resolves with the state changes. When dispatching use`.then` for triggering other actions or`.catch` for errors. Eg.