/
app.js
69 lines (58 loc) · 1.26 KB
/
app.js
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
const html = require('choo/html')
const choo = require('choo')
const xtend = require('xtend')
const BaseShape = require('./base-shape')
const model = {
state: {
pattern: {},
selectedPart: null,
selectedPoint: null,
},
reducers: {
setPart: function (state, data) {
},
setPoint: function (state, data) {
},
update: function (state, data) {
console.log(state, data)
return { title: data }
}
}
}
function mainView (state, prev, send) {
return html`
<main>
${BaseShape(state.pattern.parts)}
<pre>${JSON.stringify(state.pattern, null, 2)}</pre>
</main>
`
function update (e) {
send('update', e.target.value)
}
}
function startApp (initialState) {
const app = choo()
app.router(['/', mainView])
if (initialState) {
model.state = xtend(model.state, initialState)
}
app.model(model)
const el = app.start()
return el
}
// const yo = require('yo-yo')
// class App {
// constructor (initialState) {
// this.el = this.render(initialState)
// }
// render (state) {
// return yo`
// <pre>${JSON.stringify(state, null, 2)}</pre>
// `
// }
// setState (state) {
// const el = this.render(state)
// yo.update(this.el, el)
// }
// }
module.exports = startApp