chore: update container and init hook progress

This commit is contained in:
Jacob Nguyen
2023-05-11 01:33:49 -05:00
parent 5e878cc97b
commit 95ec4d0e3c
4 changed files with 11 additions and 8 deletions

View File

@@ -4,6 +4,7 @@ import { isAsyncFunction} from "node:util/types";
import * as assert from 'node:assert'
import { Subject } from "rxjs";
import { ModuleStore } from "./module-store";
import { Dependencies } from "../ioc/types";
/**
* Provides all the defaults for sern to function properly.
@@ -27,9 +28,9 @@ export class CoreContainer<T extends Partial<Dependencies>> extends Container<T,
}
private listenForInsertions() {
assert.ok(this.isReady(), "listening for init functions should only occur prior to sern being ready.")
assert.notEqual(this.isReady(), "listening for init functions should only occur prior to sern being ready.");
const unsubscriber = this.on('containerUpserted', e => this.callInitHooks(e));
const unsubscriber = this.on('containerUpserted', this.callInitHooks);
this.ready$.subscribe({
complete: unsubscriber
});
@@ -39,15 +40,15 @@ export class CoreContainer<T extends Partial<Dependencies>> extends Container<T,
const dep = e.newContainer;
assert.ok(dep);
//Ignore any dependencies that are not objects or array
if(typeof(dep) !== 'object' || Array.isArray(dep)) {
return;
}
if('init' in dep && typeof dep.init === 'function') {
isAsyncFunction(dep.init)
? await dep.init()
: dep.init()
: dep.init();
}
}

View File

@@ -3,6 +3,7 @@ import { ErrorHandling } from "../../contracts";
/**
* @internal
* @since 2.0.0
* Version 4.0.0 will internalize this api. Please refrain from using ModuleStore!
*/
export class DefaultErrorHandling implements ErrorHandling {
keepAlive = 5;

View File

@@ -3,6 +3,7 @@ import { LogPayload, Logging } from "../../contracts";
/**
* @internal
* @since 2.0.0
* Version 4.0.0 will internalize this api. Please refrain from using ModuleStore!
*/
export class DefaultLogging implements Logging {
private date = () => new Date();

View File

@@ -1,14 +1,14 @@
import { ModuleManager } from "../../contracts";
import { CoreModuleStore, ModuleManager } from "../../contracts";
import { importModule } from "../../module-loading";
import { CommandModule } from "../../types/modules";
import { ModuleStore } from "../module-store";
/**
* @internal
* @since 2.0.0
* @since 2.0.0/*
* Version 4.0.0 will internalize this api. Please refrain from using ModuleStore!
*/
export class DefaultModuleManager implements ModuleManager {
constructor(private moduleStore: ModuleStore) {}
constructor(private moduleStore: CoreModuleStore) {}
remove(id: string): boolean {
throw new Error('Method not implemented.');