Skip to content

Instantly share code, notes, and snippets.

@perguth
Last active August 2, 2016 18:02
Show Gist options
  • Save perguth/c3429bf5f7d3df32e4f91a84030c7734 to your computer and use it in GitHub Desktop.
Save perguth/c3429bf5f7d3df32e4f91a84030c7734 to your computer and use it in GitHub Desktop.
Playing around with Yoshs Choo.
const choo = require('choo')
const app = choo()
app.model({
state: { title: 'Set the title' },
reducers: {
update: (action, state) => ({ title: action.value })
},
subscriptions: [
(send) => setInterval(() => {send('print', { payload: 'dog?' })}, 1000)
],
effects: {
print: (action) => {
console.log(action.payload)
}
}
})
const mainView = (params, state, send) => choo.view`
<main>
<h1>${state.title}</h1>
<input
type="text"
oninput=${(e) => send('update', { value: e.target.value })}>
</main>
`
app.router((route) => [
route('/', mainView)
])
const tree = app.start()
document.body.appendChild(tree)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment