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-05-23 02:45:15 +09:00
|
|
|
update: (action, state) => ({ title: action.payload })
|
2016-05-11 13:51:17 +07:00
|
|
|
},
|
|
|
|
|
effects: {
|
2016-05-23 02:45:15 +09:00
|
|
|
update: (action, state, send) => (document.title = action.payload)
|
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)
|