Skip to content

Instantly share code, notes, and snippets.

@indigoviolet
Created October 4, 2017 08:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save indigoviolet/5cbb969fefd2c86d2a4cd99f93edfdf4 to your computer and use it in GitHub Desktop.
Save indigoviolet/5cbb969fefd2c86d2a4cd99f93edfdf4 to your computer and use it in GitHub Desktop.
fin blog embed
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