Match-id-5684643f375c3d5f9612e974f8374ae4a3548172

This commit is contained in:
* 2022-01-25 11:38:32 +08:00 committed by *
parent 356874599a
commit a68c3b9897
3 changed files with 15 additions and 43 deletions

View File

@ -323,7 +323,7 @@ function diffArrayNodes(
if (firstChild && parentNode.tag === DomComponent && newChildren.length === 0) {
// if (false) {
FlagUtils.markClear(parentNode);
parentNode.ClearChild = firstChild;
parentNode.clearChild = firstChild;
} else {
deleteVNodes(parentNode, oldNode, rightEndOldNode);
}

View File

@ -313,48 +313,20 @@ function submitClear(vNode: VNode): void {
const cloneDom = realNode.cloneNode(false); // 复制节点后horizon的两个属性消失
cloneDom[internalKeys.VNode] = realNode[internalKeys.VNode];
cloneDom[internalKeys.props] = realNode[internalKeys.props];
// 删除节点
let currentParentIsValid = false;
// 这两个变量要一起更新
let currentParent;
travelVNodeTree(vNode, (node) => {
if (!currentParentIsValid) {
const parentObj = findDomParent(node);
currentParent = parentObj.parentDom;
currentParentIsValid = true;
}
const tag = node.tag;
if (tag === DomComponent || tag === DomText) {
const parentObj = findDomParent(vNode);
const currentParent = parentObj.parentDom;
const clearChild = vNode.clearChild as VNode;
// 卸载子vNode递归遍历子vNode
unmountNestedVNodes(node.ClearChild); // node.child 为空需要添加原有的child
unmountNestedVNodes(clearChild); // node.child 为空需要添加原有的child
// 在所有子项都卸载后删除dom树中的节点
removeChildDom(currentParent, node.realNode);
console.log(currentParent);
removeChildDom(currentParent, vNode.realNode);
clearVNode(clearChild);
currentParent.append(cloneDom);
vNode.realNode = cloneDom;
FlagUtils.removeFlag(vNode, Clear);
vNode.ClearChild = null;
} else if (tag === DomPortal) {
console.log(DomPortal);
if (node.child !== null) {
currentParent = node.outerDom;
}
} else {
unmountVNode(node);
}
}, (node) => {
// 如果是dom不用再遍历child
const tag = node.tag;
return tag === DomComponent || tag === DomText;
}, null, (node) => {
if (node.tag === DomPortal) {
// 当离开portal需要重新设置parent
currentParentIsValid = false;
}
});
vNode.clearChild = null;
}
function submitDeletion(vNode: VNode): void {

View File

@ -62,7 +62,7 @@ export class VNode {
ForceUpdate?: boolean;
Clear?: boolean;
} = {};
ClearChild: VNode|null = null;
clearChild: VNode|null = null;
// one tree相关属性
isCreated: boolean = true;
oldHooks: Array<Hook<any, any>> = []; // 保存上一次执行的hook