diff --git a/libs/horizon/src/renderer/UpdateHandler.ts b/libs/horizon/src/renderer/UpdateHandler.ts index a2b55485..e50d1e21 100644 --- a/libs/horizon/src/renderer/UpdateHandler.ts +++ b/libs/horizon/src/renderer/UpdateHandler.ts @@ -18,11 +18,6 @@ export enum UpdateState { Error = 'Error', } -// 初始化更新数组 -export function createUpdateArray(vNode: VNode): void { - vNode.updates = []; // 新产生的update会加入这个数组 -} - // 创建update对象 export function newUpdate(): Update { return { @@ -35,8 +30,11 @@ export function newUpdate(): Update { // 将update对象加入updates export function pushUpdate(vNode: VNode, update: Update) { const updates = vNode.updates; - - updates?.push(update); + if (updates !== null) { + updates.push(update); + } else { + vNode.updates = [update]; + } } // 根据update获取新的state @@ -98,12 +96,14 @@ export function processUpdates(vNode: VNode, inst: any, props: any): void { const updates: Updates = vNode.updates; vNode.isForceUpdate = false; - const toProcessUpdates = [...updates]; - updates.length = 0; - - if (toProcessUpdates.length) { - calcUpdates(vNode, props, inst, toProcessUpdates); + if (updates !== null) { + const toProcessUpdates = [...updates]; + updates.length = 0; + if (toProcessUpdates.length) { + calcUpdates(vNode, props, inst, toProcessUpdates); + } } + } export function pushForceUpdate(vNode: VNode) { diff --git a/libs/horizon/src/renderer/render/ClassComponent.ts b/libs/horizon/src/renderer/render/ClassComponent.ts index 261fea3f..36b15707 100644 --- a/libs/horizon/src/renderer/render/ClassComponent.ts +++ b/libs/horizon/src/renderer/render/ClassComponent.ts @@ -23,7 +23,6 @@ import { import { FlagUtils, DidCapture } from '../vnode/VNodeFlags'; import { markRef } from './BaseComponent'; import { - createUpdateArray, processUpdates, } from '../UpdateHandler'; import { getContextChangeCtx, setContextChangeCtx } from '../ContextSaver'; @@ -55,7 +54,6 @@ function mountInstance(clazz, processing: VNode, nextProps: object) { inst.context = getCurrentContext(clazz, processing); inst.refs = {}; - createUpdateArray(processing); processUpdates(processing, inst, nextProps); inst.state = processing.state; diff --git a/libs/horizon/src/renderer/render/DomComponent.ts b/libs/horizon/src/renderer/render/DomComponent.ts index ace8f10f..8baf71e4 100644 --- a/libs/horizon/src/renderer/render/DomComponent.ts +++ b/libs/horizon/src/renderer/render/DomComponent.ts @@ -105,7 +105,7 @@ export function bubbleRender(processing: VNode) { } } -function captureDomComponent(processing: VNode): VNode | null { +export function captureRender(processing: VNode): VNode | null { setNamespaceCtx(processing); const type = processing.type; @@ -127,7 +127,3 @@ function captureDomComponent(processing: VNode): VNode | null { processing.child = createChildrenByDiff(processing, processing.child, nextChildren, !processing.isCreated); return processing.child; } - -export function captureRender(processing: VNode): VNode | null { - return captureDomComponent(processing); -} diff --git a/libs/horizon/src/renderer/vnode/VNode.ts b/libs/horizon/src/renderer/vnode/VNode.ts index a48c4ab9..129e54a8 100644 --- a/libs/horizon/src/renderer/vnode/VNode.ts +++ b/libs/horizon/src/renderer/vnode/VNode.ts @@ -138,6 +138,7 @@ export class VNode { this.stateCallbacks = null; this.isLazyComponent = true; this.lazyType = null; + this.updates = null; break; case Fragment: break; diff --git a/libs/horizon/src/renderer/vnode/VNodeCreator.ts b/libs/horizon/src/renderer/vnode/VNodeCreator.ts index 35b1b354..5305b13a 100644 --- a/libs/horizon/src/renderer/vnode/VNodeCreator.ts +++ b/libs/horizon/src/renderer/vnode/VNodeCreator.ts @@ -16,7 +16,6 @@ import { MemoComponent, SuspenseComponent, } from './VNodeTags'; -import { createUpdateArray } from '../UpdateHandler'; import { TYPE_CONTEXT, TYPE_FORWARD_REF, TYPE_FRAGMENT, @@ -137,7 +136,7 @@ export function createUndeterminedVNode(type, key, props) { export function createTreeRootVNode(container) { const vNode = newVirtualNode(TreeRoot, null, null, container); vNode.path += 0; - createUpdateArray(vNode); + vNode.updates = []; return vNode; } @@ -150,7 +149,7 @@ export function createVNode(tag: VNodeTag | string, ...secondArg) { vNode = newVirtualNode(TreeRoot, null, null, secondArg[0]); vNode.path += 0; - createUpdateArray(vNode); + vNode.updates = []; break; }