reverse initialization order, prepare for publishing

This commit is contained in:
nitowa
2022-10-16 02:45:49 +02:00
parent 963a3a9652
commit a373b178c6
10 changed files with 20 additions and 17 deletions
+1
View File
@@ -9,6 +9,7 @@ export function Singleton(config?: {
interface?: Constructor<any>,
initializationPriority?: number
}): GenericClassDecorator<Type<any>> {
return (clazz: Type<any>) => {
Injector['singletonDefinitions'].push({
initializationPriority: config ?. initializationPriority,
+2 -2
View File
@@ -1,6 +1,6 @@
import 'reflect-metadata';
import { ERR_NO_INITIALIZE_WITH_PRIORITY, ERR_NO_INJECTION_TOKEN } from './Strings';
import { Constructor, Type, Module as SingletonDefinition, InjectionError, InjectionResolutionError } from './Internals';
import { Constructor, Type, SingletonDefinition, InjectionError, InjectionResolutionError } from './Internals';
class _Injector {
@@ -71,7 +71,7 @@ class _Injector {
private initializeSingletons = () => {
this.singletonDefinitions
.sort((a, b) => (a.initializationPriority ?? 0) - (b.initializationPriority ?? 0))
.sort((a, b) => (b.initializationPriority ?? 0) - (a.initializationPriority ?? 0))
.map(def => this.singletonObjects[def.ctor.name])
.forEach(obj => obj.initialize ? obj.initialize() : undefined)
}
+2 -2
View File
@@ -12,8 +12,8 @@ export type Constructor<T> = Function & { prototype: T }
*/
export type GenericClassDecorator<T> = (target: T) => void;
export type Module = {
initializationPriority?: number //Priority of initializing this object after creation
export type SingletonDefinition = {
initializationPriority?: number //Priority of initializing this object after creation, lower value means higher priority; default: 0
ctor: Type<any> //Object constructor to make singleton from
}