Skip to content

Commit

Permalink
fix: egg qualifier should register after all file loaded (#100)
Browse files Browse the repository at this point in the history
  • Loading branch information
killagu authored Feb 13, 2023
1 parent b664147 commit 5033b51
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 18 deletions.
8 changes: 5 additions & 3 deletions plugin/tegg/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,17 @@ export default class App {
configDidLoad() {
this.eggContextHandler = new EggContextHandler(this.app);
this.app.eggContextHandler = this.eggContextHandler;
this.eggQualifierProtoHook = new EggQualifierProtoHook(this.app);
this.eggContextHandler.register();
this.app.loadUnitLifecycleUtil.registerLifecycle(this.eggQualifierProtoHook);
this.app.moduleHandler = new ModuleHandler(this.app);
}

async didLoad() {
hijackRunInBackground(this.app);
await this.app.moduleHandler.ready();
// wait all file loaded, so app/ctx has all properties
this.eggQualifierProtoHook = new EggQualifierProtoHook(this.app);
this.app.loadUnitLifecycleUtil.registerLifecycle(this.eggQualifierProtoHook);
// start load tegg objects
await this.app.moduleHandler.init();
this.compatibleHook = new EggContextCompatibleHook(this.app.moduleHandler);
this.app.eggContextLifecycleUtil.registerLifecycle(this.compatibleHook);
}
Expand Down
37 changes: 22 additions & 15 deletions plugin/tegg/lib/ModuleHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,36 @@ export class ModuleHandler extends Base {
private readonly app: Application;

constructor(app: Application) {
super({ initMethod: '_init' });
super();
this.app = app;
this.loadUnitLoader = new EggModuleLoader(this.app);
}

async _init() {
this.app.eggPrototypeCreatorFactory.registerPrototypeCreator(
COMPATIBLE_PROTO_IMPLE_TYPE, EggCompatibleProtoImpl.create);
async init() {
try {
this.app.eggPrototypeCreatorFactory.registerPrototypeCreator(
COMPATIBLE_PROTO_IMPLE_TYPE, EggCompatibleProtoImpl.create);

await this.loadUnitLoader.load();
const instances: LoadUnitInstance[] = [];
// TODO fixtures dts broken the module defintion
(this.app as any).module = {};
await this.loadUnitLoader.load();
const instances: LoadUnitInstance[] = [];
// TODO fixtures dts broken the module defintion
(this.app as any).module = {};

for (const loadUnit of this.loadUnits) {
const instance = await LoadUnitInstanceFactory.createLoadUnitInstance(loadUnit);
if (instance.loadUnit.type !== EggLoadUnitType.APP) {
CompatibleUtil.appCompatible(this.app, instance);
for (const loadUnit of this.loadUnits) {
const instance = await LoadUnitInstanceFactory.createLoadUnitInstance(loadUnit);
if (instance.loadUnit.type !== EggLoadUnitType.APP) {
CompatibleUtil.appCompatible(this.app, instance);
}
instances.push(instance);
}
instances.push(instance);
CompatibleUtil.contextModuleCompatible((this.app as any).context as Context, instances);
this.loadUnitInstances = instances;
this.ready(true);
} catch (e) {
this.ready(e);
throw e;
}
CompatibleUtil.contextModuleCompatible((this.app as any).context as Context, instances);
this.loadUnitInstances = instances;

}

async destroy() {
Expand Down

0 comments on commit 5033b51

Please sign in to comment.