Skip to content

Commit a389ec1

Browse files
liujupingJackLian
authored andcommitted
feat: mark the loaded remote description descriptions to reduce loading
1 parent 67a0c9e commit a389ec1

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

packages/editor-core/src/editor.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ const keyBlacklist = [
3535
'innerPlugins',
3636
];
3737

38+
const AssetsCache: {
39+
[key: string]: IPublicTypeRemoteComponentDescription;
40+
} = {};
41+
3842
export declare interface Editor extends StrictEventEmitter<EventEmitter, GlobalEvent.EventConfig> {
3943
addListener(event: string | symbol, listener: (...args: any[]) => void): this;
4044
once(event: string | symbol, listener: (...args: any[]) => void): this;
@@ -143,9 +147,15 @@ export class Editor extends EventEmitter implements IEditor {
143147
// 如果有远程组件描述协议,则自动加载并补充到资产包中,同时出发 designer.incrementalAssetsReady 通知组件面板更新数据
144148
if (remoteComponentDescriptions && remoteComponentDescriptions.length) {
145149
await Promise.all(
146-
remoteComponentDescriptions.map(async (component: any) => {
150+
remoteComponentDescriptions.map(async (component: IPublicTypeRemoteComponentDescription) => {
147151
const { exportName, url, npm } = component;
148-
await (new AssetLoader()).load(url);
152+
if (!url || !exportName) {
153+
return;
154+
}
155+
if (!AssetsCache[exportName] || !npm?.version || AssetsCache[exportName].npm?.version !== npm?.version) {
156+
await (new AssetLoader()).load(url);
157+
}
158+
AssetsCache[exportName] = component;
149159
function setAssetsComponent(component: any, extraNpmInfo: any = {}) {
150160
const components = component.components;
151161
assets.componentList = assets.componentList?.concat(component.componentList || []);
@@ -181,14 +191,14 @@ export class Editor extends EventEmitter implements IEditor {
181191
});
182192
});
183193
}
184-
if (window[exportName]) {
185-
if (Array.isArray(window[exportName])) {
186-
setArrayAssets(window[exportName] as any);
194+
if ((window as any)[exportName]) {
195+
if (Array.isArray((window as any)[exportName])) {
196+
setArrayAssets((window as any)[exportName] as any);
187197
} else {
188-
setAssetsComponent(window[exportName] as any);
198+
setAssetsComponent((window as any)[exportName] as any);
189199
}
190200
}
191-
return window[exportName];
201+
return (window as any)[exportName];
192202
}),
193203
);
194204
}

0 commit comments

Comments
 (0)