Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc966726

Browse files
committed
Merge branch 'master' ofhttps://github.com/alexfoxy/juicr
2 parents88f21ee +aeccdcd commitc966726

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

‎README.md‎

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const juicr = new Juicr({ initialState: { count: 0 } })
3333
2) Add an action with a name and a function that returns the changed state:
3434
```javascript
3535
juicr.action("count", (amount,_state)=> {
36-
return { count: count+= amount }
36+
return { count:_state.count+= amount }
3737
})
3838
```
3939
3) Listen to state changes. You can either listen to a single property, an array or use`*` to listen to all changes:
@@ -48,29 +48,32 @@ setInterval(() => {
4848
juicr.dispatch("count",1)
4949
},1000)
5050
```
51-
Play with this example in CodePen.
51+
Play with this example in[CodePen](https://codepen.io/alexfoxy/pen/gyNaYw).
5252
53-
For use with React see #Usewith React & React Native
53+
For use with React see #use-with-react--react-native
5454
5555
## API
56-
###`newJuicr({ initialState={}, dev=false })`
56+
####`newJuicr({ initialState={}, dev=false })`
5757
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.
5858
59-
###`juicr.action('actionName', (data,_state)=> { })`
59+
60+
####`juicr.action('actionName', (data,_state)=> { })`
6061
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:
6162
```javascript
6263
juicr.action('delete', ({ id },_state)=> {
6364
return { items:_state.items.filter(t=>t.id!== id ) }
6465
})
6566
```
6667
67-
### `juicr.dispatch('actionName', data)`
68+
69+
#### `juicr.dispatch('actionName', data)`
6870
Dispatches an **action** with `data` on your Juicr. For example:
6971
```javascript
7072
juicr.dispatch("delete", { id:1 })
7173
```
7274
73-
###`juicr.listen('propName', (changedState,_state)=> { })`
75+
76+
####`juicr.listen('propName', (changedState,_state)=> { })`
7477
Listens to changes to the **state** either from an action, or a reaction. You can either specify a single property:
7578
```javascript
7679
juicr.listen("items", (changedState,_state)=> { })
@@ -83,7 +86,7 @@ Or use the special character `*` to listen to any changes on the state:
8386
```javascript
8487
juicr.listen("*", (changedState,_state)=> {})
8588
```
86-
###`juicr.reaction('propName', (changedState,_state)=> { })`
89+
####`juicr.reaction('propName', (changedState,_state)=> { })`
8790
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`*`.
8891
8992
```javascript
@@ -92,7 +95,8 @@ juicr.reaction('count', ({ count }, _state) => {
9295
})
9396
```
9497
95-
## Asynchronous actions
98+
99+
## Asynchronous actions
96100
Actions can return a`Promise` which resolves with the state changes. When dispatching use`.then` for triggering other actions or`.catch` for errors. Eg.
97101
98102
```javascript
@@ -136,9 +140,10 @@ Alternatively you could pass the entire juicr to your components and let them ha
136140
constructor(props) {
137141
...
138142
this.state= { username:'', photoUrl:'' }
139-
props.userJuicr.listen(["username","photoUrl", (changedState,_state)=> {
140-
this.setState({...changedState })
141-
})
142-
...
143+
144+
props.userJuicr.listen(["username","photoUrl", (changedState,_state)=> {
145+
this.setState({...changedState })
146+
})
147+
...
143148
}
144149
```

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp