Match-id-dda58446000d7d98ad097c8e72465ec8e13cfe58
This commit is contained in:
parent
10c8ee3786
commit
25c3a84991
|
@ -37,7 +37,7 @@ export function startUpdate(
|
|||
launchUpdateFromVNode(treeRoot);
|
||||
}
|
||||
|
||||
export function getFirstCustomDom(treeRoot: VNode | undefined | null): Element | Text | null {
|
||||
export function getFirstCustomDom(treeRoot?: VNode | null): Element | Text | null {
|
||||
if (treeRoot?.child) {
|
||||
return treeRoot.child.realNode;
|
||||
}
|
||||
|
|
|
@ -14,6 +14,32 @@ import {launchUpdateFromVNode} from '../TreeBuilder';
|
|||
import {onlyUpdateChildVNodes} from '../vnode/VNodeCreator';
|
||||
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 {
|
||||
const providerType: ProviderType<any> = processing.type;
|
||||
const contextType: ContextType<any> = providerType._context;
|
||||
|
@ -77,29 +103,3 @@ function matchDependencies(depContexts, context, vNode): boolean {
|
|||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue