From bd7c640db67ef5a1fcbc09764891a2ca33cd52bf Mon Sep 17 00:00:00 2001 From: * <8> Date: Thu, 17 Feb 2022 20:29:51 +0800 Subject: [PATCH] Match-id-9ccbe249bd64aa265df986ea76dfa1446be57717 --- libs/horizon/src/renderer/vnode/VNode.ts | 1 + .../src/renderer/vnode/VNodeCreator.ts | 41 ++++++++----------- 2 files changed, 19 insertions(+), 23 deletions(-) diff --git a/libs/horizon/src/renderer/vnode/VNode.ts b/libs/horizon/src/renderer/vnode/VNode.ts index 371e488d..a48c4ab9 100644 --- a/libs/horizon/src/renderer/vnode/VNode.ts +++ b/libs/horizon/src/renderer/vnode/VNode.ts @@ -137,6 +137,7 @@ export class VNode { this.realNode = null; this.stateCallbacks = null; this.isLazyComponent = true; + this.lazyType = null; break; case Fragment: break; diff --git a/libs/horizon/src/renderer/vnode/VNodeCreator.ts b/libs/horizon/src/renderer/vnode/VNodeCreator.ts index c8832fa8..b37fa3c7 100644 --- a/libs/horizon/src/renderer/vnode/VNodeCreator.ts +++ b/libs/horizon/src/renderer/vnode/VNodeCreator.ts @@ -84,28 +84,6 @@ export function updateVNode(vNode: VNode, vNodeProps?: any): VNode { return vNode; } -function getVNodeTag(type: any) { - let vNodeTag = ClsOrFunComponent; - let isLazy = false; - const componentType = typeof type; - - if (componentType === 'function') { - if (isClassComponent(type)) { - vNodeTag = ClassComponent; - } - } else if (componentType === 'string') { - vNodeTag = DomComponent; - } else if (type === TYPE_SUSPENSE) { - vNodeTag = SuspenseComponent; - } else if (componentType === 'object' && type !== null && typeMap[type.vtype]) { - vNodeTag = typeMap[type.vtype]; - isLazy = type.vtype === TYPE_LAZY; - } else { - throw Error(`Component type is invalid, got: ${type == null ? type : componentType}`); - } - return { vNodeTag, isLazy }; -} - export function createFragmentVNode(fragmentKey, fragmentProps) { const vNode = newVirtualNode(Fragment, fragmentKey, fragmentProps); vNode.shouldUpdate = true; @@ -127,7 +105,24 @@ export function createPortalVNode(portal) { } export function createUndeterminedVNode(type, key, props) { - const { vNodeTag, isLazy } = getVNodeTag(type); + let vNodeTag = ClsOrFunComponent; + let isLazy = false; + const componentType = typeof type; + + if (componentType === 'function') { + if (isClassComponent(type)) { + vNodeTag = ClassComponent; + } + } else if (componentType === 'string') { + vNodeTag = DomComponent; + } else if (type === TYPE_SUSPENSE) { + vNodeTag = SuspenseComponent; + } else if (componentType === 'object' && type !== null && typeMap[type.vtype]) { + vNodeTag = typeMap[type.vtype]; + isLazy = type.vtype === TYPE_LAZY; + } else { + throw Error(`Component type is invalid, got: ${type == null ? type : componentType}`); + } const vNode = newVirtualNode(vNodeTag, key, props); vNode.type = type;