Created
February 22, 2018 01:53
-
-
Save slightlytyler/4f6c7ecfbfdc89dbe1aa2cc9c9294206 to your computer and use it in GitHub Desktop.
Promise problem
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 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