Skip to content

Instantly share code, notes, and snippets.

@avanslaars
Last active April 16, 2016 13:48
Show Gist options
  • Save avanslaars/8e8373f997ef6082fdfd395d87bb9a0b to your computer and use it in GitHub Desktop.
Save avanslaars/8e8373f997ef6082fdfd395d87bb9a0b to your computer and use it in GitHub Desktop.
First code sample for a blog post about doing this wrong before getting it right
//http://www.webpackbin.com/4kRwlEo1Z
import Motorcycle from '@motorcycle/core'
import {div, label, input, hr, h1, makeDOMDriver} from '@motorcycle/dom';
import most from 'most'
function main(sources) {
const input$ = sources.DOM.select('.field').events('input')
const click$ = sources.DOM.select('.btn').events('click')
const sinks = {
DOM: click$
.sample((in$) => in$, input$)
.map(ev => ev.target.value)
.startWith('')
.map(name =>
div([
label('Name:'),
input('.field', {attrs: {type: 'text'}, props: {value:''}}),
input('.btn', {attrs:{type:'submit',value:'Save'}}),
hr(),
h1('Hello ' + name)
])
)
};
return sinks;
}
Motorcycle.run(main, { DOM: makeDOMDriver('#app') });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment