client/src/createOptDis.ts in jason-rails-0.6.8 vs client/src/createOptDis.ts in jason-rails-0.7.0
- old
+ new
@@ -13,22 +13,24 @@
export default function createOptDis(schema, dispatch, restClient, serverActionQueue) {
const plurals = _.keys(schema).map(k => pluralize(k))
function enqueueServerAction (action) {
- serverActionQueue.addItem(action)
+ return serverActionQueue.addItem(action)
}
function dispatchServerAction() {
- const action = serverActionQueue.getItem()
- if (!action) return
+ const item = serverActionQueue.getItem()
+ if (!item) return
+ const { id, action } = item
+
restClient.post('/jason/api/action', action)
- .then(serverActionQueue.itemProcessed)
- .catch(e => {
- dispatch({ type: 'upsertLocalUi', data: { error: JSON.stringify(e) } })
- serverActionQueue.itemProcessed()
+ .then(({ data }) => serverActionQueue.itemProcessed(id, data))
+ .catch(error => {
+ dispatch({ type: 'jason/upsert', payload: { error } })
+ serverActionQueue.itemFailed(id, error)
})
}
setInterval(dispatchServerAction, 10)
@@ -37,9 +39,9 @@
const data = enrich(type, payload)
dispatch({ type, payload: data })
if (plurals.indexOf(type.split('/')[0]) > -1) {
- enqueueServerAction({ type, payload: data })
+ return enqueueServerAction({ type, payload: data })
}
}
}
\ No newline at end of file