/
VNode.js
102 lines (86 loc) · 2.65 KB
/
VNode.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/* jshint newcap:false */
function VNode() {}
VNode.prototype = {
___VNode: function(finalChildCount, ownerComponent) {
this.___finalChildCount = finalChildCount;
this.___childCount = 0;
this.___firstChildInternal = null;
this.___lastChild = null;
this.___parentNode = null;
this.___nextSiblingInternal = null;
this.___ownerComponent = ownerComponent;
},
get ___firstChild() {
var firstChild = this.___firstChildInternal;
if (firstChild && firstChild.___DocumentFragment) {
var nestedFirstChild = firstChild.___firstChild;
// The first child is a DocumentFragment node.
// If the DocumentFragment node has a first child then we will return that.
// Otherwise, the DocumentFragment node is not *really* the first child and
// we need to skip to its next sibling
return nestedFirstChild || firstChild.___nextSibling;
}
return firstChild;
},
get ___nextSibling() {
var nextSibling = this.___nextSiblingInternal;
if (nextSibling) {
if (nextSibling.___DocumentFragment) {
var firstChild = nextSibling.___firstChild;
return firstChild || nextSibling.___nextSibling;
}
} else {
var parentNode = this.___parentNode;
if (parentNode && parentNode.___DocumentFragment) {
return parentNode.___nextSibling;
}
}
return nextSibling;
},
___appendChild: function(child) {
this.___childCount++;
if (this.___nodeName === "textarea") {
if (child.___Text) {
var childValue = child.___nodeValue;
this.___valueInternal = (this.___valueInternal || "") + childValue;
} else if (child.___preserve) {
this.___preserveTextAreaValue = true;
} else {
throw TypeError();
}
} else {
var lastChild = this.___lastChild;
child.___parentNode = this;
if (lastChild) {
lastChild.___nextSiblingInternal = child;
} else {
this.___firstChildInternal = child;
}
this.___lastChild = child;
}
return child;
},
___finishChild: function finishChild() {
if (this.___childCount === this.___finalChildCount && this.___parentNode) {
return this.___parentNode.___finishChild();
} else {
return this;
}
}
// ,toJSON: function() {
// var clone = Object.assign({
// nodeType: this.nodeType
// }, this);
//
// for (var k in clone) {
// if (k.startsWith('_')) {
// delete clone[k];
// }
// }
// delete clone._nextSibling;
// delete clone._lastChild;
// delete clone.parentNode;
// return clone;
// }
};
module.exports = VNode;