choo-reactive

0.0.0 • Public • Published

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
  })
}

See Also

Dependencies (1)

Dev Dependencies (0)

    Package Sidebar

    Install

    npm i choo-reactive

    Weekly Downloads

    3

    Version

    0.0.0

    License

    MIT

    Unpacked Size

    13.8 MB

    Total Files

    3887

    Last publish

    Collaborators

    • amongiants