refactor(injector): add bool and int annotations

This commit is contained in:
vsavkin 2014-10-07 09:37:45 -04:00
parent 971e31fcd3
commit df09a7c817
4 changed files with 10 additions and 9 deletions

View File

@ -1,10 +1,10 @@
import {Type} from 'facade/lang'; import {Type, bool} from 'facade/lang';
import {List, MapWrapper, ListWrapper} from 'facade/collection'; import {List, MapWrapper, ListWrapper} from 'facade/collection';
import {Reflector} from './reflector'; import {Reflector} from './reflector';
import {Key, Dependency} from './key'; import {Key, Dependency} from './key';
export class Binding { export class Binding {
constructor(key:Key, factory:Function, dependencies:List, providedAsFuture) { constructor(key:Key, factory:Function, dependencies:List, providedAsFuture:bool) {
this.key = key; this.key = key;
this.factory = factory; this.factory = factory;
this.dependencies = dependencies; this.dependencies = dependencies;

View File

@ -2,7 +2,7 @@ import {Map, List, MapWrapper, ListWrapper} from 'facade/collection';
import {Binding, BindingBuilder, bind} from './binding'; import {Binding, BindingBuilder, bind} from './binding';
import {ProviderError, NoProviderError, InvalidBindingError, import {ProviderError, NoProviderError, InvalidBindingError,
AsyncBindingError, CyclicDependencyError, InstantiationError} from './exceptions'; AsyncBindingError, CyclicDependencyError, InstantiationError} from './exceptions';
import {Type, isPresent, isBlank} from 'facade/lang'; import {Type, isPresent, isBlank, bool} from 'facade/lang';
import {Future, FutureWrapper} from 'facade/async'; import {Future, FutureWrapper} from 'facade/async';
import {Key} from './key'; import {Key} from './key';
@ -13,7 +13,7 @@ class _Waiting {
this.future = future; this.future = future;
} }
} }
function _isWaiting(obj) { function _isWaiting(obj):bool {
return obj instanceof _Waiting; return obj instanceof _Waiting;
} }
@ -62,7 +62,7 @@ export class Injector {
return ListWrapper.createFixedSize(Key.numberOfKeys() + 1); return ListWrapper.createFixedSize(Key.numberOfKeys() + 1);
} }
_getByKey(key:Key, returnFuture, returnLazy) { _getByKey(key:Key, returnFuture:bool, returnLazy:bool) {
if (returnLazy) { if (returnLazy) {
return () => this._getByKey(key, returnFuture, false); return () => this._getByKey(key, returnFuture, false);
} }

View File

@ -1,11 +1,12 @@
import {MapWrapper} from 'facade/collection'; import {MapWrapper} from 'facade/collection';
import {int, bool} from 'facade/lang';
var _allKeys = {}; var _allKeys = {};
var _id = 0; var _id:int = 0;
//TODO: vsavkin: move to binding once cyclic deps are supported //TODO: vsavkin: move to binding once cyclic deps are supported
export class Dependency { export class Dependency {
constructor(key:Key, asFuture, lazy){ constructor(key:Key, asFuture:bool, lazy:bool){
this.key = key; this.key = key;
this.asFuture = asFuture; this.asFuture = asFuture;
this.lazy = lazy; this.lazy = lazy;
@ -13,7 +14,7 @@ export class Dependency {
} }
export class Key { export class Key {
constructor(token, id) { constructor(token, id:int) {
this.token = token; this.token = token;
this.id = id; this.id = id;
} }

View File

@ -38,7 +38,7 @@ export class Reflector {
} }
if (isPresent(type)) { if (isPresent(type)) {
return this._createDependency(type, false); return this._createDependency(type, false, false);
} else { } else {
throw new NoAnnotationError(constructedType); throw new NoAnnotationError(constructedType);
} }