Skip to content

Instantly share code, notes, and snippets.

@sht5
Last active March 5, 2018 09:47
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 sht5/229aea45a4f146e86244171e4b54c924 to your computer and use it in GitHub Desktop.
Save sht5/229aea45a4f146e86244171e4b54c924 to your computer and use it in GitHub Desktop.
repetitive async actions
const requestToGetCoins = async() => {
return (dispatch) => {
dispatch(requestToGetCoinsInProgress());
try{
const users = await httpService.getCoins();
dispatch(requestToGetCoinsSuccess(users));
}
catch(e){
dispatch(requestToGetCoinsError(e));
}
};
};
const requestToGetCoinsSuccess = (coins) => {
return {
type: types.REQUEST_TO_GET_COINS_USERS_SUCCESS,
coins
};
};
const requestToGetCoinsInProgress = () => {
return {
type: types.REQUEST_TO_GET_COINS_USERS_IN_PROGRESS
};
};
const requestToGetCoinsError = () => {
return {
type: types.REQUEST_TO_GET_COINS_ERROR
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment