-
-
Save indigoviolet/5cbb969fefd2c86d2a4cd99f93edfdf4 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
export const createAsyncAction = (type, promiseCreator) => { | |
// get hash of args to pass through to promise creator | |
return (args = {}) => (dispatch, getState) => { | |
dispatch({ args, type, readyState: REQUEST }); | |
// pass args through | |
const promise = promiseCreator(args); | |
return promise.then( | |
data => { | |
dispatch({ args, type, readyState: SUCCESS, data }); | |
}, | |
error => { | |
dispatch({ args, type, readyState: FAILURE, error }); | |
} | |
); | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment