Last active
May 13, 2018 16:38
-
-
Save jamestthompson3/15272b3d3b0d4845c4b41931c7c08a8d 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
import { get } from 'lodash' | |
import { createEventHandler } from 'recompose' | |
const selectUser = mapPropsStream(props$ => { | |
const { stream: selected$, handler: userSelect } = createEventHandler() | |
return props$.pipe( | |
switchMap(props => { | |
const userInURL = get(props, 'match.params.user') | |
return selected$ | |
.pipe( | |
startWith( | |
props.userList | |
&& userInURL | |
? props.userList.find(userInList => userInList.user === userInURL) | |
: props.userList[0] | |
) | |
) | |
.pipe(map(selectedUser => ({ ...props, selectedUser, userSelect }))) | |
}) | |
) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment