-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathclient.js
More file actions
39 lines (33 loc) · 854 Bytes
/
client.js
File metadata and controls
39 lines (33 loc) · 854 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const choo = require('choo');
const html = require('choo/html');
const app = choo();
const Choodown = require('./choodown');
const PREVIEW = 'PREVIEW';
const EDIT = 'EDIT';
app.model({
namespace: 'choodown',
state: {
text: '',
mode: 'EDIT'
},
reducers: {
updateText: (state, data) => ({text: data}),
toggleMode: (state, data) => ({mode: state.mode === PREVIEW ? EDIT : PREVIEW})
}
});
const mainView = (state, prev, send) => {
const choodown = Choodown({
text: state.choodown.text,
mode: state.choodown.mode,
onChange: (e) => send('choodown:updateText', e.target.value),
onToggle: () => send('choodown:toggleMode')
});
return html`
<main>
<h1>Choodown demo</h1>
${choodown}
</main>`
};
app.router(['/', mainView]);
const tree = app.start();
document.body.appendChild(tree);