From 964ac7009e6db5a06233bdc07fa63778eebf2db7 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Fri, 1 Jun 2018 03:30:39 +0200 Subject: async commands!! --- app/client/api/crud.actions.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'app/client/api/crud.actions.js') 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) + }) }) } -- cgit v1.2.3-70-g09d2