refactor(Injector): use TS iodioms

This commit is contained in:
Victor Berchet 2015-05-29 15:10:49 +02:00
parent e93b5a1d5b
commit 921fb9f2ce
1 changed files with 9 additions and 14 deletions

View File

@ -10,18 +10,18 @@ import {
InstantiationError, InstantiationError,
InvalidBindingError InvalidBindingError
} from './exceptions'; } from './exceptions';
import {FunctionWrapper, Type, isPresent, isBlank} from 'angular2/src/facade/lang'; import {FunctionWrapper, Type, isPresent, isBlank, CONST_EXPR} from 'angular2/src/facade/lang';
import {PromiseWrapper, Promise} from 'angular2/src/facade/async'; import {PromiseWrapper, Promise} from 'angular2/src/facade/async';
import {Key} from './key'; import {Key} from './key';
import {resolveForwardRef} from './forward_ref'; import {resolveForwardRef} from './forward_ref';
var _constructing = new Object(); const _constructing = CONST_EXPR(new Object());
var _notFound = new Object(); const _notFound = CONST_EXPR(new Object());
class _Waiting { class _Waiting {
promise: Promise<any>; constructor(public promise: Promise<any>) {}
constructor(promise: Promise<any>) { this.promise = promise; }
} }
function _isWaiting(obj): boolean { function _isWaiting(obj): boolean {
return obj instanceof _Waiting; return obj instanceof _Waiting;
} }
@ -67,10 +67,7 @@ function _isWaiting(obj): boolean {
* @exportedAs angular2/di * @exportedAs angular2/di
*/ */
export class Injector { export class Injector {
private _bindings: List<ResolvedBinding>;
private _instances: List<any>; private _instances: List<any>;
private _parent: Injector;
private _defaultBindings: boolean;
private _asyncStrategy: _AsyncInjectorStrategy; private _asyncStrategy: _AsyncInjectorStrategy;
private _syncStrategy: _SyncInjectorStrategy; private _syncStrategy: _SyncInjectorStrategy;
@ -134,11 +131,9 @@ export class Injector {
* @param `defaultBindings` Setting to true will auto-create bindings. (Only use with root * @param `defaultBindings` Setting to true will auto-create bindings. (Only use with root
* injector.) * injector.)
*/ */
constructor(bindings: List<ResolvedBinding>, parent: Injector, defaultBindings: boolean) { constructor(private _bindings: List<ResolvedBinding>, private _parent: Injector,
this._bindings = bindings; private _defaultBindings: boolean) {
this._instances = this._createInstances(); this._instances = this._createInstances();
this._parent = parent;
this._defaultBindings = defaultBindings;
this._asyncStrategy = new _AsyncInjectorStrategy(this); this._asyncStrategy = new _AsyncInjectorStrategy(this);
this._syncStrategy = new _SyncInjectorStrategy(this); this._syncStrategy = new _SyncInjectorStrategy(this);
} }
@ -266,7 +261,7 @@ interface _InjectorStrategy {
} }
class _SyncInjectorStrategy implements _InjectorStrategy { class _SyncInjectorStrategy implements _InjectorStrategy {
constructor(private _injector: Injector) { } constructor(private _injector: Injector) {}
readFromCache(key: Key) { readFromCache(key: Key) {
if (key.token === Injector) { if (key.token === Injector) {
@ -310,7 +305,7 @@ class _SyncInjectorStrategy implements _InjectorStrategy {
} }
class _AsyncInjectorStrategy implements _InjectorStrategy { class _AsyncInjectorStrategy implements _InjectorStrategy {
constructor(private _injector: Injector) { } constructor(private _injector: Injector) {}
readFromCache(key: Key) { readFromCache(key: Key) {
if (key.token === Injector) { if (key.token === Injector) {