-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
42 lines (35 loc) · 1.13 KB
/
main.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
import { rerenderVDOM, renderVDOM } from './render.js';
import { createComponentNode, h } from './transpile.js';
window.list = [1, 2, 3, 4, 5]
window.count = 0
function updateList(newList) {
window.list = newList;
rerenderVDOM(createComponentNode(App, { list: newList, count: window.count }))
}
function updateCount(newCount) {
window.count = newCount;
rerenderVDOM(createComponentNode(App, { count: newCount, list: window.list }))
}
const App = (props) => {
const { list, count = 0 } = props;
return h('div', { class: 'app', id: "app" },
h('div', { class: 'app', id: "1" },
h('h1', { id: "h1_v1" }, 'Simple vDOM'),
h('h1', { id: "h1_count" }, `Count ${count}`),
h(
'ul', { id: "ul" },
...list.map(item => h('li', { id: `li_${item}` }, item))
),
h('button', {
id: "updateCount",
onclick: () => updateCount(count + 1)
}, 'Atualize o count'),
h('button', {
id: "addList",
onclick: () => updateList([...list, 'oi'])
}, 'Adicione na lista')
)
);
};
const currentApp = createComponentNode(App, { list, count })
renderVDOM(currentApp)