Match-id-e6fbf97ee32697280c273be5bc3a8b5f1605f1c9

This commit is contained in:
* 2022-02-17 11:23:58 +08:00 committed by *
parent c702a1b3cb
commit 0a952e800a
3 changed files with 14 additions and 9 deletions

View File

@ -72,7 +72,11 @@ function calcState(
function collectCallbacks(vNode: VNode, update: Update) {
if (update.callback !== null) {
FlagUtils.markCallback(vNode);
vNode.stateCallbacks.push(update.callback);
if (vNode.stateCallbacks === null) {
vNode.stateCallbacks = [update.callback];
} else {
vNode.stateCallbacks.push(update.callback);
}
}
}

View File

@ -72,13 +72,14 @@ function callBeforeSubmitLifeCycles(
// 调用vNode.stateCallbacks
function callStateCallback(vNode: VNode, obj: any): void {
const stateCallbacks = vNode.stateCallbacks;
vNode.stateCallbacks = [];
stateCallbacks.forEach(callback => {
if (typeof callback === 'function') {
callback.call(obj);
}
});
vNode.stateCallbacks = null;
if (stateCallbacks !== null) {
stateCallbacks.forEach(callback => {
if (typeof callback === 'function') {
callback.call(obj);
}
});
}
}
// 调用界面变化后的生命周期

View File

@ -27,7 +27,7 @@ export class VNode {
changeList: any = null; // DOM的变更列表
effectList: any[] | null = null; // useEffect 的更新数组
updates: any[] | null = null; // TreeRoot和ClassComponent使用的更新数组
stateCallbacks: any[] | null = []; // 存放存在setState的第二个参数和HorizonDOM.render的第三个参数所在的node数组
stateCallbacks: any[] | null = null; // 存放存在setState的第二个参数和HorizonDOM.render的第三个参数所在的node数组
isForceUpdate: boolean = false; // 是否使用强制更新
state: any = null; // ClassComponent和TreeRoot的状态