Skip to content

Commit

Permalink
fix: fix this
Browse files Browse the repository at this point in the history
  • Loading branch information
akitaSummer committed Sep 14, 2024
1 parent 7564f6c commit 5e97543
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions core/metadata/src/factory/LoadUnitFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,29 @@ export class LoadUnitFactory {
private static loadUnitIdMap: Map<Id, LoadUnit> = new Map();

protected static async getLoanUnit(ctx: LoadUnitLifecycleContext, type: EggLoadUnitTypeLike) {
const creator = this.loadUnitCreatorMap.get(type);
const creator = LoadUnitFactory.loadUnitCreatorMap.get(type);
if (!creator) {
throw new Error(`not find creator for load unit type ${type}`);
}
return await creator(ctx);
}

static async createLoadUnit(unitPath: string, type: EggLoadUnitTypeLike, loader: Loader): Promise<LoadUnit> {
if (this.loadUnitMap.has(unitPath)) {
return this.loadUnitMap.get(unitPath)!.loadUnit;
if (LoadUnitFactory.loadUnitMap.has(unitPath)) {
return LoadUnitFactory.loadUnitMap.get(unitPath)!.loadUnit;
}
const ctx: LoadUnitLifecycleContext = {
unitPath,
loader,
};
const loadUnit = await this.getLoanUnit(ctx, type);
const loadUnit = await LoadUnitFactory.getLoanUnit(ctx, type);
await LoadUnitLifecycleUtil.objectPreCreate(ctx, loadUnit);
if (loadUnit.init) {
await loadUnit.init(ctx);
}
await LoadUnitLifecycleUtil.objectPostCreate(ctx, loadUnit);
this.loadUnitMap.set(unitPath, { loadUnit, ctx });
this.loadUnitIdMap.set(loadUnit.id, loadUnit);
LoadUnitFactory.loadUnitMap.set(unitPath, { loadUnit, ctx });
LoadUnitFactory.loadUnitIdMap.set(loadUnit.id, loadUnit);
return loadUnit;
}

Expand All @@ -46,28 +46,28 @@ export class LoadUnitFactory {
unitPath,
loader,
};
return await this.getLoanUnit(ctx, type);
return await LoadUnitFactory.getLoanUnit(ctx, type);
}

static async destroyLoadUnit(loadUnit: LoadUnit) {
const { ctx } = this.loadUnitMap.get(loadUnit.unitPath)!;
const { ctx } = LoadUnitFactory.loadUnitMap.get(loadUnit.unitPath)!;
try {
await LoadUnitLifecycleUtil.objectPreDestroy(ctx, loadUnit);
if (loadUnit.destroy) {
await loadUnit.destroy(ctx);
}
} finally {
this.loadUnitMap.delete(loadUnit.unitPath);
this.loadUnitIdMap.delete(loadUnit.id);
LoadUnitFactory.loadUnitMap.delete(loadUnit.unitPath);
LoadUnitFactory.loadUnitIdMap.delete(loadUnit.id);
LoadUnitLifecycleUtil.clearObjectLifecycle(loadUnit);
}
}

static getLoadUnitById(id: Id): LoadUnit | undefined {
return this.loadUnitIdMap.get(id);
return LoadUnitFactory.loadUnitIdMap.get(id);
}

static registerLoadUnitCreator(type: EggLoadUnitTypeLike, creator: LoadUnitCreator) {
this.loadUnitCreatorMap.set(type, creator);
LoadUnitFactory.loadUnitCreatorMap.set(type, creator);
}
}

0 comments on commit 5e97543

Please sign in to comment.