Comparing version 0.0.33 to 0.0.34
import { Injector } from './injector'; | ||
import { Type } from './type'; | ||
import { ReflectiveDependency } from '@tanbo/core/reflective-provider'; | ||
export interface ClassDecoratorContextCallback { | ||
(paramsTypes: any[], annotations: Annotations, constructor: Type<any>): any[] | void; | ||
} | ||
export interface ClassDecoratorInvokeFn { | ||
(constructor: Type<any>, paramTypes: any[]): void; | ||
} | ||
export interface ClassDecoratorPreset { | ||
invoke: ClassDecoratorInvokeFn; | ||
} | ||
export interface ClassAnnotation { | ||
paramTypes: any[]; | ||
decoratorArguments: any[]; | ||
contextCallback: ClassDecoratorContextCallback; | ||
invoke?: ClassDecoratorInvokeFn; | ||
contextCallback?: ClassDecoratorContextCallback; | ||
} | ||
export interface ParamDecoratorConfig { | ||
metadataGenerator: () => any; | ||
reflectiveController?: (reflectiveDependency: ReflectiveDependency) => void; | ||
} | ||
export interface ParamAnnotation { | ||
parameterIndex: number; | ||
config: ParamDecoratorConfig; | ||
decoratorArguments: any[]; | ||
@@ -36,2 +49,3 @@ } | ||
getParamMetadata(token: any): ParamAnnotation[]; | ||
getParamMetadataKeys(): any[]; | ||
getPropMetadataKeys(): any[]; | ||
@@ -38,0 +52,0 @@ pushPropMetadata(token: any, params: PropertyAnnotation): void; |
@@ -28,2 +28,5 @@ export class Annotations { | ||
} | ||
getParamMetadataKeys() { | ||
return Array.from(this.params.keys()); | ||
} | ||
getPropMetadataKeys() { | ||
@@ -30,0 +33,0 @@ return Array.from(this.props.keys()); |
@@ -1,3 +0,3 @@ | ||
import { Annotations, ClassDecoratorContextCallback, PropertyDecoratorContextCallback } from './annotations'; | ||
export declare function makeParamDecorator(token: any, ...params: any[]): ParameterDecorator; | ||
import { Annotations, ClassDecoratorContextCallback, ParamDecoratorConfig, PropertyDecoratorContextCallback } from './annotations'; | ||
export declare function makeParamDecorator(token: any, config: ParamDecoratorConfig, ...params: any[]): ParameterDecorator; | ||
export declare function makePropertyDecorator(token: any, contextCallback: PropertyDecoratorContextCallback): PropertyDecorator; | ||
@@ -4,0 +4,0 @@ export declare function makeMethodDecorator(token: any, ...params: any[]): MethodDecorator; |
import { Annotations } from './annotations'; | ||
export function makeParamDecorator(token, ...params) { | ||
export function makeParamDecorator(token, config, ...params) { | ||
return function (target, propertyKey, parameterIndex) { | ||
@@ -7,2 +7,3 @@ const annotations = getAnnotations(target); | ||
parameterIndex, | ||
config, | ||
decoratorArguments: params | ||
@@ -9,0 +10,0 @@ }); |
@@ -9,3 +9,10 @@ import { makeParamDecorator, makePropertyDecorator } from './decorators'; | ||
else { | ||
return makeParamDecorator(Inject, new Inject(token)); | ||
return makeParamDecorator(Inject, { | ||
metadataGenerator() { | ||
return new Inject(token); | ||
}, | ||
reflectiveController(dep) { | ||
dep.injectKey = token instanceof ForwardRef ? token.getRef() : token; | ||
} | ||
}); | ||
} | ||
@@ -15,3 +22,10 @@ }; | ||
if (!(this instanceof Self)) { | ||
return makeParamDecorator(Self); | ||
return makeParamDecorator(Self, { | ||
metadataGenerator() { | ||
return new Self(); | ||
}, | ||
reflectiveController(dep) { | ||
dep.visibility = Self; | ||
} | ||
}); | ||
} | ||
@@ -21,3 +35,10 @@ }; | ||
if (!(this instanceof SkipSelf)) { | ||
return makeParamDecorator(SkipSelf); | ||
return makeParamDecorator(SkipSelf, { | ||
metadataGenerator() { | ||
return new SkipSelf(); | ||
}, | ||
reflectiveController(dep) { | ||
dep.visibility = SkipSelf; | ||
} | ||
}); | ||
} | ||
@@ -27,3 +48,10 @@ }; | ||
if (!(this instanceof Optional)) { | ||
return makeParamDecorator(Optional); | ||
return makeParamDecorator(Optional, { | ||
metadataGenerator() { | ||
return new Optional(); | ||
}, | ||
reflectiveController(dep) { | ||
dep.visibility = Optional; | ||
} | ||
}); | ||
} | ||
@@ -30,0 +58,0 @@ }; |
@@ -67,3 +67,3 @@ import { InjectFlags } from './injector'; | ||
if (provider.provide !== provider.useClass) { | ||
cacheFn(provider.provide, instance); | ||
cacheFn(provider.useClass, instance); | ||
} | ||
@@ -70,0 +70,0 @@ return instance; |
{ | ||
"name": "@tanbo/di", | ||
"version": "0.0.33", | ||
"version": "0.0.34", | ||
"description": "A dependency injection Library", | ||
@@ -5,0 +5,0 @@ "main": "./bundles/public-api.js", |
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
27588
738
1