Skip to content

Instantly share code, notes, and snippets.

@jamestthompson3
Last active May 13, 2018 16:38
Show Gist options
  • Save jamestthompson3/15272b3d3b0d4845c4b41931c7c08a8d to your computer and use it in GitHub Desktop.
Save jamestthompson3/15272b3d3b0d4845c4b41931c7c08a8d to your computer and use it in GitHub Desktop.
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