Last active
April 16, 2016 13:49
-
-
Save avanslaars/52365a5fea734b2f7eb40ecd6c4086ea to your computer and use it in GitHub Desktop.
Rendering issue when attempting to clear an input value after sampling the value. It works if something in the node relies on data from the source stream, but with static values, re-rendering of the input with an empty (or default) value doesn't happen. This code works because the mapped value is being applied to the input as a class, but this i…
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
// Run it here: http://www.webpackbin.com/Nk5AREvJb | |
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.${name}`, {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