-
-
Save indigoviolet/7edcdb43d89e95914c4c71ed62975cda to your computer and use it in GitHub Desktop.
fin blog embed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// status constants | |
export const REQUEST = 'request'; | |
export const SUCCESS = 'success'; | |
export const FAILURE = 'failure'; | |
export const createAsyncAction = (type, promiseCreator) => { | |
return () => (dispatch, getState) => { | |
dispatch({ type, readyState: REQUEST }); | |
const promise = promiseCreator(); | |
return promise.then( | |
data => { | |
dispatch({ type, readyState: SUCCESS, data }); | |
}, | |
error => { | |
dispatch({ type, readyState: FAILURE, error }); | |
} | |
); | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment