chore(typing): extract abstract superclasses to replace @private constructors
This commit is contained in:
@ -255,29 +255,31 @@ export class Binding {
|
||||
* expect(injector.get('message')).toEqual('Hello');
|
||||
* ```
|
||||
*/
|
||||
export class ResolvedBinding {
|
||||
export abstract class ResolvedBinding {
|
||||
/**
|
||||
* @internal
|
||||
* A key, usually a `Type`.
|
||||
*/
|
||||
constructor(
|
||||
/**
|
||||
* A key, usually a `Type`.
|
||||
*/
|
||||
public key: Key,
|
||||
public key: Key;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* Factory function which can return an instance of an object represented by a key.
|
||||
*/
|
||||
public resolvedFactories: ResolvedFactory[],
|
||||
/**
|
||||
* Factory function which can return an instance of an object represented by a key.
|
||||
*/
|
||||
public resolvedFactories: ResolvedFactory[];
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* Indicates if the binding is a multi-binding or a regular binding.
|
||||
*/
|
||||
public multiBinding: boolean) {}
|
||||
/**
|
||||
* Indicates if the binding is a multi-binding or a regular binding.
|
||||
*/
|
||||
public multiBinding: boolean;
|
||||
}
|
||||
|
||||
export class ResolvedBinding_ extends ResolvedBinding {
|
||||
constructor(key: Key, resolvedFactories: ResolvedFactory[], multiBinding: boolean) {
|
||||
super();
|
||||
this.key = key;
|
||||
this.resolvedFactories = resolvedFactories;
|
||||
this.multiBinding = multiBinding;
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
get resolvedFactory(): ResolvedFactory { return this.resolvedFactories[0]; }
|
||||
}
|
||||
|
||||
@ -463,7 +465,7 @@ export function resolveFactory(binding: Binding): ResolvedFactory {
|
||||
* convenience binding syntax.
|
||||
*/
|
||||
export function resolveBinding(binding: Binding): ResolvedBinding {
|
||||
return new ResolvedBinding(Key.get(binding.token), [resolveFactory(binding)], false);
|
||||
return new ResolvedBinding_(Key.get(binding.token), [resolveFactory(binding)], false);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -474,11 +476,11 @@ export function resolveBindings(bindings: Array<Type | Binding | any[]>): Resolv
|
||||
_normalizeBindings(bindings, new Map<number, _NormalizedBinding | _NormalizedBinding[]>()));
|
||||
return normalized.map(b => {
|
||||
if (b instanceof _NormalizedBinding) {
|
||||
return new ResolvedBinding(b.key, [b.resolvedFactory], false);
|
||||
return new ResolvedBinding_(b.key, [b.resolvedFactory], false);
|
||||
|
||||
} else {
|
||||
var arr = <_NormalizedBinding[]>b;
|
||||
return new ResolvedBinding(arr[0].key, arr.map(_ => _.resolvedFactory), true);
|
||||
return new ResolvedBinding_(arr[0].key, arr.map(_ => _.resolvedFactory), true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
import {ListWrapper} from 'angular2/src/core/facade/collection';
|
||||
import {stringify, isBlank} from 'angular2/src/core/facade/lang';
|
||||
import {BaseException, WrappedException} from 'angular2/src/core/facade/exceptions';
|
||||
import {BaseException, WrappedException, unimplemented} from 'angular2/src/core/facade/exceptions';
|
||||
import {Key} from './key';
|
||||
import {Injector} from './injector';
|
||||
|
||||
@ -134,14 +134,20 @@ export class CyclicDependencyError extends AbstractBindingError {
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
export class InstantiationError extends WrappedException {
|
||||
export abstract class InstantiationError extends WrappedException {
|
||||
abstract addKey(injector: Injector, key: Key): void;
|
||||
get wrapperMessage(): string { return unimplemented(); };
|
||||
get causeKey(): Key { return unimplemented(); };
|
||||
get context() { return unimplemented(); };
|
||||
}
|
||||
|
||||
export class InstantiationError_ extends InstantiationError {
|
||||
/** @internal */
|
||||
keys: Key[];
|
||||
|
||||
/** @internal */
|
||||
injectors: Injector[];
|
||||
|
||||
/** @internal */
|
||||
constructor(injector: Injector, originalException, originalStack, key: Key) {
|
||||
super("DI Exception", originalException, originalStack, null);
|
||||
this.keys = [key];
|
||||
|
@ -13,6 +13,7 @@ import {
|
||||
NoBindingError,
|
||||
CyclicDependencyError,
|
||||
InstantiationError,
|
||||
InstantiationError_,
|
||||
InvalidBindingError,
|
||||
OutOfBoundsError,
|
||||
MixingMultiBindingsWithRegularBindings
|
||||
@ -865,7 +866,7 @@ export class Injector {
|
||||
break;
|
||||
}
|
||||
} catch (e) {
|
||||
throw new InstantiationError(this, e, e.stack, binding.key);
|
||||
throw new InstantiationError_(this, e, e.stack, binding.key);
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
Reference in New Issue
Block a user