Created
December 5, 2015 21:33
-
-
Save kooparse/18facd1f60305f5fe979 to your computer and use it in GitHub Desktop.
async sync flow in quantum physic
This file contains hidden or 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 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