choo-reactive
v0.0.0
Published
auto-trigger app render on state change
Downloads
9
Readme
choo-reactive
auto-trigger app render on state change. Uses on-change under the hood.
Example
Clone of the choo example but app is automatically re-rendered on state update:
var choo = require('choo')
var html = require('choo/html')
var devtools = require('choo-devtools')
var reactive = require('choo-reactive')
var app = choo()
app.use(devtools())
app.use(reactive())
app.use(countStore)
app.route('/', mainView)
app.mount('body')
function mainView (state, emit) {
return html`
<body>
<h1>count is ${state.count}</h1>
<button onclick=${onclick}>Increment</button>
</body>
`
function onclick () {
emit('increment', 1)
}
}
function countStore (state, emitter) {
state.count = 0
emitter.on('increment', function (count) {
state.count += count
})
}