-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrender.js
More file actions
46 lines (40 loc) · 1.33 KB
/
Copy pathrender.js
File metadata and controls
46 lines (40 loc) · 1.33 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
import nodeOps from './nodeOps.js'
import { createVNode } from './text/renderer.js'
function patch(prevNode, nextNode, container) {
let el
if (prevNode.type !== nextNode.type) {
el = nextNode.el = nodeOps.create(nextNode.type)
nodeOps.append(container, el)
} else {
el = nextNode.el = prevNode.el
}
for (const key in nextNode.props) {
const prevProp = prevNode.props[key]
const nextProp = nextNode.props[key]
if (prevProp !== nextProp) {
if (key.startsWith('on')) {
if (!prevProp || (prevProp.toString() !== nextProp.toString())) {
nodeOps.on(el, key.substring(2).toLowerCase(), () => {
nextProp()
})
}
} else {
nodeOps.setAttr(el, key, nextProp);
}
}
}
if (nextNode.children instanceof Array) {
nextNode.children.forEach((child, index) => {
if (prevNode.children.hasOwnProperty(index)) {
patch(prevNode.children[index], child, el)
} else {
patch(createVNode(), child, el)
}
})
} else {
if (prevNode.children !== nextNode.children) {
nodeOps.insertHtml(el, nextNode.children)
}
}
}
export { patch }