From d984192aebf4eda5701939bb44754b0ad1c74bb8 Mon Sep 17 00:00:00 2001 From: "lihao.ylh" Date: Thu, 23 Sep 2021 10:27:33 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=B5=8C=E5=A5=97=20p?= =?UTF-8?q?rop=20=E7=9A=84=E5=86=85=E9=83=A8=E7=BB=93=E6=9E=84=E4=B8=8D?= =?UTF-8?q?=E6=AD=A3=E5=B8=B8=E4=BB=A5=E5=8F=8A=E9=83=A8=E5=88=86=E9=87=8D?= =?UTF-8?q?=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../designer/src/document/node/props/prop.ts | 60 +++++++++---------- 1 file changed, 28 insertions(+), 32 deletions(-) diff --git a/packages/designer/src/document/node/props/prop.ts b/packages/designer/src/document/node/props/prop.ts index 4cba4671e..a6b90d3a5 100644 --- a/packages/designer/src/document/node/props/prop.ts +++ b/packages/designer/src/document/node/props/prop.ts @@ -373,35 +373,30 @@ export class Prop implements IPropParent { } @computed private get items(): Prop[] | null { - let _items: any = this._items; - if (!_items) { - if (this._type === 'list') { - const data = this._value; - const items = []; - for (const item of data) { - items.push(new Prop(this, item)); - } - _items = items; - this._maps = null; - } else if (this._type === 'map') { - const data = this._value; - const items = []; - const maps = new Map(); - const keys = Object.keys(data); - for (const key of keys) { - const prop = new Prop(this, data[key], key); - items.push(prop); - maps.set(key, prop); - } - _items = items; - this._maps = maps; - } else { - _items = null; - this._maps = null; + if (this._items) return this._items; + let items: Prop[] | null = []; + if (this._type === 'list') { + const data = this._value; + for (const item of data) { + items.push(new Prop(this, item)); } - this._items = _items; + this._maps = null; + } else if (this._type === 'map') { + const data = this._value; + const maps = new Map(); + const keys = Object.keys(data); + for (const key of keys) { + const prop = new Prop(this, data[key], key); + items.push(prop); + maps.set(key, prop); + } + this._maps = maps; + } else { + items = null; + this._maps = null; } - return _items; + this._items = items; + return this._items; } @computed private get maps(): Map | null { @@ -548,7 +543,7 @@ export class Prop implements IPropParent { } } const prop = isProp(value) ? value : new Prop(this, value, key); - const items = this.items!; + let items = this._items! || []; if (this.type === 'list') { if (!isValidArrayIndex(key)) { return null; @@ -558,20 +553,21 @@ export class Prop implements IPropParent { } else { items[key] = prop; } - } else if (this.maps) { + } else if (this.type === 'map') { const { maps } = this; - const orig = maps.get(key); + const orig = maps?.get(key); if (orig) { // replace const i = items.indexOf(orig); if (i > -1) { items.splice(i, 1, prop)[0].purge(); } - maps.set(key, prop); + maps?.set(key, prop); } else { // push items.push(prop); - maps.set(key, prop); + this._items = items; + maps?.set(key, prop); } } /* istanbul ignore next */ else { return null;