Skip to content

Instantly share code, notes, and snippets.

@indigoviolet
Created October 4, 2017 08:42
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/7edcdb43d89e95914c4c71ed62975cda to your computer and use it in GitHub Desktop.
Save indigoviolet/7edcdb43d89e95914c4c71ed62975cda to your computer and use it in GitHub Desktop.
fin blog embed
// 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