injection-js
Advanced tools
Comparing version 1.0.3 to 2.0.0-rc.2
@@ -9,19 +9,9 @@ /// <reference types="node" /> | ||
*/ | ||
/** | ||
* @stable | ||
*/ | ||
export declare class BaseError extends Error { | ||
constructor(message: string); | ||
message: string; | ||
readonly name: string; | ||
stack: any; | ||
toString(): string; | ||
} | ||
/** | ||
* @stable | ||
*/ | ||
export declare class WrappedError extends BaseError { | ||
originalError: any; | ||
constructor(message: string, error: any); | ||
readonly stack: any; | ||
} | ||
export declare const ERROR_TYPE: string; | ||
export declare const ERROR_COMPONENT_TYPE: string; | ||
export declare const ERROR_DEBUG_CONTEXT: string; | ||
export declare const ERROR_ORIGINAL_ERROR: string; | ||
export declare function getType(error: Error): Function; | ||
export declare function getDebugContext(error: Error): any; | ||
export declare function getOriginalError(error: Error): Error; | ||
export declare function wrappedError(message: string, originalError: any): Error; |
@@ -8,60 +8,21 @@ /** | ||
*/ | ||
var __extends = (this && this.__extends) || function (d, b) { | ||
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
/** | ||
* @stable | ||
*/ | ||
export var BaseError = (function (_super) { | ||
__extends(BaseError, _super); | ||
function BaseError(message) { | ||
_super.call(this, message); | ||
// Errors don't use current this, instead they create a new instance. | ||
// We have to do forward all of our api to the nativeInstance. | ||
// TODO(bradfordcsmith): Remove this hack when | ||
// google/closure-compiler/issues/2102 is fixed. | ||
var nativeError = new Error(message); | ||
this._nativeError = nativeError; | ||
} | ||
Object.defineProperty(BaseError.prototype, "message", { | ||
get: function () { return this._nativeError.message; }, | ||
set: function (message) { this._nativeError.message = message; }, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(BaseError.prototype, "name", { | ||
get: function () { return this._nativeError.name; }, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(BaseError.prototype, "stack", { | ||
get: function () { return this._nativeError.stack; }, | ||
set: function (value) { this._nativeError.stack = value; }, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
BaseError.prototype.toString = function () { return this._nativeError.toString(); }; | ||
return BaseError; | ||
}(Error)); | ||
/** | ||
* @stable | ||
*/ | ||
export var WrappedError = (function (_super) { | ||
__extends(WrappedError, _super); | ||
function WrappedError(message, error) { | ||
_super.call(this, message + " caused by: " + (error instanceof Error ? error.message : error)); | ||
this.originalError = error; | ||
} | ||
Object.defineProperty(WrappedError.prototype, "stack", { | ||
get: function () { | ||
return (this.originalError instanceof Error ? this.originalError : this._nativeError) | ||
.stack; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
return WrappedError; | ||
}(BaseError)); | ||
export var ERROR_TYPE = 'ngType'; | ||
export var ERROR_COMPONENT_TYPE = 'ngComponentType'; | ||
export var ERROR_DEBUG_CONTEXT = 'ngDebugContext'; | ||
export var ERROR_ORIGINAL_ERROR = 'ngOriginalError'; | ||
export function getType(error) { | ||
return error[ERROR_TYPE]; | ||
} | ||
export function getDebugContext(error) { | ||
return error[ERROR_DEBUG_CONTEXT]; | ||
} | ||
export function getOriginalError(error) { | ||
return error[ERROR_ORIGINAL_ERROR]; | ||
} | ||
export function wrappedError(message, originalError) { | ||
var msg = message + " caused by: " + (originalError instanceof Error ? originalError.message : originalError); | ||
var error = Error(msg); | ||
error[ERROR_ORIGINAL_ERROR] = originalError; | ||
return error; | ||
} | ||
//# sourceMappingURL=errors.js.map |
@@ -21,2 +21,1 @@ /** | ||
export { InjectionToken, OpaqueToken } from './injection_token'; | ||
export { Class } from './util/decorators'; |
@@ -20,3 +20,2 @@ /** | ||
export { InjectionToken, OpaqueToken } from './injection_token'; | ||
export { Class } from './util/decorators'; | ||
//# sourceMappingURL=index.js.map |
@@ -34,7 +34,8 @@ import { Type } from './facade/type'; | ||
*/ | ||
get<T>(token: Type<T> | InjectionToken<T>, notFoundValue?: T): T; | ||
abstract get<T>(token: Type<T> | InjectionToken<T>, notFoundValue?: T): T; | ||
/** | ||
* @deprecated from v4.0.0 use Type<T> or InjectToken<T> | ||
* @suppress {duplicate} | ||
*/ | ||
get(token: any, notFoundValue?: any): any; | ||
abstract get(token: any, notFoundValue?: any): any; | ||
} |
@@ -46,3 +46,2 @@ /** | ||
} | ||
Injector.prototype.get = function (token, notFoundValue) { return new Error('unimplemented'); }; | ||
Injector.THROW_IF_NOT_FOUND = _THROW_IF_NOT_FOUND; | ||
@@ -49,0 +48,0 @@ Injector.NULL = new _NullInjector(); |
{ | ||
"name": "injection-js", | ||
"version": "1.0.3", | ||
"version": "2.0.0-rc.2", | ||
"description": "Dependency Injection library for JavaScript and TypeScript", | ||
@@ -5,0 +5,0 @@ "main": "injection.bundle.js", |
@@ -61,3 +61,3 @@ /** | ||
/** | ||
* If true, than injector returns an array of instances. This is useful to allow multiple | ||
* If true, then injector returns an array of instances. This is useful to allow multiple | ||
* providers spread across many files to provide configuration information to a common token. | ||
@@ -103,3 +103,3 @@ * | ||
/** | ||
* If true, than injector returns an array of instances. This is useful to allow multiple | ||
* If true, then injector returns an array of instances. This is useful to allow multiple | ||
* providers spread across many files to provide configuration information to a common token. | ||
@@ -139,3 +139,3 @@ * | ||
/** | ||
* If true, than injector returns an array of instances. This is useful to allow multiple | ||
* If true, then injector returns an array of instances. This is useful to allow multiple | ||
* providers spread across many files to provide configuration information to a common token. | ||
@@ -182,3 +182,3 @@ * | ||
/** | ||
* A list of `token`s which need to be resolved by the injector. The list of values is than | ||
* A list of `token`s which need to be resolved by the injector. The list of values is then | ||
* used as arguments to the `useFactory` function. | ||
@@ -188,3 +188,3 @@ */ | ||
/** | ||
* If true, than injector returns an array of instances. This is useful to allow multiple | ||
* If true, then injector returns an array of instances. This is useful to allow multiple | ||
* providers spread across many files to provide configuration information to a common token. | ||
@@ -191,0 +191,0 @@ * |
@@ -79,3 +79,3 @@ [![Build Status](https://travis-ci.org/mgechev/injection-js.svg?branch=master)](https://travis-ci.org/mgechev/injection-js) | ||
For full documentation click [here](https://angular.io/docs/ts/latest/guide/dependency-injection.html). | ||
For full documentation click [here](https://angular.io/docs/ts/latest/guide/dependency-injection.html), [here](https://angular.io/docs/ts/latest/cookbook/dependency-injection.html) and [here](https://angular.io/docs/ts/latest/cookbook/ts-to-js.html#!#dependency-injection). | ||
@@ -82,0 +82,0 @@ # License |
@@ -1,18 +0,9 @@ | ||
/** | ||
* @license | ||
* Copyright Google Inc. All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
/// <reference types="node" /> | ||
import { Type } from './facade/type'; | ||
import { BaseError, WrappedError } from './facade/errors'; | ||
import { ReflectiveInjector } from './reflective_injector'; | ||
import { ReflectiveKey } from './reflective_key'; | ||
/** | ||
* Base class for all errors arising from misconfigured providers. | ||
* @stable | ||
*/ | ||
export declare class AbstractProviderError extends BaseError { | ||
constructor(injector: ReflectiveInjector, key: ReflectiveKey, constructResolvingMessage: Function); | ||
export interface InjectionError extends Error { | ||
keys: ReflectiveKey[]; | ||
injectors: ReflectiveInjector[]; | ||
constructResolvingMessage: (this: InjectionError) => string; | ||
addKey(injector: ReflectiveInjector, key: ReflectiveKey): void; | ||
@@ -33,7 +24,4 @@ } | ||
* ``` | ||
* @stable | ||
*/ | ||
export declare class NoProviderError extends AbstractProviderError { | ||
constructor(injector: ReflectiveInjector, key: ReflectiveKey); | ||
} | ||
export declare function noProviderError(injector: ReflectiveInjector, key: ReflectiveKey): InjectionError; | ||
/** | ||
@@ -54,7 +42,4 @@ * Thrown when dependencies form a cycle. | ||
* Retrieving `A` or `B` throws a `CyclicDependencyError` as the graph above cannot be constructed. | ||
* @stable | ||
*/ | ||
export declare class CyclicDependencyError extends AbstractProviderError { | ||
constructor(injector: ReflectiveInjector, key: ReflectiveKey); | ||
} | ||
export declare function cyclicDependencyError(injector: ReflectiveInjector, key: ReflectiveKey): InjectionError; | ||
/** | ||
@@ -85,10 +70,4 @@ * Thrown when a constructing type returns with an Error. | ||
* ``` | ||
* @stable | ||
*/ | ||
export declare class InstantiationError extends WrappedError { | ||
constructor(injector: ReflectiveInjector, originalException: any, originalStack: any, key: ReflectiveKey); | ||
addKey(injector: ReflectiveInjector, key: ReflectiveKey): void; | ||
readonly message: string; | ||
readonly causeKey: ReflectiveKey; | ||
} | ||
export declare function instantiationError(injector: ReflectiveInjector, originalException: any, originalStack: any, key: ReflectiveKey): InjectionError; | ||
/** | ||
@@ -103,7 +82,4 @@ * Thrown when an object other then {@link Provider} (or `Type`) is passed to {@link Injector} | ||
* ``` | ||
* @stable | ||
*/ | ||
export declare class InvalidProviderError extends BaseError { | ||
constructor(provider: any); | ||
} | ||
export declare function invalidProviderError(provider: any): Error; | ||
/** | ||
@@ -138,6 +114,3 @@ * Thrown when the class has no annotation information. | ||
*/ | ||
export declare class NoAnnotationError extends BaseError { | ||
constructor(typeOrFunc: Type<any> | Function, params: any[][]); | ||
private static _genMessage(typeOrFunc, params); | ||
} | ||
export declare function noAnnotationError(typeOrFunc: Type<any> | Function, params: any[][]): Error; | ||
/** | ||
@@ -157,5 +130,3 @@ * Thrown when getting an object by index. | ||
*/ | ||
export declare class OutOfBoundsError extends BaseError { | ||
constructor(index: number); | ||
} | ||
export declare function outOfBoundsError(index: number): Error; | ||
/** | ||
@@ -173,4 +144,2 @@ * Thrown when a multi provider and a regular provider are bound to the same token. | ||
*/ | ||
export declare class MixingMultiProvidersWithRegularProvidersError extends BaseError { | ||
constructor(provider1: any, provider2: any); | ||
} | ||
export declare function mixingMultiProvidersWithRegularProvidersError(provider1: any, provider2: any): Error; |
@@ -8,8 +8,4 @@ /** | ||
*/ | ||
var __extends = (this && this.__extends) || function (d, b) { | ||
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
import { BaseError, WrappedError } from './facade/errors'; | ||
import { wrappedError } from './facade/errors'; | ||
import { ERROR_ORIGINAL_ERROR, getOriginalError } from './facade/errors'; | ||
import { stringify } from './facade/lang'; | ||
@@ -35,23 +31,18 @@ function findFirstClosedCycle(keys) { | ||
} | ||
function injectionError(injector, key, constructResolvingMessage, originalError) { | ||
var error = (originalError ? wrappedError('', originalError) : Error()); | ||
error.addKey = addKey; | ||
error.keys = [key]; | ||
error.injectors = [injector]; | ||
error.constructResolvingMessage = constructResolvingMessage; | ||
error.message = error.constructResolvingMessage(); | ||
error[ERROR_ORIGINAL_ERROR] = originalError; | ||
return error; | ||
} | ||
function addKey(injector, key) { | ||
this.injectors.push(injector); | ||
this.keys.push(key); | ||
this.message = this.constructResolvingMessage(); | ||
} | ||
/** | ||
* Base class for all errors arising from misconfigured providers. | ||
* @stable | ||
*/ | ||
export var AbstractProviderError = (function (_super) { | ||
__extends(AbstractProviderError, _super); | ||
function AbstractProviderError(injector, key, constructResolvingMessage) { | ||
_super.call(this, 'DI Error'); | ||
this.keys = [key]; | ||
this.injectors = [injector]; | ||
this.constructResolvingMessage = constructResolvingMessage; | ||
this.message = this.constructResolvingMessage(this.keys); | ||
} | ||
AbstractProviderError.prototype.addKey = function (injector, key) { | ||
this.injectors.push(injector); | ||
this.keys.push(key); | ||
this.message = this.constructResolvingMessage(this.keys); | ||
}; | ||
return AbstractProviderError; | ||
}(BaseError)); | ||
/** | ||
* Thrown when trying to retrieve a dependency by key from {@link Injector}, but the | ||
@@ -69,14 +60,9 @@ * {@link Injector} does not have a {@link Provider} for the given key. | ||
* ``` | ||
* @stable | ||
*/ | ||
export var NoProviderError = (function (_super) { | ||
__extends(NoProviderError, _super); | ||
function NoProviderError(injector, key) { | ||
_super.call(this, injector, key, function (keys) { | ||
var first = stringify(keys[0].token); | ||
return "No provider for " + first + "!" + constructResolvingPath(keys); | ||
}); | ||
} | ||
return NoProviderError; | ||
}(AbstractProviderError)); | ||
export function noProviderError(injector, key) { | ||
return injectionError(injector, key, function () { | ||
var first = stringify(this.keys[0].token); | ||
return "No provider for " + first + "!" + constructResolvingPath(this.keys); | ||
}); | ||
} | ||
/** | ||
@@ -97,13 +83,8 @@ * Thrown when dependencies form a cycle. | ||
* Retrieving `A` or `B` throws a `CyclicDependencyError` as the graph above cannot be constructed. | ||
* @stable | ||
*/ | ||
export var CyclicDependencyError = (function (_super) { | ||
__extends(CyclicDependencyError, _super); | ||
function CyclicDependencyError(injector, key) { | ||
_super.call(this, injector, key, function (keys) { | ||
return "Cannot instantiate cyclic dependency!" + constructResolvingPath(keys); | ||
}); | ||
} | ||
return CyclicDependencyError; | ||
}(AbstractProviderError)); | ||
export function cyclicDependencyError(injector, key) { | ||
return injectionError(injector, key, function () { | ||
return "Cannot instantiate cyclic dependency!" + constructResolvingPath(this.keys); | ||
}); | ||
} | ||
/** | ||
@@ -134,30 +115,9 @@ * Thrown when a constructing type returns with an Error. | ||
* ``` | ||
* @stable | ||
*/ | ||
export var InstantiationError = (function (_super) { | ||
__extends(InstantiationError, _super); | ||
function InstantiationError(injector, originalException, originalStack, key) { | ||
_super.call(this, 'DI Error', originalException); | ||
this.keys = [key]; | ||
this.injectors = [injector]; | ||
} | ||
InstantiationError.prototype.addKey = function (injector, key) { | ||
this.injectors.push(injector); | ||
this.keys.push(key); | ||
}; | ||
Object.defineProperty(InstantiationError.prototype, "message", { | ||
get: function () { | ||
var first = stringify(this.keys[0].token); | ||
return this.originalError.message + ": Error during instantiation of " + first + "!" + constructResolvingPath(this.keys) + "."; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(InstantiationError.prototype, "causeKey", { | ||
get: function () { return this.keys[0]; }, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
return InstantiationError; | ||
}(WrappedError)); | ||
export function instantiationError(injector, originalException, originalStack, key) { | ||
return injectionError(injector, key, function () { | ||
var first = stringify(this.keys[0].token); | ||
return getOriginalError(this).message + ": Error during instantiation of " + first + "!" + constructResolvingPath(this.keys) + "."; | ||
}, originalException); | ||
} | ||
/** | ||
@@ -172,11 +132,6 @@ * Thrown when an object other then {@link Provider} (or `Type`) is passed to {@link Injector} | ||
* ``` | ||
* @stable | ||
*/ | ||
export var InvalidProviderError = (function (_super) { | ||
__extends(InvalidProviderError, _super); | ||
function InvalidProviderError(provider) { | ||
_super.call(this, "Invalid provider - only instances of Provider and Type are allowed, got: " + provider); | ||
} | ||
return InvalidProviderError; | ||
}(BaseError)); | ||
export function invalidProviderError(provider) { | ||
return Error("Invalid provider - only instances of Provider and Type are allowed, got: " + provider); | ||
} | ||
/** | ||
@@ -211,25 +166,18 @@ * Thrown when the class has no annotation information. | ||
*/ | ||
export var NoAnnotationError = (function (_super) { | ||
__extends(NoAnnotationError, _super); | ||
function NoAnnotationError(typeOrFunc, params) { | ||
_super.call(this, NoAnnotationError._genMessage(typeOrFunc, params)); | ||
export function noAnnotationError(typeOrFunc, params) { | ||
var signature = []; | ||
for (var i = 0, ii = params.length; i < ii; i++) { | ||
var parameter = params[i]; | ||
if (!parameter || parameter.length == 0) { | ||
signature.push('?'); | ||
} | ||
else { | ||
signature.push(parameter.map(stringify).join(' ')); | ||
} | ||
} | ||
NoAnnotationError._genMessage = function (typeOrFunc, params) { | ||
var signature = []; | ||
for (var i = 0, ii = params.length; i < ii; i++) { | ||
var parameter = params[i]; | ||
if (!parameter || parameter.length == 0) { | ||
signature.push('?'); | ||
} | ||
else { | ||
signature.push(parameter.map(stringify).join(' ')); | ||
} | ||
} | ||
return 'Cannot resolve all parameters for \'' + stringify(typeOrFunc) + '\'(' + | ||
signature.join(', ') + '). ' + | ||
'Make sure that all the parameters are decorated with Inject or have valid type annotations and that \'' + | ||
stringify(typeOrFunc) + '\' is decorated with Injectable.'; | ||
}; | ||
return NoAnnotationError; | ||
}(BaseError)); | ||
return Error('Cannot resolve all parameters for \'' + stringify(typeOrFunc) + '\'(' + | ||
signature.join(', ') + '). ' + | ||
'Make sure that all the parameters are decorated with Inject or have valid type annotations and that \'' + | ||
stringify(typeOrFunc) + '\' is decorated with Injectable.'); | ||
} | ||
/** | ||
@@ -249,9 +197,5 @@ * Thrown when getting an object by index. | ||
*/ | ||
export var OutOfBoundsError = (function (_super) { | ||
__extends(OutOfBoundsError, _super); | ||
function OutOfBoundsError(index) { | ||
_super.call(this, "Index " + index + " is out-of-bounds."); | ||
} | ||
return OutOfBoundsError; | ||
}(BaseError)); | ||
export function outOfBoundsError(index) { | ||
return Error("Index " + index + " is out-of-bounds."); | ||
} | ||
// TODO: add a working example after alpha38 is released | ||
@@ -270,10 +214,5 @@ /** | ||
*/ | ||
export var MixingMultiProvidersWithRegularProvidersError = (function (_super) { | ||
__extends(MixingMultiProvidersWithRegularProvidersError, _super); | ||
function MixingMultiProvidersWithRegularProvidersError(provider1, provider2) { | ||
_super.call(this, 'Cannot mix multi providers and regular providers, got: ' + provider1.toString() + ' ' + | ||
provider2.toString()); | ||
} | ||
return MixingMultiProvidersWithRegularProvidersError; | ||
}(BaseError)); | ||
export function mixingMultiProvidersWithRegularProvidersError(provider1, provider2) { | ||
return Error("Cannot mix multi providers and regular providers, got: " + provider1 + " " + provider2); | ||
} | ||
//# sourceMappingURL=reflective_errors.js.map |
@@ -0,84 +1,11 @@ | ||
/** | ||
* @license | ||
* Copyright Google Inc. All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
import { Injector } from './injector'; | ||
import { Provider } from './provider'; | ||
import { ResolvedReflectiveProvider } from './reflective_provider'; | ||
export interface ReflectiveProtoInjectorStrategy { | ||
getProviderAtIndex(index: number): ResolvedReflectiveProvider; | ||
createInjectorStrategy(inj: ReflectiveInjector_): ReflectiveInjectorStrategy; | ||
} | ||
export declare class ReflectiveProtoInjectorInlineStrategy implements ReflectiveProtoInjectorStrategy { | ||
provider0: ResolvedReflectiveProvider; | ||
provider1: ResolvedReflectiveProvider; | ||
provider2: ResolvedReflectiveProvider; | ||
provider3: ResolvedReflectiveProvider; | ||
provider4: ResolvedReflectiveProvider; | ||
provider5: ResolvedReflectiveProvider; | ||
provider6: ResolvedReflectiveProvider; | ||
provider7: ResolvedReflectiveProvider; | ||
provider8: ResolvedReflectiveProvider; | ||
provider9: ResolvedReflectiveProvider; | ||
keyId0: number; | ||
keyId1: number; | ||
keyId2: number; | ||
keyId3: number; | ||
keyId4: number; | ||
keyId5: number; | ||
keyId6: number; | ||
keyId7: number; | ||
keyId8: number; | ||
keyId9: number; | ||
constructor(protoEI: ReflectiveProtoInjector, providers: ResolvedReflectiveProvider[]); | ||
getProviderAtIndex(index: number): ResolvedReflectiveProvider; | ||
createInjectorStrategy(injector: ReflectiveInjector_): ReflectiveInjectorStrategy; | ||
} | ||
export declare class ReflectiveProtoInjectorDynamicStrategy implements ReflectiveProtoInjectorStrategy { | ||
providers: ResolvedReflectiveProvider[]; | ||
keyIds: number[]; | ||
constructor(protoInj: ReflectiveProtoInjector, providers: ResolvedReflectiveProvider[]); | ||
getProviderAtIndex(index: number): ResolvedReflectiveProvider; | ||
createInjectorStrategy(ei: ReflectiveInjector_): ReflectiveInjectorStrategy; | ||
} | ||
export declare class ReflectiveProtoInjector { | ||
static fromResolvedProviders(providers: ResolvedReflectiveProvider[]): ReflectiveProtoInjector; | ||
numberOfProviders: number; | ||
constructor(providers: ResolvedReflectiveProvider[]); | ||
getProviderAtIndex(index: number): ResolvedReflectiveProvider; | ||
} | ||
export interface ReflectiveInjectorStrategy { | ||
getObjByKeyId(keyId: number): any; | ||
getObjAtIndex(index: number): any; | ||
getMaxNumberOfObjects(): number; | ||
resetConstructionCounter(): void; | ||
instantiateProvider(provider: ResolvedReflectiveProvider): any; | ||
} | ||
export declare class ReflectiveInjectorInlineStrategy implements ReflectiveInjectorStrategy { | ||
injector: ReflectiveInjector_; | ||
protoStrategy: ReflectiveProtoInjectorInlineStrategy; | ||
obj0: any; | ||
obj1: any; | ||
obj2: any; | ||
obj3: any; | ||
obj4: any; | ||
obj5: any; | ||
obj6: any; | ||
obj7: any; | ||
obj8: any; | ||
obj9: any; | ||
constructor(injector: ReflectiveInjector_, protoStrategy: ReflectiveProtoInjectorInlineStrategy); | ||
resetConstructionCounter(): void; | ||
instantiateProvider(provider: ResolvedReflectiveProvider): any; | ||
getObjByKeyId(keyId: number): any; | ||
getObjAtIndex(index: number): any; | ||
getMaxNumberOfObjects(): number; | ||
} | ||
export declare class ReflectiveInjectorDynamicStrategy implements ReflectiveInjectorStrategy { | ||
protoStrategy: ReflectiveProtoInjectorDynamicStrategy; | ||
injector: ReflectiveInjector_; | ||
objs: any[]; | ||
constructor(protoStrategy: ReflectiveProtoInjectorDynamicStrategy, injector: ReflectiveInjector_); | ||
resetConstructionCounter(): void; | ||
instantiateProvider(provider: ResolvedReflectiveProvider): any; | ||
getObjByKeyId(keyId: number): any; | ||
getObjAtIndex(index: number): any; | ||
getMaxNumberOfObjects(): number; | ||
} | ||
/** | ||
@@ -219,3 +146,3 @@ * A ReflectiveDependency injection container used for instantiating objects and resolving | ||
*/ | ||
readonly parent: Injector; | ||
readonly abstract parent: Injector; | ||
/** | ||
@@ -248,3 +175,3 @@ * Resolves an array of providers and creates a child injector from those providers. | ||
*/ | ||
resolveAndCreateChild(providers: Provider[]): ReflectiveInjector; | ||
abstract resolveAndCreateChild(providers: Provider[]): ReflectiveInjector; | ||
/** | ||
@@ -275,3 +202,3 @@ * Creates a child injector from previously resolved providers. | ||
*/ | ||
createChildFromResolved(providers: ResolvedReflectiveProvider[]): ReflectiveInjector; | ||
abstract createChildFromResolved(providers: ResolvedReflectiveProvider[]): ReflectiveInjector; | ||
/** | ||
@@ -301,3 +228,3 @@ * Resolves a provider and instantiates an object in the context of the injector. | ||
*/ | ||
resolveAndInstantiate(provider: Provider): any; | ||
abstract resolveAndInstantiate(provider: Provider): any; | ||
/** | ||
@@ -327,13 +254,13 @@ * Instantiates an object using a resolved provider in the context of the injector. | ||
*/ | ||
instantiateResolved(provider: ResolvedReflectiveProvider): any; | ||
abstract instantiateResolved(provider: ResolvedReflectiveProvider): any; | ||
abstract get(token: any, notFoundValue?: any): any; | ||
} | ||
export declare class ReflectiveInjector_ implements ReflectiveInjector { | ||
private _strategy; | ||
keyIds: number[]; | ||
objs: any[]; | ||
/** | ||
* Private | ||
*/ | ||
constructor(_proto: any, _parent?: Injector); | ||
constructor(_providers: ResolvedReflectiveProvider[], _parent?: Injector); | ||
get(token: any, notFoundValue?: any): any; | ||
getAt(index: number): any; | ||
readonly parent: Injector; | ||
@@ -344,8 +271,11 @@ resolveAndCreateChild(providers: Provider[]): ReflectiveInjector; | ||
instantiateResolved(provider: ResolvedReflectiveProvider): any; | ||
getProviderAtIndex(index: number): ResolvedReflectiveProvider; | ||
private _getMaxNumberOfObjects(); | ||
private _instantiateProvider(provider); | ||
private _instantiate(provider, ResolvedReflectiveFactory); | ||
private _getByReflectiveDependency(provider, dep); | ||
private _getByKey(key, lowerBoundVisibility, upperBoundVisibility, notFoundValue); | ||
private _getByReflectiveDependency(dep); | ||
private _getByKey(key, visibility, notFoundValue); | ||
private _getObjByKeyId(keyId); | ||
readonly displayName: string; | ||
toString(): string; | ||
} |
@@ -10,276 +10,7 @@ /** | ||
import { Self, SkipSelf } from './metadata'; | ||
import { AbstractProviderError, CyclicDependencyError, InstantiationError, NoProviderError, OutOfBoundsError } from './reflective_errors'; | ||
import { cyclicDependencyError, instantiationError, noProviderError, outOfBoundsError } from './reflective_errors'; | ||
import { ReflectiveKey } from './reflective_key'; | ||
import { resolveReflectiveProviders } from './reflective_provider'; | ||
// Threshold for the dynamic version | ||
var _MAX_CONSTRUCTION_COUNTER = 10; | ||
var UNDEFINED = new Object(); | ||
export var ReflectiveProtoInjectorInlineStrategy = (function () { | ||
function ReflectiveProtoInjectorInlineStrategy(protoEI, providers) { | ||
this.provider0 = null; | ||
this.provider1 = null; | ||
this.provider2 = null; | ||
this.provider3 = null; | ||
this.provider4 = null; | ||
this.provider5 = null; | ||
this.provider6 = null; | ||
this.provider7 = null; | ||
this.provider8 = null; | ||
this.provider9 = null; | ||
this.keyId0 = null; | ||
this.keyId1 = null; | ||
this.keyId2 = null; | ||
this.keyId3 = null; | ||
this.keyId4 = null; | ||
this.keyId5 = null; | ||
this.keyId6 = null; | ||
this.keyId7 = null; | ||
this.keyId8 = null; | ||
this.keyId9 = null; | ||
var length = providers.length; | ||
if (length > 0) { | ||
this.provider0 = providers[0]; | ||
this.keyId0 = providers[0].key.id; | ||
} | ||
if (length > 1) { | ||
this.provider1 = providers[1]; | ||
this.keyId1 = providers[1].key.id; | ||
} | ||
if (length > 2) { | ||
this.provider2 = providers[2]; | ||
this.keyId2 = providers[2].key.id; | ||
} | ||
if (length > 3) { | ||
this.provider3 = providers[3]; | ||
this.keyId3 = providers[3].key.id; | ||
} | ||
if (length > 4) { | ||
this.provider4 = providers[4]; | ||
this.keyId4 = providers[4].key.id; | ||
} | ||
if (length > 5) { | ||
this.provider5 = providers[5]; | ||
this.keyId5 = providers[5].key.id; | ||
} | ||
if (length > 6) { | ||
this.provider6 = providers[6]; | ||
this.keyId6 = providers[6].key.id; | ||
} | ||
if (length > 7) { | ||
this.provider7 = providers[7]; | ||
this.keyId7 = providers[7].key.id; | ||
} | ||
if (length > 8) { | ||
this.provider8 = providers[8]; | ||
this.keyId8 = providers[8].key.id; | ||
} | ||
if (length > 9) { | ||
this.provider9 = providers[9]; | ||
this.keyId9 = providers[9].key.id; | ||
} | ||
} | ||
ReflectiveProtoInjectorInlineStrategy.prototype.getProviderAtIndex = function (index) { | ||
if (index == 0) | ||
return this.provider0; | ||
if (index == 1) | ||
return this.provider1; | ||
if (index == 2) | ||
return this.provider2; | ||
if (index == 3) | ||
return this.provider3; | ||
if (index == 4) | ||
return this.provider4; | ||
if (index == 5) | ||
return this.provider5; | ||
if (index == 6) | ||
return this.provider6; | ||
if (index == 7) | ||
return this.provider7; | ||
if (index == 8) | ||
return this.provider8; | ||
if (index == 9) | ||
return this.provider9; | ||
throw new OutOfBoundsError(index); | ||
}; | ||
ReflectiveProtoInjectorInlineStrategy.prototype.createInjectorStrategy = function (injector) { | ||
return new ReflectiveInjectorInlineStrategy(injector, this); | ||
}; | ||
return ReflectiveProtoInjectorInlineStrategy; | ||
}()); | ||
export var ReflectiveProtoInjectorDynamicStrategy = (function () { | ||
function ReflectiveProtoInjectorDynamicStrategy(protoInj, providers) { | ||
this.providers = providers; | ||
var len = providers.length; | ||
this.keyIds = new Array(len); | ||
for (var i = 0; i < len; i++) { | ||
this.keyIds[i] = providers[i].key.id; | ||
} | ||
} | ||
ReflectiveProtoInjectorDynamicStrategy.prototype.getProviderAtIndex = function (index) { | ||
if (index < 0 || index >= this.providers.length) { | ||
throw new OutOfBoundsError(index); | ||
} | ||
return this.providers[index]; | ||
}; | ||
ReflectiveProtoInjectorDynamicStrategy.prototype.createInjectorStrategy = function (ei) { | ||
return new ReflectiveInjectorDynamicStrategy(this, ei); | ||
}; | ||
return ReflectiveProtoInjectorDynamicStrategy; | ||
}()); | ||
export var ReflectiveProtoInjector = (function () { | ||
function ReflectiveProtoInjector(providers) { | ||
this.numberOfProviders = providers.length; | ||
this._strategy = providers.length > _MAX_CONSTRUCTION_COUNTER ? | ||
new ReflectiveProtoInjectorDynamicStrategy(this, providers) : | ||
new ReflectiveProtoInjectorInlineStrategy(this, providers); | ||
} | ||
ReflectiveProtoInjector.fromResolvedProviders = function (providers) { | ||
return new ReflectiveProtoInjector(providers); | ||
}; | ||
ReflectiveProtoInjector.prototype.getProviderAtIndex = function (index) { | ||
return this._strategy.getProviderAtIndex(index); | ||
}; | ||
return ReflectiveProtoInjector; | ||
}()); | ||
export var ReflectiveInjectorInlineStrategy = (function () { | ||
function ReflectiveInjectorInlineStrategy(injector, protoStrategy) { | ||
this.injector = injector; | ||
this.protoStrategy = protoStrategy; | ||
this.obj0 = UNDEFINED; | ||
this.obj1 = UNDEFINED; | ||
this.obj2 = UNDEFINED; | ||
this.obj3 = UNDEFINED; | ||
this.obj4 = UNDEFINED; | ||
this.obj5 = UNDEFINED; | ||
this.obj6 = UNDEFINED; | ||
this.obj7 = UNDEFINED; | ||
this.obj8 = UNDEFINED; | ||
this.obj9 = UNDEFINED; | ||
} | ||
ReflectiveInjectorInlineStrategy.prototype.resetConstructionCounter = function () { this.injector._constructionCounter = 0; }; | ||
ReflectiveInjectorInlineStrategy.prototype.instantiateProvider = function (provider) { | ||
return this.injector._new(provider); | ||
}; | ||
ReflectiveInjectorInlineStrategy.prototype.getObjByKeyId = function (keyId) { | ||
var p = this.protoStrategy; | ||
var inj = this.injector; | ||
if (p.keyId0 === keyId) { | ||
if (this.obj0 === UNDEFINED) { | ||
this.obj0 = inj._new(p.provider0); | ||
} | ||
return this.obj0; | ||
} | ||
if (p.keyId1 === keyId) { | ||
if (this.obj1 === UNDEFINED) { | ||
this.obj1 = inj._new(p.provider1); | ||
} | ||
return this.obj1; | ||
} | ||
if (p.keyId2 === keyId) { | ||
if (this.obj2 === UNDEFINED) { | ||
this.obj2 = inj._new(p.provider2); | ||
} | ||
return this.obj2; | ||
} | ||
if (p.keyId3 === keyId) { | ||
if (this.obj3 === UNDEFINED) { | ||
this.obj3 = inj._new(p.provider3); | ||
} | ||
return this.obj3; | ||
} | ||
if (p.keyId4 === keyId) { | ||
if (this.obj4 === UNDEFINED) { | ||
this.obj4 = inj._new(p.provider4); | ||
} | ||
return this.obj4; | ||
} | ||
if (p.keyId5 === keyId) { | ||
if (this.obj5 === UNDEFINED) { | ||
this.obj5 = inj._new(p.provider5); | ||
} | ||
return this.obj5; | ||
} | ||
if (p.keyId6 === keyId) { | ||
if (this.obj6 === UNDEFINED) { | ||
this.obj6 = inj._new(p.provider6); | ||
} | ||
return this.obj6; | ||
} | ||
if (p.keyId7 === keyId) { | ||
if (this.obj7 === UNDEFINED) { | ||
this.obj7 = inj._new(p.provider7); | ||
} | ||
return this.obj7; | ||
} | ||
if (p.keyId8 === keyId) { | ||
if (this.obj8 === UNDEFINED) { | ||
this.obj8 = inj._new(p.provider8); | ||
} | ||
return this.obj8; | ||
} | ||
if (p.keyId9 === keyId) { | ||
if (this.obj9 === UNDEFINED) { | ||
this.obj9 = inj._new(p.provider9); | ||
} | ||
return this.obj9; | ||
} | ||
return UNDEFINED; | ||
}; | ||
ReflectiveInjectorInlineStrategy.prototype.getObjAtIndex = function (index) { | ||
if (index == 0) | ||
return this.obj0; | ||
if (index == 1) | ||
return this.obj1; | ||
if (index == 2) | ||
return this.obj2; | ||
if (index == 3) | ||
return this.obj3; | ||
if (index == 4) | ||
return this.obj4; | ||
if (index == 5) | ||
return this.obj5; | ||
if (index == 6) | ||
return this.obj6; | ||
if (index == 7) | ||
return this.obj7; | ||
if (index == 8) | ||
return this.obj8; | ||
if (index == 9) | ||
return this.obj9; | ||
throw new OutOfBoundsError(index); | ||
}; | ||
ReflectiveInjectorInlineStrategy.prototype.getMaxNumberOfObjects = function () { return _MAX_CONSTRUCTION_COUNTER; }; | ||
return ReflectiveInjectorInlineStrategy; | ||
}()); | ||
export var ReflectiveInjectorDynamicStrategy = (function () { | ||
function ReflectiveInjectorDynamicStrategy(protoStrategy, injector) { | ||
this.protoStrategy = protoStrategy; | ||
this.injector = injector; | ||
this.objs = new Array(protoStrategy.providers.length).fill(UNDEFINED); | ||
} | ||
ReflectiveInjectorDynamicStrategy.prototype.resetConstructionCounter = function () { this.injector._constructionCounter = 0; }; | ||
ReflectiveInjectorDynamicStrategy.prototype.instantiateProvider = function (provider) { | ||
return this.injector._new(provider); | ||
}; | ||
ReflectiveInjectorDynamicStrategy.prototype.getObjByKeyId = function (keyId) { | ||
var p = this.protoStrategy; | ||
for (var i = 0; i < p.keyIds.length; i++) { | ||
if (p.keyIds[i] === keyId) { | ||
if (this.objs[i] === UNDEFINED) { | ||
this.objs[i] = this.injector._new(p.providers[i]); | ||
} | ||
return this.objs[i]; | ||
} | ||
} | ||
return UNDEFINED; | ||
}; | ||
ReflectiveInjectorDynamicStrategy.prototype.getObjAtIndex = function (index) { | ||
if (index < 0 || index >= this.objs.length) { | ||
throw new OutOfBoundsError(index); | ||
} | ||
return this.objs[index]; | ||
}; | ||
ReflectiveInjectorDynamicStrategy.prototype.getMaxNumberOfObjects = function () { return this.objs.length; }; | ||
return ReflectiveInjectorDynamicStrategy; | ||
}()); | ||
/** | ||
@@ -415,3 +146,3 @@ * A ReflectiveDependency injection container used for instantiating objects and resolving | ||
if (parent === void 0) { parent = null; } | ||
return new ReflectiveInjector_(ReflectiveProtoInjector.fromResolvedProviders(providers), parent); | ||
return new ReflectiveInjector_(providers, parent); | ||
}; | ||
@@ -433,112 +164,6 @@ Object.defineProperty(ReflectiveInjector.prototype, "parent", { | ||
*/ | ||
get: function () { throw new Error('unimplemented'); }, | ||
get: function () { }, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
/** | ||
* Resolves an array of providers and creates a child injector from those providers. | ||
* | ||
* <!-- TODO: Add a link to the section of the user guide talking about hierarchical injection. | ||
* --> | ||
* | ||
* The passed-in providers can be an array of `Type`, {@link Provider}, | ||
* or a recursive array of more providers. | ||
* | ||
* ### Example ([live demo](http://plnkr.co/edit/opB3T4?p=preview)) | ||
* | ||
* ```typescript | ||
* class ParentProvider {} | ||
* class ChildProvider {} | ||
* | ||
* var parent = ReflectiveInjector.resolveAndCreate([ParentProvider]); | ||
* var child = parent.resolveAndCreateChild([ChildProvider]); | ||
* | ||
* expect(child.get(ParentProvider) instanceof ParentProvider).toBe(true); | ||
* expect(child.get(ChildProvider) instanceof ChildProvider).toBe(true); | ||
* expect(child.get(ParentProvider)).toBe(parent.get(ParentProvider)); | ||
* ``` | ||
* | ||
* This function is slower than the corresponding `createChildFromResolved` | ||
* because it needs to resolve the passed-in providers first. | ||
* See {@link Injector#resolve} and {@link Injector#createChildFromResolved}. | ||
*/ | ||
ReflectiveInjector.prototype.resolveAndCreateChild = function (providers) { throw new Error('unimplemented'); }; | ||
/** | ||
* Creates a child injector from previously resolved providers. | ||
* | ||
* <!-- TODO: Add a link to the section of the user guide talking about hierarchical injection. | ||
* --> | ||
* | ||
* This API is the recommended way to construct injectors in performance-sensitive parts. | ||
* | ||
* ### Example ([live demo](http://plnkr.co/edit/VhyfjN?p=preview)) | ||
* | ||
* ```typescript | ||
* class ParentProvider {} | ||
* class ChildProvider {} | ||
* | ||
* var parentProviders = ReflectiveInjector.resolve([ParentProvider]); | ||
* var childProviders = ReflectiveInjector.resolve([ChildProvider]); | ||
* | ||
* var parent = ReflectiveInjector.fromResolvedProviders(parentProviders); | ||
* var child = parent.createChildFromResolved(childProviders); | ||
* | ||
* expect(child.get(ParentProvider) instanceof ParentProvider).toBe(true); | ||
* expect(child.get(ChildProvider) instanceof ChildProvider).toBe(true); | ||
* expect(child.get(ParentProvider)).toBe(parent.get(ParentProvider)); | ||
* ``` | ||
*/ | ||
ReflectiveInjector.prototype.createChildFromResolved = function (providers) { | ||
throw new Error('unimplemented'); | ||
}; | ||
/** | ||
* Resolves a provider and instantiates an object in the context of the injector. | ||
* | ||
* The created object does not get cached by the injector. | ||
* | ||
* ### Example ([live demo](http://plnkr.co/edit/yvVXoB?p=preview)) | ||
* | ||
* ```typescript | ||
* @Injectable() | ||
* class Engine { | ||
* } | ||
* | ||
* @Injectable() | ||
* class Car { | ||
* constructor(public engine:Engine) {} | ||
* } | ||
* | ||
* var injector = ReflectiveInjector.resolveAndCreate([Engine]); | ||
* | ||
* var car = injector.resolveAndInstantiate(Car); | ||
* expect(car.engine).toBe(injector.get(Engine)); | ||
* expect(car).not.toBe(injector.resolveAndInstantiate(Car)); | ||
* ``` | ||
*/ | ||
ReflectiveInjector.prototype.resolveAndInstantiate = function (provider) { return new Error('unimplemented'); }; | ||
/** | ||
* Instantiates an object using a resolved provider in the context of the injector. | ||
* | ||
* The created object does not get cached by the injector. | ||
* | ||
* ### Example ([live demo](http://plnkr.co/edit/ptCImQ?p=preview)) | ||
* | ||
* ```typescript | ||
* @Injectable() | ||
* class Engine { | ||
* } | ||
* | ||
* @Injectable() | ||
* class Car { | ||
* constructor(public engine:Engine) {} | ||
* } | ||
* | ||
* var injector = ReflectiveInjector.resolveAndCreate([Engine]); | ||
* var carProvider = ReflectiveInjector.resolve([Car])[0]; | ||
* var car = injector.instantiateResolved(carProvider); | ||
* expect(car.engine).toBe(injector.get(Engine)); | ||
* expect(car).not.toBe(injector.instantiateResolved(carProvider)); | ||
* ``` | ||
*/ | ||
ReflectiveInjector.prototype.instantiateResolved = function (provider) { return new Error('unimplemented'); }; | ||
return ReflectiveInjector; | ||
@@ -550,15 +175,20 @@ }()); | ||
*/ | ||
function ReflectiveInjector_(_proto /* ProtoInjector */, _parent) { | ||
function ReflectiveInjector_(_providers, _parent) { | ||
if (_parent === void 0) { _parent = null; } | ||
/** @internal */ | ||
this._constructionCounter = 0; | ||
this._proto = _proto; | ||
this._providers = _providers; | ||
this._parent = _parent; | ||
this._strategy = _proto._strategy.createInjectorStrategy(this); | ||
var len = _providers.length; | ||
this.keyIds = new Array(len); | ||
this.objs = new Array(len); | ||
for (var i = 0; i < len; i++) { | ||
this.keyIds[i] = _providers[i].key.id; | ||
this.objs[i] = UNDEFINED; | ||
} | ||
} | ||
ReflectiveInjector_.prototype.get = function (token, notFoundValue) { | ||
if (notFoundValue === void 0) { notFoundValue = THROW_IF_NOT_FOUND; } | ||
return this._getByKey(ReflectiveKey.get(token), null, null, notFoundValue); | ||
return this._getByKey(ReflectiveKey.get(token), null, notFoundValue); | ||
}; | ||
ReflectiveInjector_.prototype.getAt = function (index) { return this._strategy.getObjAtIndex(index); }; | ||
Object.defineProperty(ReflectiveInjector_.prototype, "parent", { | ||
@@ -569,12 +199,2 @@ get: function () { return this._parent; }, | ||
}); | ||
Object.defineProperty(ReflectiveInjector_.prototype, "internalStrategy", { | ||
/** | ||
* @internal | ||
* Internal. Do not use. | ||
* We return `any` not to export the InjectorStrategy type. | ||
*/ | ||
get: function () { return this._strategy; }, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
ReflectiveInjector_.prototype.resolveAndCreateChild = function (providers) { | ||
@@ -585,4 +205,3 @@ var ResolvedReflectiveProviders = ReflectiveInjector.resolve(providers); | ||
ReflectiveInjector_.prototype.createChildFromResolved = function (providers) { | ||
var proto = new ReflectiveProtoInjector(providers); | ||
var inj = new ReflectiveInjector_(proto); | ||
var inj = new ReflectiveInjector_(providers); | ||
inj._parent = this; | ||
@@ -597,9 +216,16 @@ return inj; | ||
}; | ||
ReflectiveInjector_.prototype.getProviderAtIndex = function (index) { | ||
if (index < 0 || index >= this._providers.length) { | ||
throw outOfBoundsError(index); | ||
} | ||
return this._providers[index]; | ||
}; | ||
/** @internal */ | ||
ReflectiveInjector_.prototype._new = function (provider) { | ||
if (this._constructionCounter++ > this._strategy.getMaxNumberOfObjects()) { | ||
throw new CyclicDependencyError(this, provider.key); | ||
if (this._constructionCounter++ > this._getMaxNumberOfObjects()) { | ||
throw cyclicDependencyError(this, provider.key); | ||
} | ||
return this._instantiateProvider(provider); | ||
}; | ||
ReflectiveInjector_.prototype._getMaxNumberOfObjects = function () { return this.objs.length; }; | ||
ReflectiveInjector_.prototype._instantiateProvider = function (provider) { | ||
@@ -618,49 +244,11 @@ if (provider.multiProvider) { | ||
ReflectiveInjector_.prototype._instantiate = function (provider, ResolvedReflectiveFactory) { | ||
var _this = this; | ||
var factory = ResolvedReflectiveFactory.factory; | ||
var deps = ResolvedReflectiveFactory.dependencies; | ||
var length = deps.length; | ||
var d0; | ||
var d1; | ||
var d2; | ||
var d3; | ||
var d4; | ||
var d5; | ||
var d6; | ||
var d7; | ||
var d8; | ||
var d9; | ||
var d10; | ||
var d11; | ||
var d12; | ||
var d13; | ||
var d14; | ||
var d15; | ||
var d16; | ||
var d17; | ||
var d18; | ||
var d19; | ||
var deps; | ||
try { | ||
d0 = length > 0 ? this._getByReflectiveDependency(provider, deps[0]) : null; | ||
d1 = length > 1 ? this._getByReflectiveDependency(provider, deps[1]) : null; | ||
d2 = length > 2 ? this._getByReflectiveDependency(provider, deps[2]) : null; | ||
d3 = length > 3 ? this._getByReflectiveDependency(provider, deps[3]) : null; | ||
d4 = length > 4 ? this._getByReflectiveDependency(provider, deps[4]) : null; | ||
d5 = length > 5 ? this._getByReflectiveDependency(provider, deps[5]) : null; | ||
d6 = length > 6 ? this._getByReflectiveDependency(provider, deps[6]) : null; | ||
d7 = length > 7 ? this._getByReflectiveDependency(provider, deps[7]) : null; | ||
d8 = length > 8 ? this._getByReflectiveDependency(provider, deps[8]) : null; | ||
d9 = length > 9 ? this._getByReflectiveDependency(provider, deps[9]) : null; | ||
d10 = length > 10 ? this._getByReflectiveDependency(provider, deps[10]) : null; | ||
d11 = length > 11 ? this._getByReflectiveDependency(provider, deps[11]) : null; | ||
d12 = length > 12 ? this._getByReflectiveDependency(provider, deps[12]) : null; | ||
d13 = length > 13 ? this._getByReflectiveDependency(provider, deps[13]) : null; | ||
d14 = length > 14 ? this._getByReflectiveDependency(provider, deps[14]) : null; | ||
d15 = length > 15 ? this._getByReflectiveDependency(provider, deps[15]) : null; | ||
d16 = length > 16 ? this._getByReflectiveDependency(provider, deps[16]) : null; | ||
d17 = length > 17 ? this._getByReflectiveDependency(provider, deps[17]) : null; | ||
d18 = length > 18 ? this._getByReflectiveDependency(provider, deps[18]) : null; | ||
d19 = length > 19 ? this._getByReflectiveDependency(provider, deps[19]) : null; | ||
deps = | ||
ResolvedReflectiveFactory.dependencies.map(function (dep) { return _this._getByReflectiveDependency(dep); }); | ||
} | ||
catch (e) { | ||
if (e instanceof AbstractProviderError || e instanceof InstantiationError) { | ||
if (e.addKey) { | ||
e.addKey(this, provider.key); | ||
@@ -672,89 +260,34 @@ } | ||
try { | ||
switch (length) { | ||
case 0: | ||
obj = factory(); | ||
break; | ||
case 1: | ||
obj = factory(d0); | ||
break; | ||
case 2: | ||
obj = factory(d0, d1); | ||
break; | ||
case 3: | ||
obj = factory(d0, d1, d2); | ||
break; | ||
case 4: | ||
obj = factory(d0, d1, d2, d3); | ||
break; | ||
case 5: | ||
obj = factory(d0, d1, d2, d3, d4); | ||
break; | ||
case 6: | ||
obj = factory(d0, d1, d2, d3, d4, d5); | ||
break; | ||
case 7: | ||
obj = factory(d0, d1, d2, d3, d4, d5, d6); | ||
break; | ||
case 8: | ||
obj = factory(d0, d1, d2, d3, d4, d5, d6, d7); | ||
break; | ||
case 9: | ||
obj = factory(d0, d1, d2, d3, d4, d5, d6, d7, d8); | ||
break; | ||
case 10: | ||
obj = factory(d0, d1, d2, d3, d4, d5, d6, d7, d8, d9); | ||
break; | ||
case 11: | ||
obj = factory(d0, d1, d2, d3, d4, d5, d6, d7, d8, d9, d10); | ||
break; | ||
case 12: | ||
obj = factory(d0, d1, d2, d3, d4, d5, d6, d7, d8, d9, d10, d11); | ||
break; | ||
case 13: | ||
obj = factory(d0, d1, d2, d3, d4, d5, d6, d7, d8, d9, d10, d11, d12); | ||
break; | ||
case 14: | ||
obj = factory(d0, d1, d2, d3, d4, d5, d6, d7, d8, d9, d10, d11, d12, d13); | ||
break; | ||
case 15: | ||
obj = factory(d0, d1, d2, d3, d4, d5, d6, d7, d8, d9, d10, d11, d12, d13, d14); | ||
break; | ||
case 16: | ||
obj = factory(d0, d1, d2, d3, d4, d5, d6, d7, d8, d9, d10, d11, d12, d13, d14, d15); | ||
break; | ||
case 17: | ||
obj = factory(d0, d1, d2, d3, d4, d5, d6, d7, d8, d9, d10, d11, d12, d13, d14, d15, d16); | ||
break; | ||
case 18: | ||
obj = factory(d0, d1, d2, d3, d4, d5, d6, d7, d8, d9, d10, d11, d12, d13, d14, d15, d16, d17); | ||
break; | ||
case 19: | ||
obj = factory(d0, d1, d2, d3, d4, d5, d6, d7, d8, d9, d10, d11, d12, d13, d14, d15, d16, d17, d18); | ||
break; | ||
case 20: | ||
obj = factory(d0, d1, d2, d3, d4, d5, d6, d7, d8, d9, d10, d11, d12, d13, d14, d15, d16, d17, d18, d19); | ||
break; | ||
default: | ||
throw new Error("Cannot instantiate '" + provider.key.displayName + "' because it has more than 20 dependencies"); | ||
} | ||
obj = factory.apply(void 0, deps); | ||
} | ||
catch (e) { | ||
throw new InstantiationError(this, e, e.stack, provider.key); | ||
throw instantiationError(this, e, e.stack, provider.key); | ||
} | ||
return obj; | ||
}; | ||
ReflectiveInjector_.prototype._getByReflectiveDependency = function (provider, dep) { | ||
return this._getByKey(dep.key, dep.lowerBoundVisibility, dep.upperBoundVisibility, dep.optional ? null : THROW_IF_NOT_FOUND); | ||
ReflectiveInjector_.prototype._getByReflectiveDependency = function (dep) { | ||
return this._getByKey(dep.key, dep.visibility, dep.optional ? null : THROW_IF_NOT_FOUND); | ||
}; | ||
ReflectiveInjector_.prototype._getByKey = function (key, lowerBoundVisibility, upperBoundVisibility, notFoundValue) { | ||
ReflectiveInjector_.prototype._getByKey = function (key, visibility, notFoundValue) { | ||
if (key === INJECTOR_KEY) { | ||
return this; | ||
} | ||
if (upperBoundVisibility instanceof Self) { | ||
if (visibility instanceof Self) { | ||
return this._getByKeySelf(key, notFoundValue); | ||
} | ||
else { | ||
return this._getByKeyDefault(key, notFoundValue, lowerBoundVisibility); | ||
return this._getByKeyDefault(key, notFoundValue, visibility); | ||
} | ||
}; | ||
ReflectiveInjector_.prototype._getObjByKeyId = function (keyId) { | ||
for (var i = 0; i < this.keyIds.length; i++) { | ||
if (this.keyIds[i] === keyId) { | ||
if (this.objs[i] === UNDEFINED) { | ||
this.objs[i] = this._new(this._providers[i]); | ||
} | ||
return this.objs[i]; | ||
} | ||
} | ||
return UNDEFINED; | ||
}; | ||
/** @internal */ | ||
@@ -766,3 +299,3 @@ ReflectiveInjector_.prototype._throwOrNull = function (key, notFoundValue) { | ||
else { | ||
throw new NoProviderError(this, key); | ||
throw noProviderError(this, key); | ||
} | ||
@@ -772,9 +305,9 @@ }; | ||
ReflectiveInjector_.prototype._getByKeySelf = function (key, notFoundValue) { | ||
var obj = this._strategy.getObjByKeyId(key.id); | ||
var obj = this._getObjByKeyId(key.id); | ||
return (obj !== UNDEFINED) ? obj : this._throwOrNull(key, notFoundValue); | ||
}; | ||
/** @internal */ | ||
ReflectiveInjector_.prototype._getByKeyDefault = function (key, notFoundValue, lowerBoundVisibility) { | ||
ReflectiveInjector_.prototype._getByKeyDefault = function (key, notFoundValue, visibility) { | ||
var inj; | ||
if (lowerBoundVisibility instanceof SkipSelf) { | ||
if (visibility instanceof SkipSelf) { | ||
inj = this._parent; | ||
@@ -787,3 +320,3 @@ } | ||
var inj_ = inj; | ||
var obj = inj_._strategy.getObjByKeyId(key.id); | ||
var obj = inj_._getObjByKeyId(key.id); | ||
if (obj !== UNDEFINED) | ||
@@ -814,5 +347,5 @@ return obj; | ||
function _mapProviders(injector, fn) { | ||
var res = new Array(injector._proto.numberOfProviders); | ||
for (var i = 0; i < injector._proto.numberOfProviders; ++i) { | ||
res[i] = fn(injector._proto.getProviderAtIndex(i)); | ||
var res = new Array(injector._providers.length); | ||
for (var i = 0; i < injector._providers.length; ++i) { | ||
res[i] = fn(injector.getProviderAtIndex(i)); | ||
} | ||
@@ -819,0 +352,0 @@ return res; |
@@ -0,1 +1,2 @@ | ||
import { Self, SkipSelf } from './metadata'; | ||
import { Provider } from './provider'; | ||
@@ -10,6 +11,4 @@ import { ReflectiveKey } from './reflective_key'; | ||
optional: boolean; | ||
lowerBoundVisibility: any; | ||
upperBoundVisibility: any; | ||
properties: any[]; | ||
constructor(key: ReflectiveKey, optional: boolean, lowerBoundVisibility: any, upperBoundVisibility: any, properties: any[]); | ||
visibility: Self | SkipSelf; | ||
constructor(key: ReflectiveKey, optional: boolean, visibility: Self | SkipSelf); | ||
static fromKey(key: ReflectiveKey): ReflectiveDependency; | ||
@@ -16,0 +15,0 @@ } |
@@ -11,4 +11,5 @@ /** | ||
import { resolveForwardRef } from './forward_ref'; | ||
import { Host, Inject, Optional, Self, SkipSelf } from './metadata'; | ||
import { InvalidProviderError, MixingMultiProvidersWithRegularProvidersError, NoAnnotationError } from './reflective_errors'; | ||
import { InjectionToken } from './injection_token'; | ||
import { Inject, Optional, Self, SkipSelf } from './metadata'; | ||
import { invalidProviderError, mixingMultiProvidersWithRegularProvidersError, noAnnotationError } from './reflective_errors'; | ||
import { ReflectiveKey } from './reflective_key'; | ||
@@ -20,11 +21,9 @@ /** | ||
export var ReflectiveDependency = (function () { | ||
function ReflectiveDependency(key, optional, lowerBoundVisibility, upperBoundVisibility, properties) { | ||
function ReflectiveDependency(key, optional, visibility) { | ||
this.key = key; | ||
this.optional = optional; | ||
this.lowerBoundVisibility = lowerBoundVisibility; | ||
this.upperBoundVisibility = upperBoundVisibility; | ||
this.properties = properties; | ||
this.visibility = visibility; | ||
} | ||
ReflectiveDependency.fromKey = function (key) { | ||
return new ReflectiveDependency(key, false, null, null, []); | ||
return new ReflectiveDependency(key, false, null); | ||
}; | ||
@@ -121,3 +120,3 @@ return ReflectiveDependency; | ||
if (provider.multiProvider !== existing.multiProvider) { | ||
throw new MixingMultiProvidersWithRegularProvidersError(existing, provider); | ||
throw mixingMultiProvidersWithRegularProvidersError(existing, provider); | ||
} | ||
@@ -158,3 +157,3 @@ if (provider.multiProvider) { | ||
else { | ||
throw new InvalidProviderError(b); | ||
throw invalidProviderError(b); | ||
} | ||
@@ -178,3 +177,3 @@ }); | ||
if (params.some(function (p) { return p == null; })) { | ||
throw new NoAnnotationError(typeOrFunc, params); | ||
throw noAnnotationError(typeOrFunc, params); | ||
} | ||
@@ -184,3 +183,2 @@ return params.map(function (p) { return _extractToken(typeOrFunc, p, params); }); | ||
function _extractToken(typeOrFunc, metadata, params) { | ||
var depProps = []; | ||
var token = null; | ||
@@ -190,10 +188,9 @@ var optional = false; | ||
if (metadata instanceof Inject) { | ||
return _createDependency(metadata.token, optional, null, null, depProps); | ||
return _createDependency(metadata['token'], optional, null); | ||
} | ||
else { | ||
return _createDependency(metadata, optional, null, null, depProps); | ||
return _createDependency(metadata, optional, null); | ||
} | ||
} | ||
var lowerBoundVisibility = null; | ||
var upperBoundVisibility = null; | ||
var visibility = null; | ||
for (var i = 0; i < metadata.length; ++i) { | ||
@@ -205,3 +202,3 @@ var paramMetadata = metadata[i]; | ||
else if (paramMetadata instanceof Inject) { | ||
token = paramMetadata.token; | ||
token = paramMetadata['token']; | ||
} | ||
@@ -211,23 +208,20 @@ else if (paramMetadata instanceof Optional) { | ||
} | ||
else if (paramMetadata instanceof Self) { | ||
upperBoundVisibility = paramMetadata; | ||
else if (paramMetadata instanceof Self || paramMetadata instanceof SkipSelf) { | ||
visibility = paramMetadata; | ||
} | ||
else if (paramMetadata instanceof Host) { | ||
upperBoundVisibility = paramMetadata; | ||
else if (paramMetadata instanceof InjectionToken) { | ||
token = paramMetadata; | ||
} | ||
else if (paramMetadata instanceof SkipSelf) { | ||
lowerBoundVisibility = paramMetadata; | ||
} | ||
} | ||
token = resolveForwardRef(token); | ||
if (token != null) { | ||
return _createDependency(token, optional, lowerBoundVisibility, upperBoundVisibility, depProps); | ||
return _createDependency(token, optional, visibility); | ||
} | ||
else { | ||
throw new NoAnnotationError(typeOrFunc, params); | ||
throw noAnnotationError(typeOrFunc, params); | ||
} | ||
} | ||
function _createDependency(token, optional, lowerBoundVisibility, upperBoundVisibility, depProps) { | ||
return new ReflectiveDependency(ReflectiveKey.get(token), optional, lowerBoundVisibility, upperBoundVisibility, depProps); | ||
function _createDependency(token, optional, visibility) { | ||
return new ReflectiveDependency(ReflectiveKey.get(token), optional, visibility); | ||
} | ||
//# sourceMappingURL=reflective_provider.js.map |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
216186
5017
2