Match-id-0ec66063b933d6f41b5ae51bd1357e88e68b67ae
This commit is contained in:
parent
816a199970
commit
337b729402
|
@ -376,7 +376,7 @@ function diffArrayNodesHandler(
|
||||||
|
|
||||||
if (rightNewNode) {
|
if (rightNewNode) {
|
||||||
appendNode(rightNewNode);
|
appendNode(rightNewNode);
|
||||||
setVNodesCIndex(rightNewNode.next, prevNewNode.cIndex + 1);
|
setVNodesCIndex(rightNewNode.next, rightNewNode.cIndex + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return resultingFirstChild;
|
return resultingFirstChild;
|
||||||
|
@ -464,14 +464,14 @@ function diffArrayNodesHandler(
|
||||||
|
|
||||||
if (rightNewNode) {
|
if (rightNewNode) {
|
||||||
appendNode(rightNewNode);
|
appendNode(rightNewNode);
|
||||||
setVNodesCIndex(rightNewNode.next, prevNewNode.cIndex + 1);
|
setVNodesCIndex(rightNewNode.next, rightNewNode.cIndex + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return resultingFirstChild;
|
return resultingFirstChild;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 设置vNode中的cIndex属性,cIndex是节点在children中的位置
|
// 设置vNode中的cIndex属性,cIndex是节点在children中的位置
|
||||||
function setVNodesCIndex(startChild: VNode, startIdx: number) {
|
function setVNodesCIndex(startChild: VNode | null, startIdx: number) {
|
||||||
let node: VNode | null = startChild;
|
let node: VNode | null = startChild;
|
||||||
let idx = startIdx;
|
let idx = startIdx;
|
||||||
|
|
||||||
|
|
|
@ -187,15 +187,12 @@ export function onlyUpdateChildVNodes(processing: VNode): VNode | null {
|
||||||
return processing.child;
|
return processing.child;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 当跳过子树更新时,需要更新子树path
|
// 当跳过子树更新时,父节点path更新时,需要更新所有子树path
|
||||||
if (processing.child && processing.path !== processing.child.path.slice(0, processing.path.length)) {
|
if (processing.child && processing.path !== processing.child.path.slice(0, processing.path.length)) {
|
||||||
// 更新子树path
|
// bfs更新子树path
|
||||||
const queue: VNode[] = [processing];
|
const queue: VNode[] = [];
|
||||||
while (queue.length) {
|
|
||||||
const vNode = queue.shift()!;
|
|
||||||
|
|
||||||
// 忽略processing path重新计算
|
const putChildrenIntoQueue = (vNode: VNode) => {
|
||||||
vNode.path = vNode.parent.path + vNode.cIndex;
|
|
||||||
const child = vNode.child;
|
const child = vNode.child;
|
||||||
if (child) {
|
if (child) {
|
||||||
queue.push(child);
|
queue.push(child);
|
||||||
|
@ -206,6 +203,16 @@ export function onlyUpdateChildVNodes(processing: VNode): VNode | null {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
putChildrenIntoQueue(processing.child);
|
||||||
|
|
||||||
|
while (queue.length) {
|
||||||
|
const vNode = queue.shift()!;
|
||||||
|
|
||||||
|
vNode.path = vNode.parent.path + vNode.cIndex;
|
||||||
|
|
||||||
|
putChildrenIntoQueue(vNode)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// 子树无需工作
|
// 子树无需工作
|
||||||
return null;
|
return null;
|
||||||
|
|
Loading…
Reference in New Issue