From 1825da1949f6d999f09dd723a38af0438de3fba3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8A=9B=E7=9A=93?= Date: Sun, 25 Apr 2021 14:02:49 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E5=A2=9E=E5=8A=A0=20settings=20?= =?UTF-8?q?=E9=94=80=E6=AF=81=E7=9A=84=E9=B2=81=E6=A3=92=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../editor-skeleton/src/components/settings/main.ts | 7 ++++++- packages/utils/src/misc.ts | 10 ++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/packages/editor-skeleton/src/components/settings/main.ts b/packages/editor-skeleton/src/components/settings/main.ts index 5c6e3ffa3..60a20c2bf 100644 --- a/packages/editor-skeleton/src/components/settings/main.ts +++ b/packages/editor-skeleton/src/components/settings/main.ts @@ -1,6 +1,7 @@ import { EventEmitter } from 'events'; import { Node, Designer, Selection, SettingTopEntry } from '@ali/lowcode-designer'; import { Editor, obx, computed } from '@ali/lowcode-editor-core'; +import { executePendingFn } from '@ali/lowcode-utils'; function generateSessionId(nodes: Node[]) { return nodes @@ -69,7 +70,11 @@ export class SettingsMain { this.designer = nodes[0].document.designer; } - this._settings?.purge(); + let lastSettings = this._settings; + // obx 的一些响应式计算会延迟到下一个时钟周期,导致 prop.parent 获取不到,这里也做一个延迟 + executePendingFn(() => { + lastSettings?.purge(); + }, 2000); this._settings = this.designer.createSettingEntry(nodes); } diff --git a/packages/utils/src/misc.ts b/packages/utils/src/misc.ts index 236aa071f..6682e00e7 100644 --- a/packages/utils/src/misc.ts +++ b/packages/utils/src/misc.ts @@ -61,3 +61,13 @@ export function waitForThing(obj: any, path: string): Promise { export function isFromVC(meta: ComponentMeta) { return !!meta?.getMetadata()?.experimental; } + +export function arrShallowEquals(arr1: any[], arr2: any[]): boolean { + if (!Array.isArray(arr1) || !Array.isArray(arr2)) return false; + if (arr1.length !== arr2.length) return false; + return arr1.every(item => arr2.includes(item)); +} + +export function executePendingFn(fn: () => void, timeout: number = 2000) { + return setTimeout(fn, timeout); +} \ No newline at end of file