-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.tsx
73 lines (62 loc) · 1.78 KB
/
index.tsx
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
70
71
72
73
'use strict'
//"build": "babel index.js --out-dir dist && cp vdom.js dist/vdom.js"
import { createVNode, patchNode, createDOMNode, patch } from '@';
let state = {
counter: 0,
onChange: () => {}
};
const increase = () => {
state.counter += 1;
state.onChange && state.onChange();
}
const decrease = () => {
state.counter -= 1;
state.onChange && state.onChange();
}
const createVApp = (state) => {
const { counter } = state;
return (
<div {...{ class: "container", "data-count": String(counter) }}>
<button {...{ class: "button", onclick: increase }} >
+1
</button>
<button {...{ class: "button", onclick: decrease }} >
-1
</button>
<div>
Счетчик: {String(counter)}
Контейнер
<ul>
Самый классный список:
<li>1. Котики</li>
<li>2. Собаки</li>
<li>3. Ежики</li>
</ul>
</div>
</div>
)
const testNode = createVNode(
'div',
{ id: 'root' },
[
createVNode('h1', {}, [`Какой-то текст для виртуального DOM`]),
createVNode('div', {}, [
createVNode('div', { class: 'perfect-text' }, [`Еще какой-то текст для примера ${counter}`]),
createVNode('div', {}, [
createVNode('div', {} , ['text1']),
createVNode('div', {}, ['text2', 'text3']),
'text4',
]),
createVNode('div', {}, ['kek']),
]),
createVNode('button', { onclick: onClick }, ['Какая-то кнопка']),
]
);
return testNode;
};
let root = document.getElementById("root");
let vApp = createVApp(state);
let app = patch(root, vApp);
state.onChange = () => {
app = patch(app, createVApp(state));
}