Files
buuh/examples/title/client.js
T

40 lines
783 B
JavaScript
Raw Normal View History

2016-05-23 02:45:15 +09:00
const choo = require('../../')
2016-06-30 08:18:07 -07:00
const html = require('../../html')
2016-05-11 13:51:17 +07:00
const app = choo()
2016-05-23 02:45:15 +09:00
app.model({
namespace: 'input',
state: {
title: 'my demo app'
},
2016-05-11 13:51:17 +07:00
reducers: {
2016-07-02 21:09:08 -04:00
update: (data, state) => ({ title: data.payload })
2016-05-11 13:51:17 +07:00
},
effects: {
update: (data, state, send, done) => {
document.title = data.payload
done()
}
2016-05-11 13:51:17 +07:00
}
})
2016-07-02 00:13:13 +02:00
const mainView = (state, prev, send) => {
2016-06-30 08:18:07 -07:00
return html`
2016-05-23 02:45:15 +09:00
<main class="app">
<h1>${state.input.title}</h1>
<label>Set the title</label>
<input
type="text"
placeholder=${state.input.title}
oninput=${(e) => send('input:update', { payload: e.target.value })}>
</main>
`
}
2016-05-11 13:51:17 +07:00
app.router((route) => [
route('/', mainView)
])
2016-05-11 14:56:18 +07:00
const tree = app.start()
document.body.appendChild(tree)