Skip to content

Instantly share code, notes, and snippets.

@sammylupt
Last active June 24, 2016 01:11
Show Gist options
  • Save sammylupt/6c76733ccae554c03b2b5b0862579cde to your computer and use it in GitHub Desktop.
Save sammylupt/6c76733ccae554c03b2b5b0862579cde to your computer and use it in GitHub Desktop.
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)
}
}
@vasanthk
Copy link

vasanthk commented Jun 24, 2016

@scottluptowski
Minor modifications:
cartAddSuccess needs to be onSuccess and cartAddFailure => onFailure

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment