refactor(core): removed getter and changed to readonly variable (#19117)

PR Close #19117
This commit is contained in:
Yuan Gao
2017-09-08 18:06:33 -07:00
committed by Igor Minar
parent 549f2254b4
commit b14c2d1568
9 changed files with 62 additions and 77 deletions

View File

@ -29,10 +29,10 @@
* @stable
*/
export class InjectionToken<T> {
/** @internal */
readonly ngMetadataName = 'InjectionToken';
constructor(protected _desc: string) {}
toString(): string { return `InjectionToken ${this._desc}`; }
/** @internal */
get ngMetadataName() { return 'InjectionToken'; }
}

View File

@ -282,8 +282,7 @@ export class ReflectiveInjector_ implements ReflectiveInjector {
_constructionCounter: number = 0;
/** @internal */
public _providers: ResolvedReflectiveProvider[];
/** @internal */
public _parent: Injector|null;
public readonly parent: Injector|null;
keyIds: number[];
objs: any[];
@ -292,7 +291,7 @@ export class ReflectiveInjector_ implements ReflectiveInjector {
*/
constructor(_providers: ResolvedReflectiveProvider[], _parent?: Injector) {
this._providers = _providers;
this._parent = _parent || null;
this.parent = _parent || null;
const len = _providers.length;
@ -309,8 +308,6 @@ export class ReflectiveInjector_ implements ReflectiveInjector {
return this._getByKey(ReflectiveKey.get(token), null, notFoundValue);
}
get parent(): Injector|null { return this._parent; }
resolveAndCreateChild(providers: Provider[]): ReflectiveInjector {
const ResolvedReflectiveProviders = ReflectiveInjector.resolve(providers);
return this.createChildFromResolved(ResolvedReflectiveProviders);
@ -318,7 +315,7 @@ export class ReflectiveInjector_ implements ReflectiveInjector {
createChildFromResolved(providers: ResolvedReflectiveProvider[]): ReflectiveInjector {
const inj = new ReflectiveInjector_(providers);
inj._parent = this;
(inj as{parent: Injector | null}).parent = this;
return inj;
}
@ -436,7 +433,7 @@ export class ReflectiveInjector_ implements ReflectiveInjector {
let inj: Injector|null;
if (visibility instanceof SkipSelf) {
inj = this._parent;
inj = this.parent;
} else {
inj = this;
}
@ -445,7 +442,7 @@ export class ReflectiveInjector_ implements ReflectiveInjector {
const inj_ = <ReflectiveInjector_>inj;
const obj = inj_._getObjByKeyId(key.id);
if (obj !== UNDEFINED) return obj;
inj = inj_._parent;
inj = inj_.parent;
}
if (inj !== null) {
return inj.get(key.token, notFoundValue);

View File

@ -27,6 +27,7 @@ import {resolveForwardRef} from './forward_ref';
* @deprecated No replacement
*/
export class ReflectiveKey {
public readonly displayName: string;
/**
* Private
*/
@ -34,13 +35,9 @@ export class ReflectiveKey {
if (!token) {
throw new Error('Token must be defined!');
}
this.displayName = stringify(this.token);
}
/**
* Returns a stringified token.
*/
get displayName(): string { return stringify(this.token); }
/**
* Retrieves a `Key` for a token.
*/