Readme: fix effects example (#223)
Per #186. We could introduce `xtend` here to make a copy of `data` in order to keep it `addAndSave`, but if the purpose of this example is to illustrate an effect, that may seem overkill (unless accompanied by a longer explanation.
This commit is contained in:
@@ -297,15 +297,16 @@ app.model({
|
|||||||
namespace: 'todos',
|
namespace: 'todos',
|
||||||
state: { items: [] },
|
state: { items: [] },
|
||||||
effects: {
|
effects: {
|
||||||
addAndSave: (data, state, send, done) => {
|
fetch: (data, state, send, done) => {
|
||||||
http.post('/todo', {json: data.payload}, (err, res, body) => {
|
http('/todos', (err, res, body) => {
|
||||||
data.payload.id = body.id
|
send('todos:receive', body, done)
|
||||||
send('todos:add', data, done)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
reducers: {
|
reducers: {
|
||||||
add: (data, state) => ({ items: state.items.concat(data.payload) })
|
receive: (data, state) => {
|
||||||
|
return { items: data }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|||||||
Reference in New Issue
Block a user