Created
August 27, 2017 18:51
-
-
Save shibacomputer/5b2ed9e613a6f943dac033383e733172 to your computer and use it in GitHub Desktop.
This file contains 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
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