Last active
November 23, 2017 20:12
-
-
Save jongacnik/f9f339a9d108f156aa885bca96723d36 to your computer and use it in GitHub Desktop.
choop - basic example
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
var html = require('choop/html') | |
var devtools = require('choo-devtools') | |
var choop = require('choop') | |
var app = choop() | |
app.use(devtools()) | |
app.use(countStore) | |
app.route('*', mainView) | |
app.mount('body') | |
function mainView (state, emit) { | |
return html` | |
<main> | |
<h1>count is ${state.count}</h1> | |
<button onclick=${onclick}>Increment</button> | |
</main> | |
` | |
function onclick () { | |
emit('increment', 1) | |
} | |
} | |
function countStore (state, emitter) { | |
state.count = 0 | |
emitter.on('increment', function (count) { | |
state.count += count | |
emitter.emit('render') | |
}) | |
} |
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
{ | |
"dependencies": { | |
"choop": "3.0.0", | |
"choo-devtools": "2.2.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment