Skip to content

Instantly share code, notes, and snippets.

@shibacomputer
Created August 27, 2017 18:51
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 shibacomputer/5b2ed9e613a6f943dac033383e733172 to your computer and use it in GitHub Desktop.
Save shibacomputer/5b2ed9e613a6f943dac033383e733172 to your computer and use it in GitHub Desktop.
var html = require('choo/html')
var log = require('choo-log')
var choo = require('choo')
var app = choo()
app.use(log())
app.use(validStore)
app.route('/', mainView)
app.mount('body')
function mainView (state, emit) {
return html`
<body>
<input type="text" oninput=${validateInput}/>
<button disabled=${state.valid}>Click me!</button>
</body>
`
function validateInput (e) {
if (e.target.value.length >= 16) {
emit('valid', false)
} else {
emit('valid', true)
}
}
}
function validStore (state, emitter) {
state.valid = false
emitter.on('valid', function (e) {
state.valid = e
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment