Last active
November 5, 2015 20:17
-
-
Save sholden/92d5e188f626371f75d4 to your computer and use it in GitHub Desktop.
api call dispatch
This file contains 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 const TRUECASH_OFFER_REQUEST = "TRUECASH_OFFER_REQUEST"; | |
export const TRUECASH_OFFER_SUCCESS = "TRUECASH_OFFER_SUCCESS"; | |
export const TRUECASH_OFFER_FAILURE = "TRUECASH_OFFER_FAILURE"; | |
export function fetchTruecashOffer(pag, offerId) { | |
return { | |
pag, | |
offerId, | |
[CALL_API]: { | |
endpoint: `/my_api_endpoint`, | |
types: [TRUECASH_OFFER_REQUEST, TRUECASH_OFFER_SUCCESS, TRUECASH_OFFER_FAILURE] | |
} | |
} | |
} | |
export function loadTruecashOffer (offerId) { | |
return (dispatch, getState) => { | |
const state = getState(); | |
if (state.offer.loaded) { | |
return Promise.resolve(); | |
} | |
return dispatch(fetchTruecashOffer(pag, offerId)).then( | |
result => { | |
dispatch({type: "PROMISE_COMPLETE", result}); | |
if (result.type == TRUECASH_OFFER_SUCCESS) { | |
dispatch({type: "RECEIVE_OFFER", data: result.response.data}); | |
} else { | |
dispatch({type: "OFFER_ERROR", data: result.response.data}); | |
} | |
} | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment