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:
Tim Wisniewski
2016-08-16 09:50:56 -04:00
committed by GitHub
parent 920129c8df
commit cdabe22e59
+6 -5
View File
@@ -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 }
}
} }
}) })
``` ```