Comparing version 0.0.31 to 0.0.32
@@ -0,0 +0,0 @@ import { Injector } from './injector'; |
@@ -0,0 +0,0 @@ export class Annotations { |
@@ -0,0 +0,0 @@ import { Annotations, ClassDecoratorContextCallback, PropertyDecoratorContextCallback } from './annotations'; |
@@ -0,0 +0,0 @@ import { Annotations } from './annotations'; |
@@ -1,6 +0,6 @@ | ||
export declare class ForwardRef { | ||
export declare class ForwardRef<T = any> { | ||
private forwardRefFn; | ||
constructor(forwardRefFn: () => any); | ||
getRef(): any; | ||
constructor(forwardRefFn: () => T); | ||
getRef(): T; | ||
} | ||
export declare function forwardRef(fn: () => any): ForwardRef; | ||
export declare function forwardRef<T>(fn: () => T): ForwardRef<T>; |
@@ -0,0 +0,0 @@ export class ForwardRef { |
@@ -0,0 +0,0 @@ export interface Injectable { |
@@ -0,0 +0,0 @@ import { makeClassDecorator } from './decorators'; |
@@ -0,0 +0,0 @@ export declare class InjectionToken<T> { |
@@ -0,0 +0,0 @@ export class InjectionToken { |
import { Type } from './type'; | ||
import { InjectionToken } from './injection-token'; | ||
export declare enum InjectFlags { | ||
Default = 0, | ||
Self = 1, | ||
SkipSelf = 2, | ||
Optional = 3 | ||
Default = "Default", | ||
Self = "Self", | ||
SkipSelf = "SkipSelf", | ||
Optional = "Optional" | ||
} | ||
@@ -9,0 +9,0 @@ export declare abstract class Injector { |
export var InjectFlags; | ||
(function (InjectFlags) { | ||
InjectFlags[InjectFlags["Default"] = 0] = "Default"; | ||
InjectFlags[InjectFlags["Self"] = 1] = "Self"; | ||
InjectFlags[InjectFlags["SkipSelf"] = 2] = "SkipSelf"; | ||
InjectFlags[InjectFlags["Optional"] = 3] = "Optional"; | ||
InjectFlags["Default"] = "Default"; | ||
InjectFlags["Self"] = "Self"; | ||
InjectFlags["SkipSelf"] = "SkipSelf"; | ||
InjectFlags["Optional"] = "Optional"; | ||
})(InjectFlags || (InjectFlags = {})); | ||
export class Injector { | ||
} |
import { Type } from './type'; | ||
import { InjectFlags } from './injector'; | ||
import { InjectionToken } from './injection-token'; | ||
import { ForwardRef } from './forward-ref'; | ||
export interface Inject { | ||
@@ -33,11 +36,10 @@ token: any; | ||
<T extends Type<any>>(type: T): T; | ||
(target: Object, propertyKey?: string | symbol, parameterIndex?: number): void; | ||
(target: unknown, propertyKey?: string | symbol, parameterIndex?: number): void; | ||
} | ||
export interface Prop { | ||
token: any; | ||
} | ||
export interface PropDecorator { | ||
(token: any): PropertyDecorator; | ||
<T>(token: Type<T> | InjectionToken<T> | ForwardRef<T>, notFoundValue?: T, flags?: InjectFlags): PropertyDecorator; | ||
new (token: any): Prop; | ||
} | ||
export declare const Prop: PropDecorator; |
@@ -28,6 +28,3 @@ import { makeParamDecorator, makePropertyDecorator } from './decorators'; | ||
export const Prop = function PropDecorator(token, notFoundValue = THROW_IF_NOT_FOUND, flags) { | ||
if (this instanceof PropDecorator) { | ||
this.token = token; | ||
} | ||
else { | ||
if (!(this instanceof Prop)) { | ||
return makePropertyDecorator(Prop, function (instance, propertyName, injector) { | ||
@@ -34,0 +31,0 @@ instance[propertyName] = injector.get(token instanceof ForwardRef ? token.getRef() : token, notFoundValue, flags); |
import { Injector } from './injector'; | ||
export declare const THROW_IF_NOT_FOUND: {}; | ||
export declare const THROW_IF_NOT_FOUND: any; | ||
export declare class NullInjector implements Injector { | ||
@@ -4,0 +4,0 @@ parentInjector: any; |
import { makeInjectError } from './utils/_api'; | ||
export const THROW_IF_NOT_FOUND = {}; | ||
export const THROW_IF_NOT_FOUND = { | ||
__debug_value__: 'THROW_IF_NOT_FOUND' | ||
}; | ||
const nullInjectorErrorFn = makeInjectError('NullInjectorError'); | ||
@@ -4,0 +6,0 @@ export class NullInjector { |
@@ -0,0 +0,0 @@ import { Type } from './type'; |
export {}; |
@@ -0,0 +0,0 @@ import { Provider } from './provider'; |
@@ -34,3 +34,3 @@ import { InjectFlags, Injector } from './injector'; | ||
const params = this.resolveDeps(deps || [], notFoundValue); | ||
let reflectiveValue = factory(...params); | ||
const reflectiveValue = factory(...params); | ||
this.reflectiveValues.set(token, reflectiveValue); | ||
@@ -40,4 +40,7 @@ return reflectiveValue; | ||
} | ||
if (flags === InjectFlags.Self && notFoundValue === THROW_IF_NOT_FOUND) { | ||
throw reflectiveInjectorErrorFn(token); | ||
if (flags === InjectFlags.Self) { | ||
if (notFoundValue === THROW_IF_NOT_FOUND) { | ||
throw reflectiveInjectorErrorFn(token); | ||
} | ||
return notFoundValue; | ||
} | ||
@@ -63,5 +66,10 @@ if (this.parentInjector) { | ||
if (this.parentInjector) { | ||
reflectiveValue = this.parentInjector.get(injectToken, tryValue, InjectFlags.Default); | ||
reflectiveValue = this.parentInjector.get(injectToken, tryValue, dep.optional ? InjectFlags.Optional : InjectFlags.Default); | ||
} | ||
else { | ||
if (dep.optional) { | ||
if (notFoundValue === THROW_IF_NOT_FOUND) { | ||
return null; | ||
} | ||
} | ||
throw reflectiveInjectorErrorFn(injectToken); | ||
@@ -68,0 +76,0 @@ } |
@@ -0,0 +0,0 @@ import { Provider } from './provider'; |
@@ -0,0 +0,0 @@ import { Inject, Optional, Self, SkipSelf } from './metadata'; |
@@ -0,0 +0,0 @@ export declare const Type: FunctionConstructor; |
export const Type = Function; |
export * from './inject-error'; | ||
export * from './stringify'; |
export * from './inject-error'; | ||
export * from './stringify'; |
export declare function makeInjectError(name: string): (token: any) => Error; |
@@ -0,0 +0,0 @@ import { stringify } from './stringify'; |
export declare function stringify(token: any): string; |
@@ -0,0 +0,0 @@ export function stringify(token) { |
@@ -0,0 +0,0 @@ export * from './core/utils/_api'; |
@@ -0,0 +0,0 @@ export * from './core/utils/_api'; |
{ | ||
"name": "@tanbo/di", | ||
"version": "0.0.31", | ||
"version": "0.0.32", | ||
"description": "A dependency injection Library", | ||
@@ -5,0 +5,0 @@ "main": "./bundles/public-api.js", |
26333
682