mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2025-12-12 19:52:51 +00:00
feat: 资产包支持一个package从另一个package异步导出 (#1150)
This commit is contained in:
parent
535b75c04f
commit
8a83fc9b5c
@ -352,9 +352,11 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
|
|||||||
const _library = library || (this.get('library') as LibraryItem[]);
|
const _library = library || (this.get('library') as LibraryItem[]);
|
||||||
const libraryAsset: AssetList = [];
|
const libraryAsset: AssetList = [];
|
||||||
const libraryExportList: string[] = [];
|
const libraryExportList: string[] = [];
|
||||||
|
const functionCallLibraryExportList: string[] = [];
|
||||||
|
|
||||||
if (_library && _library.length) {
|
if (_library && _library.length) {
|
||||||
_library.forEach((item) => {
|
_library.forEach((item) => {
|
||||||
|
const { exportMode, exportSourceLibrary } = item;
|
||||||
this.libraryMap[item.package] = item.library;
|
this.libraryMap[item.package] = item.library;
|
||||||
if (item.async) {
|
if (item.async) {
|
||||||
this.asyncLibraryMap[item.package] = item;
|
this.asyncLibraryMap[item.package] = item;
|
||||||
@ -364,6 +366,11 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
|
|||||||
`Object.defineProperty(window,'${item.exportName}',{get:()=>window.${item.library}});`,
|
`Object.defineProperty(window,'${item.exportName}',{get:()=>window.${item.library}});`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
if (exportMode === 'functionCall' && exportSourceLibrary) {
|
||||||
|
functionCallLibraryExportList.push(
|
||||||
|
`window["${item.library}"] = window["${exportSourceLibrary}"]("${item.library}", "${item.package}");`,
|
||||||
|
);
|
||||||
|
}
|
||||||
if (item.editUrls) {
|
if (item.editUrls) {
|
||||||
libraryAsset.push(item.editUrls);
|
libraryAsset.push(item.editUrls);
|
||||||
} else if (item.urls) {
|
} else if (item.urls) {
|
||||||
@ -372,7 +379,7 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
libraryAsset.unshift(assetItem(AssetType.JSText, libraryExportList.join('')));
|
libraryAsset.unshift(assetItem(AssetType.JSText, libraryExportList.join('')));
|
||||||
|
libraryAsset.push(assetItem(AssetType.JSText, functionCallLibraryExportList.join('')));
|
||||||
return libraryAsset;
|
return libraryAsset;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -428,6 +435,9 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
|
|||||||
if (Object.keys(this.asyncLibraryMap).length > 0) {
|
if (Object.keys(this.asyncLibraryMap).length > 0) {
|
||||||
// 加载异步Library
|
// 加载异步Library
|
||||||
await renderer.loadAsyncLibrary(this.asyncLibraryMap);
|
await renderer.loadAsyncLibrary(this.asyncLibraryMap);
|
||||||
|
Object.keys(this.asyncLibraryMap).forEach(key => {
|
||||||
|
delete this.asyncLibraryMap[key];
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// step 5 ready & render
|
// step 5 ready & render
|
||||||
@ -447,7 +457,14 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
|
|||||||
|
|
||||||
async setupComponents(library) {
|
async setupComponents(library) {
|
||||||
const libraryAsset: AssetList = this.buildLibrary(library);
|
const libraryAsset: AssetList = this.buildLibrary(library);
|
||||||
await this.renderer.load(libraryAsset);
|
await this.renderer?.load(libraryAsset);
|
||||||
|
if (Object.keys(this.asyncLibraryMap).length > 0) {
|
||||||
|
// 加载异步Library
|
||||||
|
await this.renderer?.loadAsyncLibrary(this.asyncLibraryMap);
|
||||||
|
Object.keys(this.asyncLibraryMap).forEach(key => {
|
||||||
|
delete this.asyncLibraryMap[key];
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setupEvents() {
|
setupEvents() {
|
||||||
|
|||||||
@ -11,6 +11,7 @@ export interface BuiltinSimulatorRenderer {
|
|||||||
setNativeSelection(enableFlag: boolean): void;
|
setNativeSelection(enableFlag: boolean): void;
|
||||||
setDraggingState(state: boolean): void;
|
setDraggingState(state: boolean): void;
|
||||||
setCopyState(state: boolean): void;
|
setCopyState(state: boolean): void;
|
||||||
|
loadAsyncLibrary(asyncMap: { [index: string]: any }): void;
|
||||||
clearState(): void;
|
clearState(): void;
|
||||||
run(): void;
|
run(): void;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -130,6 +130,14 @@ export interface Package {
|
|||||||
* @todo 需推进提案 @度城
|
* @todo 需推进提案 @度城
|
||||||
*/
|
*/
|
||||||
async?: boolean;
|
async?: boolean;
|
||||||
|
/**
|
||||||
|
* 标识当前 package 从其他 package 的导出方式
|
||||||
|
*/
|
||||||
|
exportMode?: 'functionCall';
|
||||||
|
/**
|
||||||
|
* 标识当前 package 是从 window 上的哪个属性导出来的
|
||||||
|
*/
|
||||||
|
exportSourceLibrary?: any;
|
||||||
/**
|
/**
|
||||||
* 组件描述导出名字,可以通过 window[exportName] 获取到组件描述的 Object 内容;
|
* 组件描述导出名字,可以通过 window[exportName] 获取到组件描述的 Object 内容;
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -268,17 +268,24 @@ export class AssetLoader {
|
|||||||
async loadAsyncLibrary(asyncLibraryMap: Record<string, any>) {
|
async loadAsyncLibrary(asyncLibraryMap: Record<string, any>) {
|
||||||
const promiseList: any[] = [];
|
const promiseList: any[] = [];
|
||||||
const libraryKeyList: any[] = [];
|
const libraryKeyList: any[] = [];
|
||||||
|
const pkgs: any[] = [];
|
||||||
for (const key in asyncLibraryMap) {
|
for (const key in asyncLibraryMap) {
|
||||||
// 需要异步加载
|
// 需要异步加载
|
||||||
if (asyncLibraryMap[key].async) {
|
if (asyncLibraryMap[key].async) {
|
||||||
promiseList.push(window[asyncLibraryMap[key].library]);
|
promiseList.push(window[asyncLibraryMap[key].library]);
|
||||||
libraryKeyList.push(asyncLibraryMap[key].library);
|
libraryKeyList.push(asyncLibraryMap[key].library);
|
||||||
|
pkgs.push(asyncLibraryMap[key]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
await Promise.all(promiseList).then((mods) => {
|
await Promise.all(promiseList).then((mods) => {
|
||||||
if (mods.length > 0) {
|
if (mods.length > 0) {
|
||||||
mods.map((item, index) => {
|
mods.map((item, index) => {
|
||||||
window[libraryKeyList[index]] = item;
|
const { exportMode, exportSourceLibrary, library } = pkgs[index];
|
||||||
|
window[libraryKeyList[index]] =
|
||||||
|
exportMode === 'functionCall' &&
|
||||||
|
(exportSourceLibrary == null || exportSourceLibrary === library)
|
||||||
|
? item()
|
||||||
|
: item;
|
||||||
return item;
|
return item;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user