Match-id-29421900668faf7d435ef9e587e4d8718e0d2524
This commit is contained in:
commit
f294673004
|
@ -1,6 +1,6 @@
|
|||
import type {VNode} from './Types';
|
||||
|
||||
// 当前处理的classVNode,用于inst.refs用法中的
|
||||
// 当前处理的classVNode,用于设置inst.refs
|
||||
let processingClassVNode: VNode | null = null;
|
||||
export function getProcessingClassVNode(): VNode | null {
|
||||
return processingClassVNode;
|
||||
|
|
|
@ -10,7 +10,7 @@ import { runAsyncEffects } from './submit/HookEffectHandler';
|
|||
import { handleRenderThrowError } from './ErrorHandler';
|
||||
import componentRenders from './render';
|
||||
import {
|
||||
BuildCompleted, BuildErrored,
|
||||
BuildCompleted,
|
||||
BuildFatalErrored,
|
||||
BuildInComplete, getBuildResult,
|
||||
getStartVNode,
|
||||
|
@ -37,12 +37,11 @@ import {
|
|||
updateShouldUpdateOfTree
|
||||
} from './vnode/VNodeShouldUpdate';
|
||||
|
||||
// 当前运行的vNode节点
|
||||
let processing: VNode | null = null;
|
||||
|
||||
// 不可恢复错误
|
||||
let unrecoverableErrorDuringBuild: any = null;
|
||||
|
||||
// 当前运行的vNode节点
|
||||
let processing: VNode | null = null;
|
||||
export function setProcessing(vNode: VNode | null) {
|
||||
processing = vNode;
|
||||
}
|
||||
|
@ -65,7 +64,7 @@ function collectDirtyNodes(vNode: VNode, parent: VNode): void {
|
|||
}
|
||||
}
|
||||
|
||||
// ============================== 向上递归 ==============================
|
||||
// ============================== 向上冒泡 ==============================
|
||||
|
||||
// 尝试完成当前工作单元,然后移动到下一个兄弟工作单元。如果没有更多的同级,请返回父vNode。
|
||||
function bubbleVNode(vNode: VNode): void {
|
||||
|
@ -202,18 +201,18 @@ function buildVNodeTree(treeRoot: VNode) {
|
|||
changeMode(InRender, true);
|
||||
|
||||
// 计算出开始节点
|
||||
const startUpdateVNode = calcStartUpdateVNode(treeRoot);
|
||||
const startVNode = calcStartUpdateVNode(treeRoot);
|
||||
// 缓存起来
|
||||
setStartVNode(startUpdateVNode);
|
||||
setStartVNode(startVNode);
|
||||
|
||||
// 清空toUpdateNodes
|
||||
treeRoot.toUpdateNodes.clear();
|
||||
|
||||
if (startUpdateVNode.tag !== TreeRoot) { // 不是根节点
|
||||
if (startVNode.tag !== TreeRoot) { // 不是根节点
|
||||
// 设置namespace,用于createElement
|
||||
const parentObj = findDomParent(startUpdateVNode);
|
||||
const parentObj = findDomParent(startVNode);
|
||||
|
||||
// 当在componentWillUnmount中调用setState,parent可能是null,因为startUpdateVNode会被clear
|
||||
// 当在componentWillUnmount中调用setState,parent可能是null,因为startVNode会被clear
|
||||
if (parentObj !== null) {
|
||||
const domParent = parentObj.parent;
|
||||
resetNamespaceCtx(domParent);
|
||||
|
@ -221,20 +220,20 @@ function buildVNodeTree(treeRoot: VNode) {
|
|||
}
|
||||
|
||||
// 恢复父节点的context
|
||||
recoverParentsContextCtx(startUpdateVNode);
|
||||
recoverParentsContextCtx(startVNode);
|
||||
}
|
||||
|
||||
// 重置环境变量,为重新进行深度遍历做准备
|
||||
resetProcessingVariables(startUpdateVNode);
|
||||
resetProcessingVariables(startVNode);
|
||||
|
||||
do {
|
||||
while (processing !== null) {
|
||||
try {
|
||||
while (processing !== null) {
|
||||
// 捕获创建 vNodes
|
||||
const next = captureVNode(processing);
|
||||
|
||||
if (next === null) {
|
||||
// 如果没有产生新的,那么就完成当前节点,向上遍历
|
||||
// 如果没有子节点,那么就完成当前节点,开始冒泡
|
||||
bubbleVNode(processing);
|
||||
} else {
|
||||
processing = next;
|
||||
|
@ -242,14 +241,10 @@ function buildVNodeTree(treeRoot: VNode) {
|
|||
}
|
||||
|
||||
setProcessingClassVNode(null);
|
||||
|
||||
break;
|
||||
} catch (thrownValue) {
|
||||
handleError(treeRoot, thrownValue);
|
||||
}
|
||||
} while (true);
|
||||
|
||||
processing = null;
|
||||
}
|
||||
|
||||
setExecuteMode(preMode);
|
||||
}
|
||||
|
@ -314,12 +309,6 @@ export function launchUpdateFromVNode(vNode: VNode) {
|
|||
}
|
||||
}
|
||||
|
||||
export function setBuildResultError() {
|
||||
if (getBuildResult() !== BuildCompleted) {
|
||||
setBuildResult(BuildErrored);
|
||||
}
|
||||
}
|
||||
|
||||
// ============================== HorizonDOM使用 ==============================
|
||||
export function runDiscreteUpdates() {
|
||||
if (checkMode(ByAsync) || checkMode(InRender)) {
|
||||
|
|
|
@ -14,8 +14,6 @@ import {runAsync} from '../taskExecutor/TaskExecutor';
|
|||
import {
|
||||
copyExecuteMode, InRender, setExecuteMode,changeMode
|
||||
} from '../ExecuteMode';
|
||||
import {handleSubmitError} from '../ErrorHandler';
|
||||
import {clearDirtyNodes} from './Submit';
|
||||
import {EffectConstant} from '../hooks/EffectConstant';
|
||||
|
||||
let hookEffects: Array<HookEffect | VNode> = [];
|
||||
|
@ -81,7 +79,7 @@ export function runAsyncEffects() {
|
|||
try {
|
||||
destroy();
|
||||
} catch (error) {
|
||||
handleSubmitError(vNode, error);
|
||||
// 不处理副作用阶段抛出的异常
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -95,13 +93,10 @@ export function runAsyncEffects() {
|
|||
|
||||
effect.removeEffect = create();
|
||||
} catch (error) {
|
||||
handleSubmitError(vNode, error);
|
||||
// 不处理副作用阶段抛出的异常
|
||||
}
|
||||
});
|
||||
|
||||
// 清理dirtyNodes
|
||||
clearDirtyNodes(root.dirtyNodes);
|
||||
|
||||
setExecuteMode(preMode);
|
||||
|
||||
callRenderQueueImmediate();
|
||||
|
|
|
@ -70,8 +70,6 @@ export function submitToRender(treeRoot) {
|
|||
|
||||
// 记录root,说明这个root有副作用要执行
|
||||
setHookEffectRoot(treeRoot);
|
||||
} else {
|
||||
clearDirtyNodes(dirtyNodes);
|
||||
}
|
||||
|
||||
// 统计root同步重渲染的次数,如果太多可能是无线循环
|
||||
|
@ -197,13 +195,3 @@ export function checkLoopingUpdateLimit() {
|
|||
);
|
||||
}
|
||||
}
|
||||
|
||||
// 清理dirtyNodes
|
||||
export function clearDirtyNodes(dirtyNodes) {
|
||||
dirtyNodes.forEach(node => {
|
||||
if (node.flags.Deletion) {
|
||||
node.realNode = null;
|
||||
node.next = null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -41,8 +41,9 @@ export class FlagUtils {
|
|||
static hasAnyFlag(node: VNode) { // 有标志位
|
||||
const flags = node.flags;
|
||||
const arrLength = FlagArr.length;
|
||||
let key;
|
||||
for (let i = 0; i < arrLength; i++) {
|
||||
const key = FlagArr[i];
|
||||
key = FlagArr[i];
|
||||
if (flags[key]) {
|
||||
return true;
|
||||
}
|
||||
|
@ -92,7 +93,6 @@ export class FlagUtils {
|
|||
static markForceUpdate(node: VNode) {
|
||||
node.flags.ForceUpdate = true;
|
||||
}
|
||||
|
||||
static markClear(node: VNode) {
|
||||
node.flags.Clear = true;
|
||||
}
|
||||
|
|
|
@ -56,6 +56,7 @@ export function updateParentsChildShouldUpdate(vNode: VNode) {
|
|||
let isShouldUpdate = vNode.shouldUpdate || vNode.childShouldUpdate;
|
||||
|
||||
if (isShouldUpdate) { // 开始节点是shouldUpdate或childShouldUpdate
|
||||
// 更新从当前节点到根节点的childShouldUpdate为true
|
||||
setParentsChildShouldUpdate(node);
|
||||
} else {
|
||||
while (node !== null) {
|
||||
|
|
|
@ -81,7 +81,6 @@ export function clearVNode(vNode: VNode) {
|
|||
vNode.next = null;
|
||||
vNode.depContexts = [];
|
||||
vNode.dirtyNodes = [];
|
||||
vNode.oldProps = null;
|
||||
vNode.state = null;
|
||||
vNode.hooks = [];
|
||||
vNode.suspenseChildStatus = '';
|
||||
|
@ -91,7 +90,9 @@ export function clearVNode(vNode: VNode) {
|
|||
vNode.changeList = null;
|
||||
vNode.effectList = [];
|
||||
vNode.updates = null;
|
||||
vNode.realNode = null;
|
||||
|
||||
vNode.oldProps = null;
|
||||
vNode.oldHooks = [];
|
||||
vNode.oldState = null;
|
||||
vNode.oldRef = null;
|
||||
|
|
Loading…
Reference in New Issue