Skip to content

Commit

Permalink
refactor: fix linter errors
Browse files Browse the repository at this point in the history
  • Loading branch information
NoNameProvided committed Jan 9, 2021
1 parent 53d6f13 commit ee97141
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 20 deletions.
7 changes: 4 additions & 3 deletions src/container-instance.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ export class ContainerInstance {
*/
getAsync<T>(identifier: ServiceIdentifier<T>): Promise<T> {
const globalContainer = Container.of(undefined);
let service = globalContainer.findService(identifier);
let scopedService = this.findService(identifier);
const service = globalContainer.findService(identifier);
const scopedService = this.findService(identifier);

if (service && service.global === true) return this.getServiceValueAsync(identifier, service);

Expand Down Expand Up @@ -472,7 +472,7 @@ export class ContainerInstance {
if (service.factory instanceof Array) {
// use special [Type, "create"] syntax to allow factory services
// in this case Type instance will be obtained from Container and its method "create" will be called
value = ((await this.getAsync(service.factory[0])) as any)[service.factory[1]](...params);
value = (await this.getAsync(service.factory[0]))[service.factory[1]](...params);
} else {
// regular factory function
value = service.factory(...params, this);
Expand All @@ -488,6 +488,7 @@ export class ContainerInstance {
// need to be injected, and user can use provided container to get instances he needs
params.push(this);

// eslint-disable-next-line prefer-spread
value = new (type.bind.apply(type, params))();
}

Expand Down
25 changes: 13 additions & 12 deletions src/error/MissingInitializedPromiseError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@
* Thrown when user improperly uses the asyncInitialization Service option.
*/
export class MissingInitializedPromiseError extends Error {
name = "MissingInitializedPromiseError";
name = 'MissingInitializedPromiseError';

constructor(value: any) {
super(
(value.initialized
? `asyncInitialization: true was used, but ${value.name}#initialized is not a Promise. `
: `asyncInitialization: true was used, but ${value.name}#initialized is undefined. `) +
`You will need to either extend the abstract AsyncInitializedService class, or assign ` +
`${value.name}#initialized to a Promise in your class' constructor that resolves when all required ` +
`initialization is complete.`
);
Object.setPrototypeOf(this, MissingInitializedPromiseError.prototype);
}
// TODO: User proper type
constructor(value: { name: string; initialized: boolean }) {
super(
(value.initialized
? `asyncInitialization: true was used, but ${value.name}#initialized is not a Promise. `
: `asyncInitialization: true was used, but ${value.name}#initialized is undefined. `) +
`You will need to either extend the abstract AsyncInitializedService class, or assign ` +
`${value.name}#initialized to a Promise in your class' constructor that resolves when all required ` +
`initialization is complete.`
);
Object.setPrototypeOf(this, MissingInitializedPromiseError.prototype);
}
}
10 changes: 5 additions & 5 deletions src/types/AsyncInitializedService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
* Extend when declaring a service with asyncInitialization: true flag.
*/
export abstract class AsyncInitializedService {
public initialized: Promise<any>;
public initialized: Promise<any>;

constructor() {
this.initialized = this.initialize();
}
constructor() {
this.initialized = this.initialize();
}

protected abstract initialize(): Promise<any>;
protected abstract initialize(): Promise<any>;
}

0 comments on commit ee97141

Please sign in to comment.