Skip to content

Instantly share code, notes, and snippets.

@farism
Created March 1, 2017 23:58
Show Gist options
  • Save farism/213096124d522458faee55f3725cdd6c to your computer and use it in GitHub Desktop.
Save farism/213096124d522458faee55f3725cdd6c to your computer and use it in GitHub Desktop.
import {div, input, li, ul, VNode} from '@cycle/dom'
import {MemoryStream, Stream} from 'xstream'
import xs from 'xstream'
import {Message} from '../../drivers/phoenix/PhoenixSource'
import {State} from './model'
import styles from './styles'
export default function view(
state$: MemoryStream<State>,
message$: Stream<Message[]>,
): Stream<VNode> {
return xs.combine(state$, message$).map(([state, messages]) => {
return div([
div(`.pane ${styles.pane}`, {
hook: {
postpatch: (oldVnode: VNode, vnode: VNode) => {
const el = vnode.elm as Element
if (state.autoScroll) {
el.scrollTop = el.scrollHeight - el.clientHeight
}
}
}
}, [
ul([
...messages.map(message => li(message.payload.value)),
]),
]),
div([
input(`.input ${styles.input}`, {props: {value: state.inputValue}}),
]),
])
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment