Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@appolo/inject

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@appolo/inject - npm Package Compare versions

Comparing version 8.0.3 to 8.0.4

4

lib/define.js

@@ -40,2 +40,6 @@ "use strict";

}
injector(injector) {
this._definition.injector = injector;
return this;
}
singleton(singleton = true) {

@@ -42,0 +46,0 @@ this._definition.singleton = util_1.Util.isUndefined(singleton) ? true : singleton;

"use strict";
import {Class, IDefinition, IParamInject} from "./IDefinition";
import {Util} from "./util";
import {Injector} from "./inject";

@@ -59,2 +60,8 @@ export class Define {

public injector(injector: Injector): this {
this._definition.injector = injector;
return this;
}
public singleton(singleton: boolean = true): this {

@@ -61,0 +68,0 @@

39

lib/inject.js

@@ -12,2 +12,5 @@ "use strict";

this._isInitialized = false;
this._instanceOwnInitializedEvent = new events_1.Event();
this._instanceInitializedEvent = new events_1.Event();
this._instanceOwnCreatedEvent = new events_1.Event();
this._instanceCreatedEvent = new events_1.Event();

@@ -24,5 +27,14 @@ this._instances = {};

}
get instanceInitializedEvent() {
return this._instanceInitializedEvent;
}
get instanceOwnInitializedEvent() {
return this._instanceOwnInitializedEvent;
}
get instanceCreatedEvent() {
return this._instanceCreatedEvent;
}
get instanceOwnCreatedEvent() {
return this._instanceOwnCreatedEvent;
}
get parent() {

@@ -217,3 +229,3 @@ return this._parent;

}
if (def.injector) {
if (def.injector && def.injector !== this) {
return def.injector.getFactoryValue(def.refName || def.id);

@@ -232,3 +244,3 @@ }

}
if (def.injector) {
if (def.injector && def.injector !== this) {
return def.injector.getFactory(def.refName || def.id, refs);

@@ -276,3 +288,3 @@ }

if (def) {
return def.injector
return def.injector && def.injector !== this
? def.injector.getObject(def.refName || objectID, runtimeArgs)

@@ -386,3 +398,3 @@ : this._createObjectInstance(objectID, this._definitions[objectID], runtimeArgs);

if (def) {
return def.injector ? def.injector.getDefinition(def.refName || id) : def;
return def.injector && def.injector !== this ? def.injector.getDefinition(def.refName || id) : def;
}

@@ -426,2 +438,3 @@ }

define.path(filePath);
define.injector(this);
this.addDefinition(define.definition.id || id, define.definition);

@@ -457,2 +470,7 @@ return define;

}
this._instanceCreatedEvent.fireEvent({ instance, definition: def });
this._instanceOwnCreatedEvent.fireEvent({ instance, definition: def });
if (this._parent) {
this._parent.instanceCreatedEvent.fireEvent({ instance, definition: def });
}
if (def.singleton && def.lazy) {

@@ -518,3 +536,7 @@ this._addSingletonAliases(def, instance);

instance[IsWiredSymbol] = true;
this._instanceCreatedEvent.fireEvent({ instance, definition });
this._instanceInitializedEvent.fireEvent({ instance, definition });
this._instanceOwnInitializedEvent.fireEvent({ instance, definition });
if (this._parent) {
this._parent.instanceInitializedEvent.fireEvent({ instance, definition });
}
}

@@ -533,3 +555,4 @@ _prepareProperties(definition) {

if (dto.parent && dto.parent !== definition.type) {
dto.injector = this._children.find(injector => !!injector.getDefinitionsValue().find(def => def.type === dto.parent));
let define = util_1.Util.getClassDefinition(dto.parent);
dto.injector = define && define.definition.injector ? define.definition.injector : this._children.find(injector => !!injector.getDefinitionsValue().find(def => def.type === dto.parent));
}

@@ -579,3 +602,3 @@ let injector = dto.injector || this;

_getByParamObj(propObj, ref, args) {
return propObj.injector ? propObj.injector._get(ref, args) : this._get(ref, args);
return propObj.injector && propObj.injector !== this ? propObj.injector._get(ref, args) : this._get(ref, args);
}

@@ -673,3 +696,3 @@ _injectPropertiesAndLookUpMethods(object, objectDefinition, objectId) {

let propName = keys[i], factory = factoryData[propName];
instance[propName] = factory.injector ? factory.injector.getFactoryValue(factory.id) : this.getFactoryValue(factory.id);
instance[propName] = factory.injector && factory.injector !== this ? factory.injector.getFactoryValue(factory.id) : this.getFactoryValue(factory.id);
}

@@ -676,0 +699,0 @@ }

@@ -32,4 +32,8 @@ "use strict";

private _instanceCreatedEvent = new Event<{ instance: any, definition: IDefinition }>()
private _instanceOwnInitializedEvent = new Event<{ instance: any, definition: IDefinition }>();
private _instanceInitializedEvent = new Event<{ instance: any, definition: IDefinition }>();
private _instanceOwnCreatedEvent = new Event<{ instance: any, definition: IDefinition }>();
private _instanceCreatedEvent = new Event<{ instance: any, definition: IDefinition }>();
constructor() {

@@ -47,2 +51,10 @@ this._instances = {};

public get instanceInitializedEvent(): IEvent<{ instance: any, definition: IDefinition }> {
return this._instanceInitializedEvent
}
public get instanceOwnInitializedEvent(): IEvent<{ instance: any, definition: IDefinition }> {
return this._instanceOwnInitializedEvent
}
public get instanceCreatedEvent(): IEvent<{ instance: any, definition: IDefinition }> {

@@ -52,2 +64,6 @@ return this._instanceCreatedEvent

public get instanceOwnCreatedEvent(): IEvent<{ instance: any, definition: IDefinition }> {
return this._instanceOwnCreatedEvent
}
public get parent(): Injector {

@@ -92,4 +108,2 @@ return this._parent

this.initProperties();

@@ -336,3 +350,3 @@

if (def.injector) {
if (def.injector && def.injector !== this) {
return def.injector.getFactoryValue<T>(def.refName || def.id);

@@ -358,3 +372,3 @@ }

if (def.injector) {
if (def.injector && def.injector !== this) {
return def.injector.getFactory<T>(def.refName || def.id, refs);

@@ -423,3 +437,3 @@ }

if (def) {
return def.injector
return def.injector && def.injector !== this
? def.injector.getObject(def.refName || objectID, runtimeArgs)

@@ -579,3 +593,3 @@ : this._createObjectInstance<T>(objectID, this._definitions[objectID], runtimeArgs);

if (def) {
return def.injector ? def.injector.getDefinition(def.refName || id) : def;
return def.injector && def.injector !== this ? def.injector.getDefinition(def.refName || id) : def;
}

@@ -628,3 +642,3 @@ }

let define = type
let define: Define = type
? (Reflect.getMetadata(InjectDefineSymbol, type) || new Define(id as string, type))

@@ -634,4 +648,5 @@ : new Define(id as string);

define.path(filePath);
define.injector(this);
this.addDefinition(define.definition.id || id, define.definition);
this.addDefinition(define.definition.id || id as string, define.definition);

@@ -674,2 +689,9 @@ return define;

this._instanceCreatedEvent.fireEvent({instance, definition: def});
this._instanceOwnCreatedEvent.fireEvent({instance, definition: def});
if (this._parent) {
(this._parent.instanceCreatedEvent as Event<any>).fireEvent({instance, definition: def})
}
if (def.singleton && def.lazy) {

@@ -757,3 +779,8 @@

this._instanceCreatedEvent.fireEvent({instance, definition});
this._instanceInitializedEvent.fireEvent({instance, definition});
this._instanceOwnInitializedEvent.fireEvent({instance, definition});
if (this._parent) {
(this._parent.instanceInitializedEvent as Event<any>).fireEvent({instance, definition});
}
}

@@ -780,3 +807,6 @@

if (dto.parent && dto.parent !== definition.type) {
dto.injector = this._children.find(injector => !!injector.getDefinitionsValue().find(def => def.type === dto.parent))
let define = Util.getClassDefinition(dto.parent);
dto.injector = define && define.definition.injector ? define.definition.injector : this._children.find(injector => !!injector.getDefinitionsValue().find(def => def.type === dto.parent))
}

@@ -849,3 +879,3 @@

private _getByParamObj(propObj: IParamInject, ref: string, args?: any[]) {
return propObj.injector ? propObj.injector._get(ref, args) : this._get(ref, args)
return propObj.injector && propObj.injector !== this ? propObj.injector._get(ref, args) : this._get(ref, args)
}

@@ -979,3 +1009,3 @@

instance[propName] = factory.injector ? factory.injector.getFactoryValue(factory.id) : this.getFactoryValue(factory.id);
instance[propName] = factory.injector && factory.injector !== this ? factory.injector.getFactoryValue(factory.id) : this.getFactoryValue(factory.id);
}

@@ -982,0 +1012,0 @@ }

@@ -34,3 +34,3 @@ {

"main": "./index.js",
"version": "8.0.3",
"version": "8.0.4",
"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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc