Skip to content

Instantly share code, notes, and snippets.

@kooparse
Created December 5, 2015 21:33
Show Gist options
  • Save kooparse/18facd1f60305f5fe979 to your computer and use it in GitHub Desktop.
Save kooparse/18facd1f60305f5fe979 to your computer and use it in GitHub Desktop.
async sync flow in quantum physic
export default function asyncMiddleware () {
return (dispatch) => (action) => {
const { promise, type, ...rest } = action;
const SUCCESS = type;
const REQUEST = type + '_REQUEST';
const FAILURE = type + '_FAILURE';
dispatch({ ...rest, type: REQUEST });
return promise
.then((result) => {
dispatch({ ...rest, result, type: SUCCESS });
return true;
})
.catch((error) => {
dispatch({ ...rest, error, type: FAILURE });
return false;
});
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment