Skip to content

Commit 5f8cf2f

Browse files
committed
add 《实现 Virtual DOM 下的一个 VNode 节点》
1 parent 5deb552 commit 5f8cf2f

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
class VNode {
2+
constructor (tag, data, children, text, elm) {
3+
this.tag = tag;
4+
this.data = data;
5+
this.children = children;
6+
this.text = text;
7+
this.elm = elm;
8+
}
9+
}
10+
11+
createEmptyVNode () {
12+
const node = new VNode();
13+
node.text = '';
14+
return node;
15+
}
16+
17+
function createTextVNode (val) {
18+
return new VNode(undefined, undefined, undefined, String(val));
19+
}
20+
21+
function cloneVNode (node) {
22+
const cloneVnode = new VNode(
23+
node.tag,
24+
node.data,
25+
node.children,
26+
node.text,
27+
node.elm
28+
);
29+
}

0 commit comments

Comments
 (0)