Skip to content

Commit

Permalink
feat: mark the loaded remote description descriptions to reduce loading
Browse files Browse the repository at this point in the history
  • Loading branch information
liujuping authored and JackLian committed Aug 17, 2023
1 parent 67a0c9e commit a389ec1
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions packages/editor-core/src/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ const keyBlacklist = [
'innerPlugins',
];

const AssetsCache: {
[key: string]: IPublicTypeRemoteComponentDescription;
} = {};

export declare interface Editor extends StrictEventEmitter<EventEmitter, GlobalEvent.EventConfig> {
addListener(event: string | symbol, listener: (...args: any[]) => void): this;
once(event: string | symbol, listener: (...args: any[]) => void): this;
Expand Down Expand Up @@ -143,9 +147,15 @@ export class Editor extends EventEmitter implements IEditor {
// 如果有远程组件描述协议,则自动加载并补充到资产包中,同时出发 designer.incrementalAssetsReady 通知组件面板更新数据
if (remoteComponentDescriptions && remoteComponentDescriptions.length) {
await Promise.all(
remoteComponentDescriptions.map(async (component: any) => {
remoteComponentDescriptions.map(async (component: IPublicTypeRemoteComponentDescription) => {
const { exportName, url, npm } = component;
await (new AssetLoader()).load(url);
if (!url || !exportName) {
return;
}
if (!AssetsCache[exportName] || !npm?.version || AssetsCache[exportName].npm?.version !== npm?.version) {
await (new AssetLoader()).load(url);
}
AssetsCache[exportName] = component;
function setAssetsComponent(component: any, extraNpmInfo: any = {}) {
const components = component.components;
assets.componentList = assets.componentList?.concat(component.componentList || []);
Expand Down Expand Up @@ -181,14 +191,14 @@ export class Editor extends EventEmitter implements IEditor {
});
});
}
if (window[exportName]) {
if (Array.isArray(window[exportName])) {
setArrayAssets(window[exportName] as any);
if ((window as any)[exportName]) {
if (Array.isArray((window as any)[exportName])) {
setArrayAssets((window as any)[exportName] as any);
} else {
setAssetsComponent(window[exportName] as any);
setAssetsComponent((window as any)[exportName] as any);
}
}
return window[exportName];
return (window as any)[exportName];
}),
);
}
Expand Down

0 comments on commit a389ec1

Please sign in to comment.