Remove convention where Async suffix is added to functions that returns a Promise. It was a habit from C#, but is not widely used in JavaScript / TypeScript world, also bloats the code. The code is more consistent with third party dependencies/frameworks without the suffix.
22 lines
918 B
TypeScript
22 lines
918 B
TypeScript
import { IApplication } from '@/domain/IApplication';
|
|
import { AsyncLazy } from '@/infrastructure/Threading/AsyncLazy';
|
|
import { IApplicationFactory } from './IApplicationFactory';
|
|
import { parseApplication } from './Parser/ApplicationParser';
|
|
|
|
export type ApplicationGetter = () => IApplication;
|
|
const ApplicationGetter: ApplicationGetter = parseApplication;
|
|
|
|
export class ApplicationFactory implements IApplicationFactory {
|
|
public static readonly Current: IApplicationFactory = new ApplicationFactory(ApplicationGetter);
|
|
private readonly getter: AsyncLazy<IApplication>;
|
|
protected constructor(costlyGetter: ApplicationGetter) {
|
|
if (!costlyGetter) {
|
|
throw new Error('undefined getter');
|
|
}
|
|
this.getter = new AsyncLazy<IApplication>(() => Promise.resolve(costlyGetter()));
|
|
}
|
|
public getApp(): Promise<IApplication> {
|
|
return this.getter.getValue();
|
|
}
|
|
}
|