Match-id-b6cac53463810555e2269155146dbe8d5ce72177

This commit is contained in:
* 2022-02-18 11:53:02 +08:00 committed by *
parent da571cecd3
commit 0be64ac289
6 changed files with 16 additions and 16 deletions

View File

@ -471,7 +471,7 @@ function diffIteratorNodesHandler(
parentNode: VNode, parentNode: VNode,
firstChild: VNode | null, firstChild: VNode | null,
newChildrenIterable: Iterable<any>, newChildrenIterable: Iterable<any>,
isComparing: boolean = true isComparing: boolean
): VNode | null { ): VNode | null {
const iteratorFn = getIteratorFn(newChildrenIterable); const iteratorFn = getIteratorFn(newChildrenIterable);
const iteratorObj = iteratorFn.call(newChildrenIterable); const iteratorObj = iteratorFn.call(newChildrenIterable);
@ -604,7 +604,7 @@ export function createChildrenByDiff(
parentNode: VNode, parentNode: VNode,
firstChild: VNode | null, firstChild: VNode | null,
newChild: any, newChild: any,
isComparing: boolean = true isComparing: boolean
): VNode | null { ): VNode | null {
const isFragment = isNoKeyFragment(newChild); const isFragment = isNoKeyFragment(newChild);
newChild = isFragment ? newChild.props.children : newChild; newChild = isFragment ? newChild.props.children : newChild;

View File

@ -56,7 +56,7 @@ function handleContextChange(processing: VNode, context: ContextType<any>): void
}, node => }, node =>
// 如果这是匹配的provider则不要更深入地扫描 // 如果这是匹配的provider则不要更深入地扫描
node.tag === ContextProvider && node.type === processing.type node.tag === ContextProvider && node.type === processing.type
, processing); , processing, null);
// 找到了依赖context的子节点触发一次更新 // 找到了依赖context的子节点触发一次更新
if (isMatch) { if (isMatch) {

View File

@ -88,7 +88,7 @@ export function bubbleRender(processing: VNode) {
}, node => }, node =>
// 已经append到父节点或者是DomPortal都不需要处理child了 // 已经append到父节点或者是DomPortal都不需要处理child了
node.tag === DomComponent || node.tag === DomText || node.tag === DomPortal node.tag === DomComponent || node.tag === DomText || node.tag === DomPortal
, processing); , processing, null);
} }
processing.realNode = dom; processing.realNode = dom;

View File

@ -17,7 +17,7 @@ function capturePortalComponent(processing: VNode) {
const newElements = processing.props; const newElements = processing.props;
if (processing.isCreated) { if (processing.isCreated) {
processing.child = createChildrenByDiff(processing, null, newElements); processing.child = createChildrenByDiff(processing, null, newElements, true);
} else { } else {
processing.child = createVNodeChildren(processing, newElements); processing.child = createVNodeChildren(processing, newElements);
} }

View File

@ -147,7 +147,7 @@ function hideOrUnhideAllChildren(vNode, isHidden) {
unHideDom(node.tag, instance, node.props); unHideDom(node.tag, instance, node.props);
} }
} }
}); }, null, vNode, null);
} }
function attachRef(vNode: VNode) { function attachRef(vNode: VNode) {
@ -216,7 +216,7 @@ function unmountNestedVNodes(vNode: VNode): void {
}, node => }, node =>
// 如果是DomPortal不需要遍历child // 如果是DomPortal不需要遍历child
node.tag === DomPortal node.tag === DomPortal
); , vNode, null);
} }
function submitAddition(vNode: VNode): void { function submitAddition(vNode: VNode): void {
@ -314,7 +314,7 @@ function unmountDomComponents(vNode: VNode): void {
} }
}, node => }, node =>
// 如果是dom不用再遍历child // 如果是dom不用再遍历child
node.tag === DomComponent || node.tag === DomText, null, (node) => { node.tag === DomComponent || node.tag === DomText, vNode, (node) => {
if (node.tag === DomPortal) { if (node.tag === DomPortal) {
// 当离开portal需要重新设置parent // 当离开portal需要重新设置parent
currentParentIsValid = false; currentParentIsValid = false;

View File

@ -27,11 +27,11 @@ export function travelChildren(beginVNode: VNode, handleVNode: Function, isFinis
export function travelVNodeTree( export function travelVNodeTree(
beginVNode: VNode, beginVNode: VNode,
handleVNode: Function, handleVNode: Function,
childFilter: Function = () => false, // 返回true不处理child childFilter: ((node: VNode) => boolean) | null, // 返回true不处理child
finishVNode?: VNode, // 结束遍历节点有时候和beginVNode不相同 finishVNode: VNode, // 结束遍历节点有时候和beginVNode不相同
handleWhenToParent?: Function handleWhenToParent: Function | null
): VNode | null { ): VNode | null {
const overVNode = finishVNode || beginVNode; const filter = childFilter === null;
let node = beginVNode; let node = beginVNode;
while (true) { while (true) {
@ -43,20 +43,20 @@ export function travelVNodeTree(
// 找子节点 // 找子节点
const childVNode = node.child; const childVNode = node.child;
if (childVNode !== null && !childFilter(node)) { if (childVNode !== null && (filter || !childFilter(node))) {
childVNode.parent = node; childVNode.parent = node;
node = childVNode; node = childVNode;
continue; continue;
} }
// 回到开始节点 // 回到开始节点
if (node === overVNode) { if (node === finishVNode) {
return null; return null;
} }
// 找兄弟,没有就往上再找兄弟 // 找兄弟,没有就往上再找兄弟
while (node.next === null) { while (node.next === null) {
if (node.parent === null || node.parent === overVNode) { if (node.parent === null || node.parent === finishVNode) {
return null; return null;
} }
node = node.parent; node = node.parent;
@ -119,7 +119,7 @@ export function findDomVNode(vNode: VNode): VNode | null {
return node; return node;
} }
return null; return null;
}); }, null, vNode, null);
} }
export function findDOMByClassInst(inst) { export function findDOMByClassInst(inst) {