|
@@ -32,19 +32,21 @@ const promiseReducer = (state={}, action) => {
|
|
|
}
|
|
|
|
|
|
export const actionPromise = (name, promise) => {
|
|
|
+
|
|
|
const actionPending = () => ({ type: PROMISE, name, status: PENDING, payload: null, error: null })
|
|
|
const actionResolved = (payload) => ({ type: PROMISE, name, status: RESOLVED, payload, error: null })
|
|
|
const actionRejected = (error) => ({ type: PROMISE, name, status: REJECTED, payload: null, error })
|
|
|
+
|
|
|
return async (dispatch) => {
|
|
|
dispatch(actionPending())
|
|
|
let result;
|
|
|
try {
|
|
|
result = await promise
|
|
|
- dispatch(actionResolved(result))
|
|
|
+ dispatch(actionResolved(result)) // { type: PROMISE, name, status: RESOLVED, payload: result, error: null }
|
|
|
}
|
|
|
catch (e) {
|
|
|
history.push("/404")
|
|
|
- dispatch(actionRejected(e))
|
|
|
+ dispatch(actionRejected(e)) // { type: PROMISE, name, status: REJECTED, payload: null, error: e }
|
|
|
}
|
|
|
return result
|
|
|
}
|