Match-id-dda58446000d7d98ad097c8e72465ec8e13cfe58

This commit is contained in:
* 2022-01-21 10:00:29 +08:00 committed by *
parent 10c8ee3786
commit 25c3a84991
2 changed files with 27 additions and 27 deletions

View File

@ -37,7 +37,7 @@ export function startUpdate(
launchUpdateFromVNode(treeRoot); launchUpdateFromVNode(treeRoot);
} }
export function getFirstCustomDom(treeRoot: VNode | undefined | null): Element | Text | null { export function getFirstCustomDom(treeRoot?: VNode | null): Element | Text | null {
if (treeRoot?.child) { if (treeRoot?.child) {
return treeRoot.child.realNode; return treeRoot.child.realNode;
} }

View File

@ -14,6 +14,32 @@ import {launchUpdateFromVNode} from '../TreeBuilder';
import {onlyUpdateChildVNodes} from '../vnode/VNodeCreator'; import {onlyUpdateChildVNodes} from '../vnode/VNodeCreator';
import {setParentsChildShouldUpdate} from '../vnode/VNodeShouldUpdate'; import {setParentsChildShouldUpdate} from '../vnode/VNodeShouldUpdate';
// 从当前子节点开始向下遍历找到消费此context的组件并更新
function handleContextChange(processing: VNode, context: ContextType<any>): void {
const vNode = processing.child;
if (vNode === null) {
return;
}
let isMatch = false;
// 从vNode开始遍历
travelVNodeTree(vNode, (node) => {
const depContexts = node.depContexts;
if (depContexts.length) {
isMatch = matchDependencies(depContexts, context, node) ?? isMatch;
}
}, (node) => {
// 如果这是匹配的provider则不要更深入地扫描
return node.tag === ContextProvider && node.type === processing.type;
}, processing);
// 找到了依赖context的子节点触发一次更新
if (isMatch) {
launchUpdateFromVNode(processing);
}
}
function captureContextProvider(processing: VNode): VNode | null { function captureContextProvider(processing: VNode): VNode | null {
const providerType: ProviderType<any> = processing.type; const providerType: ProviderType<any> = processing.type;
const contextType: ContextType<any> = providerType._context; const contextType: ContextType<any> = providerType._context;
@ -77,29 +103,3 @@ function matchDependencies(depContexts, context, vNode): boolean {
return false; return false;
} }
// 从当前子节点开始向下遍历找到消费此context的组件并更新
function handleContextChange(processing: VNode, context: ContextType<any>): void {
const vNode = processing.child;
if (vNode === null) {
return;
}
let isMatch = false;
// 从vNode开始遍历
travelVNodeTree(vNode, (node) => {
const depContexts = node.depContexts;
if (depContexts.length) {
isMatch = matchDependencies(depContexts, context, node) ?? isMatch;
}
}, (node) => {
// 如果这是匹配的provider则不要更深入地扫描
return node.tag === ContextProvider && node.type === processing.type;
}, processing);
// 找到了依赖context的子节点触发一次更新
if (isMatch) {
launchUpdateFromVNode(processing);
}
}