From 1a107bc67a64c350a4844615cc00ea7233e20a3a Mon Sep 17 00:00:00 2001 From: "lihao.ylh" Date: Fri, 25 Jun 2021 17:23:02 +0800 Subject: [PATCH] =?UTF-8?q?refactor(perf):=20=E8=AE=A9=20props=20=E5=8F=AA?= =?UTF-8?q?=E6=9E=84=E9=80=A0=E4=B8=80=E6=AC=A1,=20=E9=99=8D=E4=BD=8E?= =?UTF-8?q?=E5=A4=8D=E6=9D=82=E5=BA=A6=E4=B8=94=E6=8F=90=E9=AB=98=E6=80=A7?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/designer/src/document/node/node.ts | 2 +- packages/designer/src/document/node/props/prop.ts | 3 ++- packages/designer/src/document/node/props/props.ts | 11 ++++++++--- .../src/props-reducers/init-node-reducer.ts | 4 ++-- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/packages/designer/src/document/node/node.ts b/packages/designer/src/document/node/node.ts index 0bc849f1a..0e2fab65f 100644 --- a/packages/designer/src/document/node/node.ts +++ b/packages/designer/src/document/node/node.ts @@ -173,7 +173,7 @@ export class Node { this.props = new Props(this, props, extras); this._children = new NodeChildren(this as ParentalNode, this.initialChildren(children)); this._children.internalInitParent(); - this.props.import( + this.props.merge( this.upgradeProps(this.initProps(props || {})), this.upgradeProps(extras || {}), ); diff --git a/packages/designer/src/document/node/props/prop.ts b/packages/designer/src/document/node/props/prop.ts index f8237e8f0..e903f70ef 100644 --- a/packages/designer/src/document/node/props/prop.ts +++ b/packages/designer/src/document/node/props/prop.ts @@ -218,6 +218,7 @@ export class Prop implements IPropParent { * set value, val should be JSON Object */ setValue(val: CompositeValue) { + if (val === this._value) return; const editor = this.owner.document?.designer.editor; const oldValue = this._value; this._value = val; @@ -231,7 +232,7 @@ export class Prop implements IPropParent { } else if (Array.isArray(val)) { this._type = 'list'; } else if (isPlainObject(val)) { - if (isJSSlot(val) && this.options.skipSetSlot !== true) { + if (isJSSlot(val)) { this.setAsSlot(val); } else if (isJSExpression(val)) { this._type = 'expression'; diff --git a/packages/designer/src/document/node/props/props.ts b/packages/designer/src/document/node/props/props.ts index 1e900710f..eefe3ad01 100644 --- a/packages/designer/src/document/node/props/props.ts +++ b/packages/designer/src/document/node/props/props.ts @@ -64,9 +64,9 @@ export class Props implements IPropParent { }); if (Array.isArray(value)) { this.type = 'list'; - this.items = value.map(item => new Prop(this, item.value, item.name, item.spread, { skipSetSlot: true })); + this.items = value.map(item => new Prop(this, item.value, item.name, item.spread)); } else if (value != null) { - this.items = Object.keys(value).map(key => new Prop(this, value[key], key, false, { skipSetSlot: true })); + this.items = Object.keys(value).map(key => new Prop(this, value[key], key, false)); } if (extras) { Object.keys(extras).forEach(key => { @@ -96,10 +96,15 @@ export class Props implements IPropParent { originItems.forEach(item => item.purge()); } - merge(value: PropsMap) { + merge(value: PropsMap, extras?: PropsMap) { Object.keys(value).forEach(key => { this.query(key, true)!.setValue(value[key]); }); + if (extras) { + Object.keys(extras).forEach(key => { + this.query(getConvertedExtraKey(key), true)!.setValue(extras[key]); + }); + } } export(stage: TransformStage = TransformStage.Save): { props?: PropsMap | PropsList; extras?: object } { diff --git a/packages/vision-polyfill/src/props-reducers/init-node-reducer.ts b/packages/vision-polyfill/src/props-reducers/init-node-reducer.ts index 11f826ad9..e65cbf7c3 100644 --- a/packages/vision-polyfill/src/props-reducers/init-node-reducer.ts +++ b/packages/vision-polyfill/src/props-reducers/init-node-reducer.ts @@ -33,13 +33,13 @@ export function initNodeReducer(props, node) { // 2. 结构为 JSExpression 并且带有 events 字段 if ((item.name === 'fieldId' && value) || (isJSExpression(value) && value.events)) { if (newProps[item.name] && !node.props.has(item.name)) { - node.props.add(value, item.name, false, { skipSetSlot: true }); + node.props.add(value, item.name, false); } return; } newProps[item.name] = item.initial(node as any, newProps[item.name]); if (newProps[item.name] && !node.props.has(item.name)) { - node.props.add(value, item.name, false, { skipSetSlot: true }); + node.props.add(value, item.name, false); } } catch (e) { if (hasOwnProperty(props, item.name)) {