Last active
May 11, 2017 09:19
-
-
Save whroman/394b280a2efcd21056b95c129acf09c1 to your computer and use it in GitHub Desktop.
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
// SomeConnectedComponent.js | |
// ============================ | |
// Before: | |
const mapDispatchToProps = (dispatch) => ({ | |
dispatch, | |
}) | |
const mapStateToProps = (state) => ({ | |
resumable: (state.exam.attempt.attemptUUID !== null), | |
const mergeProps = (stateProps, dispatchProps, ownProps) => { | |
const startOrResume = (stateProps.resumable) ? | |
examResumeAndUpdateAttempt : examStartAndCreateAttempt | |
return Object.assign( | |
{}, | |
dispatchProps, | |
ownProps, | |
{ | |
startOrResume, | |
dispatch: dispatchProps.dispatch, | |
} | |
) | |
} | |
export default connect(mapStateToProps, mapDispatchToProps, mergeProps)(Preparation) | |
// ============================ | |
// After: | |
const mapStateToProps = (state) => { | |
const resumable = state.exam.attempt.attemptUUID !== null | |
const startOrResume = resumable ? examResumeAndUpdateAttempt : examStartAndCreateAttempt | |
return { startOrResume } | |
} | |
export default connect(mapStateToProps)(Preparation) | |
// ============================ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment