Last active
April 16, 2016 13:48
-
-
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
This file contains hidden or 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
//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