Advertisement
Guest User

Untitled

a guest
Jun 30th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. const choo = require('choo')
  2. const app = choo()
  3.  
  4. function init (send) {
  5. send('start')
  6. }
  7.  
  8. function decrement (state) {
  9. if (state.count === 0) {
  10. // implode
  11. } else {
  12. return {count: state.count - 1}
  13. }
  14. }
  15.  
  16. app.model({
  17. state: {
  18. data: 'app',
  19. count: 5
  20. },
  21. effects: {
  22. start: (action, state, send) => setInterval(() => send('tick'), 1000)
  23. },
  24. reducers: {
  25. tick: (action, state) => decrement(state)
  26. },
  27. subscriptions: [init]
  28. })
  29.  
  30. function main (params, state, send) {
  31. return choo.view`<button>${state.count}</button>`
  32. }
  33.  
  34. app.router((route) => [
  35. route('/', main)
  36. ])
  37.  
  38. setTimeout(function() {
  39. const tree = app.start({name: 'app'})
  40. document.body.appendChild(tree)
  41. }, 3000)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement