Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: mark the loaded remote description descriptions to reduce loading #2378

Merged
merged 1 commit into from
Aug 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading