Skip to content

Instantly share code, notes, and snippets.

@laszlokorte
Created May 7, 2016 16:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save laszlokorte/2a9ae0accca2805bde3eb28c376fd660 to your computer and use it in GitHub Desktop.
Save laszlokorte/2a9ae0accca2805bde3eb28c376fd660 to your computer and use it in GitHub Desktop.
import {Observable as O} from "rx"
import hyper from "hyperscript-helpers"
const view = (DOM, model$) => {
const {div, h1, button} = hyper(DOM.h)
return DOM.prepare(model$.map(text =>
div([
h1(text),
button("Click me!"),
DOM.h('svg', {width: 100, height: 100}, [
DOM.h('circle', {cx: 50, cy: 50, r: 25, fill: 'black'}),
]),
]))
)
}
const intent = (DOM, vtree$) => {
const click$ = DOM.events(vtree$, "button", "click")
return {
click$,
}
}
const model = actions => O.merge([
actions.click$.map(() => text => text + "!"),
])
// The component
export default ({DOM, model$: state$, mux}) => {
const vdom$ = view(DOM, state$)
const actions = intent(DOM, vdom$)
const updateMod$ = state$.mod(
model(actions)
)
return mux({
DOM: vdom$,
model$: updateMod$,
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment