Match-id-312daf8aa3b9932a2847f98e404ff35e5ea88b01

This commit is contained in:
* 2022-02-17 11:47:15 +08:00 committed by *
parent d1df21f264
commit 9a3c6440a1
3 changed files with 11 additions and 15 deletions

View File

@ -18,7 +18,7 @@ import {
setProcessingClassVNode, setProcessingClassVNode,
setStartVNode setStartVNode
} from './GlobalVar'; } from './GlobalVar';
import { findDomParent, getSiblingVNode } from './vnode/VNodeUtils'; import { findDomParent } from './vnode/VNodeUtils';
import { import {
ByAsync, ByAsync,
BySync, BySync,
@ -108,7 +108,7 @@ function bubbleVNode(vNode: VNode): void {
break; break;
} }
const siblingVNode = getSiblingVNode(node); const siblingVNode = node.next;
if (siblingVNode !== null) { // 有兄弟vNode if (siblingVNode !== null) { // 有兄弟vNode
processing = siblingVNode; processing = siblingVNode;
return; return;

View File

@ -11,7 +11,7 @@ import {
isIteratorType, isIteratorType,
isObjectType, isObjectType,
} from './DiffTools'; } from './DiffTools';
import {getSiblingVNode, travelChildren} from '../vnode/VNodeUtils'; import { travelChildren } from '../vnode/VNodeUtils';
enum DiffCategory { enum DiffCategory {
TEXT_NODE = 'TEXT_NODE', TEXT_NODE = 'TEXT_NODE',
@ -249,7 +249,7 @@ function diffArrayNodes(
nextOldNode = oldNode; nextOldNode = oldNode;
oldNode = null; oldNode = null;
} else { } else {
nextOldNode = getSiblingVNode(oldNode); nextOldNode = oldNode.next;
} }
const canBeReuse = checkCanReuseNode(oldNode, newChildren[leftIdx]); const canBeReuse = checkCanReuseNode(oldNode, newChildren[leftIdx]);
@ -552,13 +552,13 @@ function diffObjectNodeHandler(
// 可以复用 // 可以复用
if (canReuseNode.tag === Fragment && newChild.type === TYPE_FRAGMENT) { if (canReuseNode.tag === Fragment && newChild.type === TYPE_FRAGMENT) {
resultNode = updateVNode(canReuseNode, newChild.props.children); resultNode = updateVNode(canReuseNode, newChild.props.children);
startDelVNode = getSiblingVNode(canReuseNode); startDelVNode = canReuseNode.next;
resultNode.next = null; resultNode.next = null;
} else if (isSameType(canReuseNode, newChild)) { } else if (isSameType(canReuseNode, newChild)) {
resultNode = updateVNode(canReuseNode, newChild.props); resultNode = updateVNode(canReuseNode, newChild.props);
resultNode.ref = newChild.ref; resultNode.ref = newChild.ref;
resultNode.belongClassVNode = newChild.belongClassVNode; resultNode.belongClassVNode = newChild.belongClassVNode;
startDelVNode = getSiblingVNode(resultNode); startDelVNode = resultNode.next;
resultNode.next = null; resultNode.next = null;
} }
} }
@ -578,7 +578,7 @@ function diffObjectNodeHandler(
// 可以复用 // 可以复用
if (canReuseNode.tag === DomPortal && canReuseNode.outerDom === newChild.outerDom) { if (canReuseNode.tag === DomPortal && canReuseNode.outerDom === newChild.outerDom) {
resultNode = updateVNode(canReuseNode, newChild.children || []); resultNode = updateVNode(canReuseNode, newChild.children || []);
startDelVNode = getSiblingVNode(canReuseNode); startDelVNode = canReuseNode.next;
resultNode.next = null; resultNode.next = null;
} }
} }

View File

@ -8,10 +8,6 @@ import {DomComponent, DomPortal, DomText, TreeRoot} from './VNodeTags';
import {isComment} from '../../dom/utils/Common'; import {isComment} from '../../dom/utils/Common';
import {getNearestVNode} from '../../dom/DOMInternalKeys'; import {getNearestVNode} from '../../dom/DOMInternalKeys';
export function getSiblingVNode(node) {
return node.next;
}
export function travelChildren(beginVNode: VNode, handleVNode: Function, isFinish?: Function) { export function travelChildren(beginVNode: VNode, handleVNode: Function, isFinish?: Function) {
let node: VNode | null = beginVNode; let node: VNode | null = beginVNode;
@ -58,7 +54,7 @@ export function travelVNodeTree(
} }
// 找兄弟,没有就往上再找兄弟 // 找兄弟,没有就往上再找兄弟
while (getSiblingVNode(node) === null) { while (node.next === null) {
if (node.parent === null || node.parent === overVNode) { if (node.parent === null || node.parent === overVNode) {
return null; return null;
} }
@ -69,7 +65,7 @@ export function travelVNodeTree(
} }
} }
// 找到兄弟 // 找到兄弟
const siblingVNode = getSiblingVNode(node); const siblingVNode = node.next;
siblingVNode.parent = node.parent; siblingVNode.parent = node.parent;
node = siblingVNode; node = siblingVNode;
} }
@ -175,7 +171,7 @@ export function getSiblingDom(vNode: VNode): Element | null {
findSibling: while (true) { findSibling: while (true) {
// 没有兄弟节点,找父节点 // 没有兄弟节点,找父节点
while (getSiblingVNode(node) === null) { while (node.next === null) {
// 没父节点,或父节点已经是根节点,则返回 // 没父节点,或父节点已经是根节点,则返回
if (node.parent === null || isDomContainer(node.parent)) { if (node.parent === null || isDomContainer(node.parent)) {
return null; return null;
@ -183,7 +179,7 @@ export function getSiblingDom(vNode: VNode): Element | null {
node = node.parent; node = node.parent;
} }
const siblingVNode = getSiblingVNode(node); const siblingVNode = node.next;
siblingVNode.parent = node.parent; siblingVNode.parent = node.parent;
node = siblingVNode; node = siblingVNode;