style(DI): idiomatic TS
This commit is contained in:
parent
edd01615c3
commit
ffd1ac425e
|
@ -15,7 +15,7 @@ import {CONST, stringify} from "angular2/src/facade/lang";
|
||||||
@CONST()
|
@CONST()
|
||||||
export class Inject {
|
export class Inject {
|
||||||
constructor(public token) {}
|
constructor(public token) {}
|
||||||
toString() { return `@Inject(${stringify(this.token)})`; }
|
toString(): string { return `@Inject(${stringify(this.token)})`; }
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -34,7 +34,7 @@ export class Inject {
|
||||||
@CONST()
|
@CONST()
|
||||||
export class InjectPromise {
|
export class InjectPromise {
|
||||||
constructor(public token) {}
|
constructor(public token) {}
|
||||||
toString() { return `@InjectPromise(${stringify(this.token)})`; }
|
toString(): string { return `@InjectPromise(${stringify(this.token)})`; }
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -53,7 +53,7 @@ export class InjectPromise {
|
||||||
@CONST()
|
@CONST()
|
||||||
export class InjectLazy {
|
export class InjectLazy {
|
||||||
constructor(public token) {}
|
constructor(public token) {}
|
||||||
toString() { return `@InjectLazy(${stringify(this.token)})`; }
|
toString(): string { return `@InjectLazy(${stringify(this.token)})`; }
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -72,7 +72,7 @@ export class InjectLazy {
|
||||||
*/
|
*/
|
||||||
@CONST()
|
@CONST()
|
||||||
export class Optional {
|
export class Optional {
|
||||||
toString() { return `@Optional()`; }
|
toString(): string { return `@Optional()`; }
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -3,6 +3,7 @@ import {
|
||||||
isBlank,
|
isBlank,
|
||||||
isPresent,
|
isPresent,
|
||||||
CONST,
|
CONST,
|
||||||
|
CONST_EXPR,
|
||||||
BaseException,
|
BaseException,
|
||||||
stringify,
|
stringify,
|
||||||
isArray
|
isArray
|
||||||
|
@ -30,7 +31,7 @@ export class Dependency {
|
||||||
static fromKey(key: Key) { return new Dependency(key, false, false, false, []); }
|
static fromKey(key: Key) { return new Dependency(key, false, false, false, []); }
|
||||||
}
|
}
|
||||||
|
|
||||||
var _EMPTY_LIST = []; // TODO: make const when supported
|
const _EMPTY_LIST = CONST_EXPR([]);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Describes how the {@link Injector} should instantiate a given token.
|
* Describes how the {@link Injector} should instantiate a given token.
|
||||||
|
|
|
@ -140,6 +140,7 @@ export class CyclicDependencyError extends AbstractBindingError {
|
||||||
export class InstantiationError extends AbstractBindingError {
|
export class InstantiationError extends AbstractBindingError {
|
||||||
cause;
|
cause;
|
||||||
causeKey;
|
causeKey;
|
||||||
|
|
||||||
// TODO(tbosch): Can't do key:Key as this results in a circular dependency!
|
// TODO(tbosch): Can't do key:Key as this results in a circular dependency!
|
||||||
constructor(cause, key) {
|
constructor(cause, key) {
|
||||||
super(key, function(keys: List<any>) {
|
super(key, function(keys: List<any>) {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import {Type, stringify} from 'angular2/src/facade/lang';
|
import {Type, stringify, isFunction} from 'angular2/src/facade/lang';
|
||||||
|
|
||||||
export interface ForwardRefFn { (): any; }
|
export interface ForwardRefFn { (): any; }
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ export function forwardRef(forwardRefFn: ForwardRefFn): Type {
|
||||||
* @exportedAs angular2/di
|
* @exportedAs angular2/di
|
||||||
*/
|
*/
|
||||||
export function resolveForwardRef(type: any): any {
|
export function resolveForwardRef(type: any): any {
|
||||||
if (typeof type == 'function' && type.hasOwnProperty('__forward_ref__') &&
|
if (isFunction(type) && type.hasOwnProperty('__forward_ref__') &&
|
||||||
type.__forward_ref__ === forwardRef) {
|
type.__forward_ref__ === forwardRef) {
|
||||||
return (<ForwardRefFn>type)();
|
return (<ForwardRefFn>type)();
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -5,8 +5,6 @@ import {resolveForwardRef} from './forward_ref';
|
||||||
|
|
||||||
export {TypeLiteral} from './type_literal';
|
export {TypeLiteral} from './type_literal';
|
||||||
|
|
||||||
// TODO: uncoment `int` once https://github.com/angular/angular/issues/1414 is fixed
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A unique object used for retrieving items from the {@link Injector}.
|
* A unique object used for retrieving items from the {@link Injector}.
|
||||||
*
|
*
|
||||||
|
@ -20,21 +18,16 @@ export {TypeLiteral} from './type_literal';
|
||||||
* @exportedAs angular2/di
|
* @exportedAs angular2/di
|
||||||
*/
|
*/
|
||||||
export class Key {
|
export class Key {
|
||||||
token: Object;
|
|
||||||
id: number;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
constructor(token: Object, id: number) {
|
constructor(public token: Object, public id: number) {
|
||||||
if (isBlank(token)) {
|
if (isBlank(token)) {
|
||||||
throw new BaseException('Token must be defined!');
|
throw new BaseException('Token must be defined!');
|
||||||
}
|
}
|
||||||
this.token = token;
|
|
||||||
this.id = id;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get displayName() { return stringify(this.token); }
|
get displayName(): string { return stringify(this.token); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves a `Key` for a token.
|
* Retrieves a `Key` for a token.
|
||||||
|
@ -51,8 +44,7 @@ export class Key {
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
export class KeyRegistry {
|
export class KeyRegistry {
|
||||||
_allKeys: Map<Object, Key>;
|
private _allKeys: Map<Object, Key> = MapWrapper.create();
|
||||||
constructor() { this._allKeys = MapWrapper.create(); }
|
|
||||||
|
|
||||||
get(token: Object): Key {
|
get(token: Object): Key {
|
||||||
if (token instanceof Key) return token;
|
if (token instanceof Key) return token;
|
||||||
|
@ -73,7 +65,7 @@ export class KeyRegistry {
|
||||||
return newKey;
|
return newKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
get numberOfKeys() /* :int */ { return MapWrapper.size(this._allKeys); }
|
get numberOfKeys(): number { return MapWrapper.size(this._allKeys); }
|
||||||
}
|
}
|
||||||
|
|
||||||
var _globalKeyRegistry = new KeyRegistry();
|
var _globalKeyRegistry = new KeyRegistry();
|
||||||
|
|
Loading…
Reference in New Issue