MCPcopy
hub / github.com/Tencent/CodeAnalysis / CombineLoader

Class CombineLoader

web/packages/framework/src/loader/index.ts:14–52  ·  view source on GitHub ↗

* 组合加载器

Source from the content-addressed store, hash-verified

12 * 组合加载器
13 */
14class CombineLoader implements MicroApplicationLoader {
15 private productionLoader: MicroApplicationLoader;
16 private developmentLoader: MicroApplicationLoader;
17 private settingLoader: SettingLoader;
18 constructor(
19 pLoader: MicroApplicationLoader,
20 dLoader: MicroApplicationLoader,
21 sLoader: SettingLoader,
22 ) {
23 this.productionLoader = pLoader;
24 this.developmentLoader = dLoader;
25 this.settingLoader = sLoader;
26 }
27
28 public async enabled(): Promise<boolean> {
29 return Promise.resolve(true);
30 }
31
32 public async loadMeta(): Promise<MicroApplication[]> {
33 if (await this.productionLoader.enabled()) {
34 // 加载微前端资源配置
35 const production = await this.productionLoader.loadMeta();
36 // 加载微前端设置配置
37 await this.settingLoader.loadSetting();
38 // 如果启用开发者模式,则加载开发者微前端资源配置
39 if (await this.developmentLoader.enabled()) {
40 const dev = await this.developmentLoader.loadMeta(production);
41 if (!isEmpty(dev)) {
42 debug('MicroApplicationDevelopmentLoader meta config mount');
43 return dev;
44 }
45 }
46 debug('MicroApplicationAPILoader meta config mount');
47 return production;
48 }
49 message.error('微前端启动失败', 0);
50 throw new Error('微前端启动失败');
51 }
52}
53
54const loader = new CombineLoader(apiLoader, developmentLoader, settingLoader);
55

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected