summaryrefslogtreecommitdiff
path: root/app/client/api
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2018-06-01 03:30:39 +0200
committerJules Laplace <julescarbon@gmail.com>2018-06-01 03:30:39 +0200
commit964ac7009e6db5a06233bdc07fa63778eebf2db7 (patch)
tree960ceb019514f960a6597b9b282baf4d5cd77607 /app/client/api
parentdd31a7b9a3af167808b04ffe2af3a66af8b17c33 (diff)
async commands!!
Diffstat (limited to 'app/client/api')
-rw-r--r--app/client/api/crud.actions.js14
-rw-r--r--app/client/api/crud.upload.js4
2 files changed, 13 insertions, 5 deletions
diff --git a/app/client/api/crud.actions.js b/app/client/api/crud.actions.js
index 1fcae81..f8b3bac 100644
--- a/app/client/api/crud.actions.js
+++ b/app/client/api/crud.actions.js
@@ -20,10 +20,14 @@ export function crud_actions(type) {
}
export const crud_action = (type, method, fn) => q => dispatch => {
- dispatch({ type: as_type(type, method + '_loading') })
- fn(q).then(data => {
- dispatch({ type: as_type(type, method), data })
- }).catch(e => {
- dispatch({ type: as_type(type, method + '_error') })
+ return new Promise ((resolve, reject) => {
+ dispatch({ type: as_type(type, method + '_loading') })
+ fn(q).then(data => {
+ dispatch({ type: as_type(type, method), data })
+ resolve(data)
+ }).catch(e => {
+ dispatch({ type: as_type(type, method + '_error') })
+ reject(e)
+ })
})
}
diff --git a/app/client/api/crud.upload.js b/app/client/api/crud.upload.js
index 65ae4e0..01c3e18 100644
--- a/app/client/api/crud.upload.js
+++ b/app/client/api/crud.upload.js
@@ -57,6 +57,7 @@ export function crud_upload(type, fd, data, dispatch) {
error: 'upload failed',
[type]: id,
})
+ reject(e)
return
}
dispatch && dispatch({
@@ -64,6 +65,7 @@ export function crud_upload(type, fd, data, dispatch) {
data,
[type]: id,
})
+ resolve(data)
}
function uploadFailed (evt) {
@@ -72,6 +74,7 @@ export function crud_upload(type, fd, data, dispatch) {
error: 'upload failed',
[type]: id,
})
+ reject(evt)
}
function uploadCancelled (evt) {
@@ -80,6 +83,7 @@ export function crud_upload(type, fd, data, dispatch) {
error: 'upload cancelled',
[type]: id,
})
+ reject(evt)
}
})
}