btheado / choo-detached

A wrapper around choo API that allows to use choo components without a baked-in routing layer.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

choo-detached

npm version

A wrapper around choo API that allows to use choo components without a baked-in routing layer.

JavaScript Style Guide

Example

var choo = require('choo-detached')
var html = require('choo-detached/html')
var log = require('choo-log')

var app = choo()
app.use(log())
app.use(countStore)
app.component(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
    emitter.emit('render')
  })
}

About

A wrapper around choo API that allows to use choo components without a baked-in routing layer.

License:MIT License


Languages

Language:JavaScript 100.0%