Last active
June 24, 2016 01:11
-
-
Save sammylupt/6c76733ccae554c03b2b5b0862579cde to your computer and use it in GitHub Desktop.
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
const noop = () => {} | |
function formatProductForRequest(product) { | |
// ... | |
} | |
export function addToCart(product, onSuccess = noop, onFailure = noop) { | |
return (dispatch, getState) => { | |
dispatch(cartAddAttempt(()) | |
const params = formatProductForRequest(product) | |
fetch(params) | |
.then((res) => dispatch(cartAddSuccess(res))) | |
.then(onSuccess) | |
.catch((res) => dispatch(cartAddFailure(res))) | |
.then(onFailure) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@scottluptowski
Minor modifications:
cartAddSuccess
needs to beonSuccess
andcartAddFailure
=>onFailure