forked from dongyuanxin/pure-virtual-dom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
58 lines (51 loc) · 991 Bytes
/
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/**
* <div>
* <span>item 1</span>
* <li>item 2</li>
* </div>
*/
const a = el("div", {}, [
el("span", {}, ["item 1"])
]);
/**
* <div>
* <span>item 1</span>
* <li>item 2</li>
* </div>
*/
const b = el("div", {}, [
el("span", {}, ["item 1"]),
el("li", {}, ["item 2"])
]);
/**
* <div>
* <span>item 1</span>
* <li>hello world!</li>
* </div>
*/
const c = el("div", {}, [
el("span", {}, ["item 1"]),
el("li", {}, ["hello world!"])
]);
/**
* <div class="night">
* <span>item 1</span>
* <li>hello world!</li>
* </div>
*/
const d = el("div", { class: 'night' }, [
el("span", {}, ["item 1"]),
el("li", {}, ["hello world!"])
]);
const $root = document.querySelector("#root");
updateEl($root, a);
const btns = document.querySelectorAll('button')
btns[0].addEventListener('click', () => {
updateEl($root, b, a);
})
btns[1].addEventListener('click', () => {
updateEl($root, c, b);
})
btns[2].addEventListener('click', () => {
updateEl($root, d, c);
})