@appolo/inject
Advanced tools
Comparing version 8.0.6 to 8.0.7
@@ -11,2 +11,4 @@ "use strict"; | ||
this.instanceCreated = new index_1.Event(); | ||
this.beforeInitialize = new index_1.Event(); | ||
this.afterInitialize = new index_1.Event(); | ||
} | ||
@@ -13,0 +15,0 @@ } |
@@ -10,5 +10,8 @@ import {Event, IEvent} from "@appolo/events/index"; | ||
public readonly instanceOwnCreated: IEvent<InjectEvent> = new Event() | ||
public readonly instanceCreated: IEvent<InjectEvent> = new Event() | ||
public readonly instanceOwnCreated: IEvent<InjectEvent> = new Event(); | ||
public readonly instanceCreated: IEvent<InjectEvent> = new Event(); | ||
public readonly beforeInitialize: IEvent<void> = new Event(); | ||
public readonly afterInitialize: IEvent<void> = new Event(); | ||
} |
@@ -13,3 +13,3 @@ import {Injector} from "./inject"; | ||
aliasFactory?: string, | ||
alias?: string, | ||
alias?: string | Class, | ||
array?: IParamInject[], | ||
@@ -45,3 +45,3 @@ dictionary?: IParamInject[], | ||
aliasFactory?: string[] | ||
alias?: string[] | ||
alias?: (string | Class)[] | ||
initMethod?: string | ||
@@ -54,4 +54,4 @@ bootstrapMethod?: string | ||
//$isFactoryWired?: boolean | ||
properties?: IParamInject[] | ||
props?: IParamInject[] | ||
//properties?: IParamInject[] | ||
//props?: IParamInject[] | ||
inject?: IParamInject[] | ||
@@ -58,0 +58,0 @@ injectorAware?: boolean |
@@ -48,2 +48,3 @@ "use strict"; | ||
this.initDefinitions(); | ||
await this._events.beforeInitialize.fireEventAsync(); | ||
await this.initFactories(); | ||
@@ -55,2 +56,3 @@ this.initInstances(); | ||
this._isInitialized = true; | ||
await this._events.afterInitialize.fireEventAsync(); | ||
} | ||
@@ -528,3 +530,3 @@ initDefinitions() { | ||
_prepareProperties(definition) { | ||
let properties = definition.props || definition.properties || []; | ||
let properties = definition.inject || []; | ||
for (let i = 0, length = (definition.inject ? definition.inject.length : 0); i < length; i++) { | ||
@@ -570,3 +572,3 @@ let injectable = definition.inject[i]; | ||
} | ||
definition.properties = properties; | ||
definition.inject = properties; | ||
} | ||
@@ -593,3 +595,3 @@ _wireObjectInstance(instance, definition, objectId) { | ||
} | ||
let obj, properties = objectDefinition.properties; | ||
let obj, properties = objectDefinition.inject; | ||
for (let i = 0, length = (properties ? properties.length : 0); i < length; i++) { | ||
@@ -717,4 +719,4 @@ let prop = properties[i]; | ||
} | ||
for (let i = 0, length = (definition.properties ? definition.properties.length : 0); i < length; i++) { | ||
let prop = definition.properties[i]; | ||
for (let i = 0, length = (definition.inject ? definition.inject.length : 0); i < length; i++) { | ||
let prop = definition.inject[i]; | ||
let injector = prop.injector ? prop.injector : this; | ||
@@ -730,4 +732,4 @@ (prop.alias) && (instance[prop.name] = prop.indexBy | ||
} | ||
for (let i = 0, length = (definition.properties ? definition.properties.length : 0); i < length; i++) { | ||
let prop = definition.properties[i]; | ||
for (let i = 0, length = (definition.inject ? definition.inject.length : 0); i < length; i++) { | ||
let prop = definition.inject[i]; | ||
let injector = prop.injector ? prop.injector : this; | ||
@@ -734,0 +736,0 @@ if (prop.aliasFactory) { |
@@ -84,2 +84,5 @@ "use strict"; | ||
this.initDefinitions(); | ||
await (this._events.beforeInitialize as Event<void>).fireEventAsync(); | ||
await this.initFactories(); | ||
@@ -97,2 +100,4 @@ this.initInstances(); | ||
this._isInitialized = true; | ||
await (this._events.afterInitialize as Event<void>).fireEventAsync(); | ||
} | ||
@@ -397,3 +402,3 @@ | ||
if (inject.alias) { | ||
let ids = this.getAliasDefinitions(inject.alias).map((def => def.id)); | ||
let ids = this.getAliasDefinitions(inject.alias as string).map((def => def.id)); | ||
for (let id of ids) { | ||
@@ -476,3 +481,3 @@ await this.getFactory(id, JSON.parse(JSON.stringify(refs))) | ||
public addDefinitions(definitions: { [index: string]: any } | Map<string, any>): Injector { | ||
public addDefinitions(definitions: { [index: string]: IDefinition } | Map<string, IDefinition>): Injector { | ||
@@ -776,3 +781,3 @@ if (definitions instanceof Map) { | ||
let properties = definition.props || definition.properties || []; | ||
let properties = definition.inject || []; | ||
@@ -840,3 +845,3 @@ | ||
definition.properties = properties; | ||
definition.inject = properties; | ||
} | ||
@@ -873,3 +878,3 @@ | ||
} | ||
let obj, properties = objectDefinition.properties; | ||
let obj, properties = objectDefinition.inject; | ||
@@ -1035,9 +1040,9 @@ for (let i = 0, length = (properties ? properties.length : 0); i < length; i++) { | ||
for (let i = 0, length = (definition.properties ? definition.properties.length : 0); i < length; i++) { | ||
let prop = definition.properties[i]; | ||
for (let i = 0, length = (definition.inject ? definition.inject.length : 0); i < length; i++) { | ||
let prop = definition.inject[i]; | ||
let injector = prop.injector ? prop.injector : this; | ||
(prop.alias) && (instance[prop.name] = prop.indexBy | ||
? Util.keyBy(injector.getAlias(prop.alias), prop.indexBy) | ||
: injector.getAlias(prop.alias)); | ||
? Util.keyBy(injector.getAlias(prop.alias as string), prop.indexBy) | ||
: injector.getAlias(prop.alias as string)); | ||
} | ||
@@ -1051,4 +1056,4 @@ } | ||
for (let i = 0, length = (definition.properties ? definition.properties.length : 0); i < length; i++) { | ||
let prop = definition.properties[i]; | ||
for (let i = 0, length = (definition.inject ? definition.inject.length : 0); i < length; i++) { | ||
let prop = definition.inject[i]; | ||
@@ -1055,0 +1060,0 @@ let injector = prop.injector ? prop.injector : this; |
@@ -34,3 +34,3 @@ { | ||
"main": "./index.js", | ||
"version": "8.0.6", | ||
"version": "8.0.7", | ||
"license": "MIT", | ||
@@ -37,0 +37,0 @@ "repository": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
177126
2778