feat(core): add lazy module loader class

This commit is contained in:
Kamil Myśliwiec
2021-02-11 13:48:36 +01:00
parent 4c432a729c
commit c212327794
11 changed files with 235 additions and 57 deletions

View File

@@ -59,6 +59,7 @@ export class Module {
>();
private readonly _exports = new Set<InstanceToken>();
private _distance = 0;
private _token: string;
constructor(
private readonly _metatype: Type<any>,
@@ -72,6 +73,14 @@ export class Module {
return this._id;
}
get token(): string {
return this._token;
}
set token(token: string) {
this._token = token;
}
get providers(): Map<InstanceToken, InstanceWrapper<Injectable>> {
return this._providers;
}
@@ -411,15 +420,13 @@ export class Module {
if (this._providers.has(token)) {
return token;
}
const importsArray = [...this._imports.values()];
const importsNames = iterate(importsArray)
const imports = iterate(this._imports.values())
.filter(item => !!item)
.map(({ metatype }) => metatype)
.filter(metatype => !!metatype)
.map(({ name }) => name)
.toArray();
if (!importsNames.includes(token as string)) {
if (!imports.includes(token as Type<unknown>)) {
const { name } = this.metatype;
const providerName = isFunction(token) ? (token as Function).name : token;
throw new UnknownExportException(providerName as string, name);