fc7d661c3d96e1d5325012e123fcee748ee61d0a.svn-base
1.86 KB
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
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.createTextNode = exports.setAttribute = exports.removeChildNode = exports.insertBeforeNode = exports.appendStaticNode = exports.appendChildNode = exports.createNode = void 0;
// Helper utilities implementing some common DOM methods to simplify reconciliation code
const createNode = tagName => ({
nodeName: tagName.toUpperCase(),
style: {},
attributes: {},
childNodes: [],
parentNode: null
});
exports.createNode = createNode;
const appendChildNode = (node, childNode) => {
if (childNode.parentNode) {
removeChildNode(childNode.parentNode, childNode);
}
childNode.parentNode = node;
node.childNodes.push(childNode);
}; // Same as `appendChildNode`, but without removing child node from parent node
exports.appendChildNode = appendChildNode;
const appendStaticNode = (node, childNode) => {
node.childNodes.push(childNode);
};
exports.appendStaticNode = appendStaticNode;
const insertBeforeNode = (node, newChildNode, beforeChildNode) => {
if (newChildNode.parentNode) {
removeChildNode(newChildNode.parentNode, newChildNode);
}
newChildNode.parentNode = node;
const index = node.childNodes.indexOf(beforeChildNode);
if (index >= 0) {
node.childNodes.splice(index, 0, newChildNode);
return;
}
node.childNodes.push(newChildNode);
};
exports.insertBeforeNode = insertBeforeNode;
const removeChildNode = (node, removeNode) => {
removeNode.parentNode = null;
const index = node.childNodes.indexOf(removeNode);
if (index >= 0) {
node.childNodes.splice(index, 1);
}
};
exports.removeChildNode = removeChildNode;
const setAttribute = (node, key, value) => {
node.attributes[key] = value;
};
exports.setAttribute = setAttribute;
const createTextNode = text => ({
nodeName: '#text',
nodeValue: text
});
exports.createTextNode = createTextNode;