https://github.com/jongacnik/choo-reactive
auto-trigger app render on state change
https://github.com/jongacnik/choo-reactive
Last synced: about 1 year ago
JSON representation
auto-trigger app render on state change
- Host: GitHub
- URL: https://github.com/jongacnik/choo-reactive
- Owner: jongacnik
- Created: 2018-11-12T20:07:49.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-11-12T20:09:01.000Z (over 7 years ago)
- Last Synced: 2025-02-28T09:21:02.037Z (over 1 year ago)
- Language: JavaScript
- Size: 1000 Bytes
- Stars: 11
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# choo-reactive
auto-trigger app render on state change. Uses [on-change](https://github.com/sindresorhus/on-change) under the hood.
## Example
Clone of the [choo example](https://github.com/choojs/choo#example) but app is automatically re-rendered on state update:
```js
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`
count is ${state.count}
Increment
`
function onclick () {
emit('increment', 1)
}
}
function countStore (state, emitter) {
state.count = 0
emitter.on('increment', function (count) {
state.count += count
})
}
```
## See Also
- [on-change](https://github.com/sindresorhus/on-change)
- [`Proxy` API](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy)