Match-id-18f59c81b8302ce98bbefcf4608d9327523dd34b
This commit is contained in:
parent
c6f1debb03
commit
35d98b615f
|
@ -165,7 +165,7 @@ function getChildByIndex(vNode: VNode, idx: number) {
|
|||
|
||||
// 从多个更新节点中,计算出开始节点。即:找到最近的共同的父辈节点
|
||||
export function calcStartUpdateVNode(treeRoot: VNode) {
|
||||
const toUpdateNodes = [...treeRoot.toUpdateNodes];
|
||||
const toUpdateNodes = Array.from(treeRoot.toUpdateNodes);
|
||||
|
||||
if (toUpdateNodes.length === 0) {
|
||||
return treeRoot;
|
||||
|
|
|
@ -1,36 +0,0 @@
|
|||
import type {VNode} from '../Types';
|
||||
|
||||
import {FunctionComponent} from '../vnode/VNodeTags';
|
||||
import {resetDepContexts} from '../components/context/Context';
|
||||
import {getOldContext} from '../components/context/CompatibleContext';
|
||||
import {FlagUtils} from '../vnode/VNodeFlags';
|
||||
import {exeFunctionHook} from '../hooks/HookMain';
|
||||
import { createChildrenByDiff } from '../diff/nodeDiffComparator';
|
||||
|
||||
function captureIndeterminateComponent(
|
||||
processing: VNode,
|
||||
): VNode | null {
|
||||
const funcComp = processing.type;
|
||||
|
||||
if (!processing.isCreated) {
|
||||
processing.isCreated = true;
|
||||
FlagUtils.markAddition(processing);
|
||||
}
|
||||
|
||||
const props = processing.props;
|
||||
const context = getOldContext(processing, funcComp, false);
|
||||
|
||||
resetDepContexts(processing);
|
||||
|
||||
const newElements = exeFunctionHook(funcComp, props, context, processing);
|
||||
|
||||
processing.tag = FunctionComponent;
|
||||
processing.child = createChildrenByDiff(processing, processing.child, newElements, !processing.isCreated);
|
||||
return processing.child;
|
||||
}
|
||||
|
||||
export function captureRender(processing: VNode): VNode | null {
|
||||
return captureIndeterminateComponent(processing);
|
||||
}
|
||||
|
||||
export function bubbleRender() {}
|
|
@ -10,7 +10,6 @@ import * as DomPortalRender from './DomPortal';
|
|||
import * as TreeRootRender from './TreeRoot';
|
||||
import * as DomTextRender from './DomText';
|
||||
import * as IncompleteClassComponentRender from './IncompleteClassComponent';
|
||||
import * as ClsOrFunComponentRender from './ClsOrFunComponent';
|
||||
import * as LazyComponentRender from './LazyComponent';
|
||||
import * as MemoComponentRender from './MemoComponent';
|
||||
import * as SuspenseComponentRender from './SuspenseComponent';
|
||||
|
@ -27,7 +26,6 @@ import {
|
|||
TreeRoot,
|
||||
DomText,
|
||||
IncompleteClassComponent,
|
||||
ClsOrFunComponent,
|
||||
LazyComponent,
|
||||
MemoComponent,
|
||||
SuspenseComponent,
|
||||
|
@ -49,7 +47,6 @@ export default {
|
|||
[TreeRoot]: TreeRootRender,
|
||||
[DomText]: DomTextRender,
|
||||
[IncompleteClassComponent]: IncompleteClassComponentRender,
|
||||
[ClsOrFunComponent]: ClsOrFunComponentRender,
|
||||
[LazyComponent]: LazyComponentRender,
|
||||
[MemoComponent]: MemoComponentRender,
|
||||
[SuspenseComponent]: SuspenseComponentRender,
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
* 虚拟DOM结构体
|
||||
*/
|
||||
import { TreeRoot, FunctionComponent, ClassComponent, DomPortal, DomText, ContextConsumer, ForwardRef, SuspenseComponent, LazyComponent, ClsOrFunComponent, DomComponent, Fragment, ContextProvider, Profiler, MemoComponent, IncompleteClassComponent } from './VNodeTags';
|
||||
import { TreeRoot, FunctionComponent, ClassComponent, DomPortal, DomText, ContextConsumer, ForwardRef, SuspenseComponent, LazyComponent, DomComponent, Fragment, ContextProvider, Profiler, MemoComponent, IncompleteClassComponent } from './VNodeTags';
|
||||
import type { VNodeTag } from './VNodeTags';
|
||||
import type { RefType, ContextType } from '../Types';
|
||||
import type { Hook } from '../hooks/HookType';
|
||||
|
@ -18,8 +18,8 @@ export class VNode {
|
|||
parent: VNode | null = null; // 父节点
|
||||
child: VNode | null = null; // 子节点
|
||||
next: VNode | null = null; // 兄弟节点
|
||||
cIndex: number = 0; // 节点在children数组中的位置
|
||||
eIndex: number = 0; // HorizonElement在jsx中的位置,例如:jsx中的null不会生成vNode,所以eIndex和cIndex不一致
|
||||
cIndex = 0; // 节点在children数组中的位置
|
||||
eIndex = 0; // HorizonElement在jsx中的位置,例如:jsx中的null不会生成vNode,所以eIndex和cIndex不一致
|
||||
|
||||
ref: RefType | ((handle: any) => void) | null = null; // 包裹一个函数,submit阶段使用,比如将外部useRef生成的对象赋值到ref上
|
||||
oldProps: any = null;
|
||||
|
@ -33,12 +33,12 @@ export class VNode {
|
|||
|
||||
state: any; // ClassComponent和TreeRoot的状态
|
||||
hooks: Array<Hook<any, any>> | null; // 保存hook
|
||||
suspenseChildStatus: string = ''; // Suspense的Children是否显示
|
||||
suspenseChildStatus = ''; // Suspense的Children是否显示
|
||||
depContexts: Array<ContextType<any>> | null; // FunctionComponent和ClassComponent对context的依赖列表
|
||||
isDepContextChange: boolean; // context是否变更
|
||||
dirtyNodes: Array<VNode> | null = null; // 需要改动的节点数组
|
||||
shouldUpdate: boolean = false;
|
||||
childShouldUpdate: boolean = false;
|
||||
shouldUpdate = false;
|
||||
childShouldUpdate = false;
|
||||
task: any;
|
||||
|
||||
// 使用这个变量来记录修改前的值,用于恢复。
|
||||
|
@ -51,7 +51,7 @@ export class VNode {
|
|||
flags = InitFlag;
|
||||
clearChild: VNode | null;
|
||||
// one tree相关属性
|
||||
isCreated: boolean = true;
|
||||
isCreated = true;
|
||||
oldHooks: Array<Hook<any, any>> | null; // 保存上一次执行的hook
|
||||
oldState: any;
|
||||
oldRef: RefType | ((handle: any) => void) | null = null;
|
||||
|
@ -61,7 +61,7 @@ export class VNode {
|
|||
suspenseDidCapture: boolean; // suspense是否捕获了异常
|
||||
promiseResolve: boolean; // suspense的promise是否resolve
|
||||
|
||||
path: string = ''; // 保存从根到本节点的路径
|
||||
path = ''; // 保存从根到本节点的路径
|
||||
toUpdateNodes: Set<VNode> | null; // 保存要更新的节点
|
||||
|
||||
belongClassVNode: VNode | null = null; // 记录JSXElement所属class vNode,处理ref的时候使用
|
||||
|
@ -84,6 +84,7 @@ export class VNode {
|
|||
this.contexts = null;
|
||||
break;
|
||||
case FunctionComponent:
|
||||
this.realNode = null;
|
||||
this.effectList = null;
|
||||
this.hooks = null;
|
||||
this.depContexts = null;
|
||||
|
@ -101,10 +102,6 @@ export class VNode {
|
|||
this.oldState = null;
|
||||
this.contexts = null;
|
||||
break;
|
||||
case ClsOrFunComponent:
|
||||
this.realNode = null;
|
||||
this.contexts = null;
|
||||
break;
|
||||
case DomPortal:
|
||||
this.realNode = null;
|
||||
this.contexts = null;
|
||||
|
|
|
@ -11,7 +11,6 @@ import {
|
|||
DomPortal,
|
||||
TreeRoot,
|
||||
DomText,
|
||||
ClsOrFunComponent,
|
||||
LazyComponent,
|
||||
MemoComponent,
|
||||
SuspenseComponent,
|
||||
|
@ -52,13 +51,12 @@ function isClassComponent(comp: Function) {
|
|||
|
||||
// 解析懒组件的tag
|
||||
export function getLazyVNodeTag(lazyComp: any): string {
|
||||
let vNodeTag = ClsOrFunComponent;
|
||||
if (typeof lazyComp === 'function') {
|
||||
vNodeTag = isClassComponent(lazyComp) ? ClassComponent : FunctionComponent;
|
||||
return isClassComponent(lazyComp) ? ClassComponent : FunctionComponent;
|
||||
} else if (lazyComp !== undefined && lazyComp !== null && typeLazyMap[lazyComp.vtype]) {
|
||||
vNodeTag = typeLazyMap[lazyComp.vtype];
|
||||
return typeLazyMap[lazyComp.vtype];
|
||||
}
|
||||
return vNodeTag;
|
||||
throw Error("Horizon can't resolve the content of lazy ")
|
||||
}
|
||||
|
||||
// 创建processing
|
||||
|
@ -105,7 +103,7 @@ export function createPortalVNode(portal) {
|
|||
}
|
||||
|
||||
export function createUndeterminedVNode(type, key, props) {
|
||||
let vNodeTag = ClsOrFunComponent;
|
||||
let vNodeTag = FunctionComponent;
|
||||
let isLazy = false;
|
||||
const componentType = typeof type;
|
||||
|
||||
|
|
|
@ -6,7 +6,6 @@ export type VNodeTag = string;
|
|||
export const TreeRoot = 'TreeRoot'; // tree的根节点,用于存放一些tree级的变量
|
||||
export const FunctionComponent = 'FunctionComponent';
|
||||
export const ClassComponent = 'ClassComponent';
|
||||
export const ClsOrFunComponent = 'ClsOrFunComponent';
|
||||
export const DomPortal = 'DomPortal';
|
||||
export const DomComponent = 'DomComponent';
|
||||
export const DomText = 'DomText';
|
||||
|
|
Loading…
Reference in New Issue