refactor: 增加 settings 销毁的鲁棒性

This commit is contained in:
力皓 2021-04-25 14:02:49 +08:00
parent f84ec7e72e
commit 1825da1949
2 changed files with 16 additions and 1 deletions

View File

@ -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);
}

View File

@ -61,3 +61,13 @@ export function waitForThing(obj: any, path: string): Promise<any> {
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);
}