Skip to content

Commit ffd1ac4

Browse files
committed
style(DI): idiomatic TS
1 parent edd0161 commit ffd1ac4

File tree

5 files changed

+13
-19
lines changed

5 files changed

+13
-19
lines changed

modules/angular2/src/di/annotations_impl.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {CONST, stringify} from "angular2/src/facade/lang";
1515
@CONST()
1616
export class Inject {
1717
constructor(public token) {}
18-
toString() { return `@Inject(${stringify(this.token)})`; }
18+
toString(): string { return `@Inject(${stringify(this.token)})`; }
1919
}
2020

2121
/**
@@ -34,7 +34,7 @@ export class Inject {
3434
@CONST()
3535
export class InjectPromise {
3636
constructor(public token) {}
37-
toString() { return `@InjectPromise(${stringify(this.token)})`; }
37+
toString(): string { return `@InjectPromise(${stringify(this.token)})`; }
3838
}
3939

4040
/**
@@ -53,7 +53,7 @@ export class InjectPromise {
5353
@CONST()
5454
export class InjectLazy {
5555
constructor(public token) {}
56-
toString() { return `@InjectLazy(${stringify(this.token)})`; }
56+
toString(): string { return `@InjectLazy(${stringify(this.token)})`; }
5757
}
5858

5959
/**
@@ -72,7 +72,7 @@ export class InjectLazy {
7272
*/
7373
@CONST()
7474
export class Optional {
75-
toString() { return `@Optional()`; }
75+
toString(): string { return `@Optional()`; }
7676
}
7777

7878
/**

modules/angular2/src/di/binding.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
isBlank,
44
isPresent,
55
CONST,
6+
CONST_EXPR,
67
BaseException,
78
stringify,
89
isArray
@@ -30,7 +31,7 @@ export class Dependency {
3031
static fromKey(key: Key) { return new Dependency(key, false, false, false, []); }
3132
}
3233

33-
var _EMPTY_LIST = []; // TODO: make const when supported
34+
const _EMPTY_LIST = CONST_EXPR([]);
3435

3536
/**
3637
* Describes how the {@link Injector} should instantiate a given token.

modules/angular2/src/di/exceptions.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ export class CyclicDependencyError extends AbstractBindingError {
140140
export class InstantiationError extends AbstractBindingError {
141141
cause;
142142
causeKey;
143+
143144
// TODO(tbosch): Can't do key:Key as this results in a circular dependency!
144145
constructor(cause, key) {
145146
super(key, function(keys: List<any>) {

modules/angular2/src/di/forward_ref.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {Type, stringify} from 'angular2/src/facade/lang';
1+
import {Type, stringify, isFunction} from 'angular2/src/facade/lang';
22

33
export interface ForwardRefFn { (): any; }
44

@@ -42,7 +42,7 @@ export function forwardRef(forwardRefFn: ForwardRefFn): Type {
4242
* @exportedAs angular2/di
4343
*/
4444
export function resolveForwardRef(type: any): any {
45-
if (typeof type == 'function' && type.hasOwnProperty('__forward_ref__') &&
45+
if (isFunction(type) && type.hasOwnProperty('__forward_ref__') &&
4646
type.__forward_ref__ === forwardRef) {
4747
return (<ForwardRefFn>type)();
4848
} else {

modules/angular2/src/di/key.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ import {resolveForwardRef} from './forward_ref';
55

66
export {TypeLiteral} from './type_literal';
77

8-
// TODO: uncoment `int` once https://github.com/angular/angular/issues/1414 is fixed
9-
108
/**
119
* A unique object used for retrieving items from the {@link Injector}.
1210
*
@@ -20,21 +18,16 @@ export {TypeLiteral} from './type_literal';
2018
* @exportedAs angular2/di
2119
*/
2220
export class Key {
23-
token: Object;
24-
id: number;
25-
2621
/**
2722
* @private
2823
*/
29-
constructor(token: Object, id: number) {
24+
constructor(public token: Object, public id: number) {
3025
if (isBlank(token)) {
3126
throw new BaseException('Token must be defined!');
3227
}
33-
this.token = token;
34-
this.id = id;
3528
}
3629

37-
get displayName() { return stringify(this.token); }
30+
get displayName(): string { return stringify(this.token); }
3831

3932
/**
4033
* Retrieves a `Key` for a token.
@@ -51,8 +44,7 @@ export class Key {
5144
* @private
5245
*/
5346
export class KeyRegistry {
54-
_allKeys: Map<Object, Key>;
55-
constructor() { this._allKeys = MapWrapper.create(); }
47+
private _allKeys: Map<Object, Key> = MapWrapper.create();
5648

5749
get(token: Object): Key {
5850
if (token instanceof Key) return token;
@@ -73,7 +65,7 @@ export class KeyRegistry {
7365
return newKey;
7466
}
7567

76-
get numberOfKeys() /* :int */ { return MapWrapper.size(this._allKeys); }
68+
get numberOfKeys(): number { return MapWrapper.size(this._allKeys); }
7769
}
7870

7971
var _globalKeyRegistry = new KeyRegistry();

0 commit comments

Comments
 (0)