From f8100851c373020e30829b87dd914d31561e901f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8A=9B=E7=9A=93?= Date: Tue, 22 Jun 2021 10:58:09 +0800 Subject: [PATCH] =?UTF-8?q?refactor(perf):=20=E8=8A=82=E7=82=B9=E5=B1=9E?= =?UTF-8?q?=E6=80=A7=20settingEntry=20=E6=8C=89=E9=9C=80=E6=9E=84=E9=80=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/designer/src/document/node/node.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/designer/src/document/node/node.ts b/packages/designer/src/document/node/node.ts index b55ee359a..9dfde4baf 100644 --- a/packages/designer/src/document/node/node.ts +++ b/packages/designer/src/document/node/node.ts @@ -156,8 +156,6 @@ export class Node { return this.componentMeta.icon; } - readonly settingEntry: SettingTopEntry; - private isInited = false; constructor(readonly document: DocumentModel, nodeSchema: Schema, options: any = {}) { @@ -168,13 +166,11 @@ export class Node { this.props = new Props(this, { children: isDOMText(children) || isJSExpression(children) ? children : '', }); - this.settingEntry = this.document.designer.createSettingEntry([this]); } else { // 这里 props 被初始化两次,一次 new,一次 import,new 的实例需要给 propsReducer 的钩子去使用, // import 是为了使用钩子返回的值,并非完全幂等的操作,部分行为执行两次会有 bug, // 所以在 props 里会对 new / import 做一些区别化的解析 this.props = new Props(this, props, extras); - this.settingEntry = this.document.designer.createSettingEntry([this]); this._children = new NodeChildren(this as ParentalNode, this.initialChildren(children)); this._children.internalInitParent(); this.props.import( @@ -188,6 +184,14 @@ export class Node { this.emitter = new EventEmitter(); } + _settingEntry: SettingTopEntry; + + get settingEntry(): SettingTopEntry { + if (this._settingEntry) return this._settingEntry; + this._settingEntry = this.document.designer.createSettingEntry([this]); + return this._settingEntry; + } + private initProps(props: any): any { return this.document.designer.transformProps(props, this, TransformStage.Init); }