Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const choo = require('choo')
- const app = choo()
- function init (send) {
- send('start')
- }
- function decrement (state) {
- if (state.count === 0) {
- // implode
- } else {
- return {count: state.count - 1}
- }
- }
- app.model({
- state: {
- data: 'app',
- count: 5
- },
- effects: {
- start: (action, state, send) => setInterval(() => send('tick'), 1000)
- },
- reducers: {
- tick: (action, state) => decrement(state)
- },
- subscriptions: [init]
- })
- function main (params, state, send) {
- return choo.view`<button>${state.count}</button>`
- }
- app.router((route) => [
- route('/', main)
- ])
- setTimeout(function() {
- const tree = app.start({name: 'app'})
- document.body.appendChild(tree)
- }, 3000)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement