Skip to content

Instantly share code, notes, and snippets.

@slightlytyler
Created February 22, 2018 01:53
Show Gist options
  • Save slightlytyler/4f6c7ecfbfdc89dbe1aa2cc9c9294206 to your computer and use it in GitHub Desktop.
Save slightlytyler/4f6c7ecfbfdc89dbe1aa2cc9c9294206 to your computer and use it in GitHub Desktop.
Promise problem
const withValues = mapProps(p => ({
...p,
onEvent: val => p.onEvent(val)
.then(res => res.data.val)
.catch(res => Promise.reject(res.data.errors))
}));
const withEffect = mapProps(p => ({
...p,
onEvent: val => p.onEvent(val)
.then(val => p.history.push(`/route/${val}`))
}));
const withMoreStuff = mapProps(p => ({
...p,
onEvent: val => p.onEvent(val)
.then(val => this.setState({ val }))
.catch(errors => this.setState({ errors }))
}));
const container = compose(
withValues,
withEffect,
withMoreStuff,
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment