docs: setup example section

This commit is contained in:
Yoshua Wuyts
2016-05-16 02:48:47 +07:00
parent 99e4e04e1b
commit 6eef04663d
2 changed files with 8 additions and 0 deletions
+30
View File
@@ -0,0 +1,30 @@
const choo = require('../')
const app = choo()
app.model('title', {
state: { title: 'my-demo-app' },
reducers: {
'update': (action, state) => ({ title: action.payload })
},
effects: {
'update': (action, state, send) => (document.title = action.payload)
}
})
const mainView = (params, state, send) => choo.view`
<main class="app">
<h1>${state.title}</h1>
<label>Set the title</label>
<input
type="text"
placeholder=${state.title}
oninput=${(e) => send('title:update', { payload: e.target.value })}>
</main>
`
app.router((route) => [
route('/', mainView)
])
const tree = app.start()
document.body.appendChild(tree)