diff --git a/packages/core/src/application_init.ts b/packages/core/src/application_init.ts index b801ab26b4..554c120d9d 100644 --- a/packages/core/src/application_init.ts +++ b/packages/core/src/application_init.ts @@ -27,11 +27,11 @@ export class ApplicationInitStatus { private resolve: Function; private reject: Function; private initialized = false; - private _donePromise: Promise; - private _done = false; + public readonly donePromise: Promise; + public readonly done = false; constructor(@Inject(APP_INITIALIZER) @Optional() private appInits: (() => any)[]) { - this._donePromise = new Promise((res, rej) => { + this.donePromise = new Promise((res, rej) => { this.resolve = res; this.reject = rej; }); @@ -46,7 +46,7 @@ export class ApplicationInitStatus { const asyncInitPromises: Promise[] = []; const complete = () => { - this._done = true; + (this as{done: boolean}).done = true; this.resolve(); }; @@ -66,8 +66,4 @@ export class ApplicationInitStatus { } this.initialized = true; } - - get done(): boolean { return this._done; } - - get donePromise(): Promise { return this._donePromise; } } diff --git a/packages/core/src/application_ref.ts b/packages/core/src/application_ref.ts index 8f131e8857..b024bfb626 100644 --- a/packages/core/src/application_ref.ts +++ b/packages/core/src/application_ref.ts @@ -335,14 +335,27 @@ export class ApplicationRef { /** @internal */ static _tickScope: WtfScopeFn = wtfCreateScope('ApplicationRef#tick()'); private _bootstrapListeners: ((compRef: ComponentRef) => void)[] = []; - private _rootComponents: ComponentRef[] = []; - private _rootComponentTypes: Type[] = []; private _views: InternalViewRef[] = []; private _runningTick: boolean = false; private _enforceNoNewChanges: boolean = false; - private _isStable: Observable; private _stable = true; + /** + * Get a list of component types registered to this application. + * This list is populated even before the component is created. + */ + public readonly componentTypes: Type[] = []; + + /** + * Get a list of components registered to this application. + */ + public readonly components: ComponentRef[] = []; + + /** + * Returns an Observable that indicates when the application is stable or unstable. + */ + public readonly isStable: Observable; + /** @internal */ constructor( private _zone: NgZone, private _console: Console, private _injector: Injector, @@ -397,7 +410,8 @@ export class ApplicationRef { }; }); - this._isStable = merge(isCurrentlyStable, share.call(isStable)); + (this as{isStable: Observable}).isStable = + merge(isCurrentlyStable, share.call(isStable)); } /** @@ -428,7 +442,7 @@ export class ApplicationRef { componentFactory = this._componentFactoryResolver.resolveComponentFactory(componentOrFactory) !; } - this._rootComponentTypes.push(componentFactory.componentType); + this.componentTypes.push(componentFactory.componentType); // Create a factory associated with the current module if it's not bound to some other const ngModule = componentFactory instanceof ComponentFactoryBoundToModule ? @@ -483,17 +497,6 @@ export class ApplicationRef { } } - /** - * Get a list of component types registered to this application. - * This list is populated even before the component is created. - */ - get componentTypes(): Type[] { return this._rootComponentTypes; } - - /** - * Get a list of components registered to this application. - */ - get components(): ComponentRef[] { return this._rootComponents; } - /** * Attaches a view so that it will be dirty checked. * The view will be automatically detached when it is destroyed. @@ -517,7 +520,7 @@ export class ApplicationRef { private _loadComponent(componentRef: ComponentRef): void { this.attachView(componentRef.hostView); this.tick(); - this._rootComponents.push(componentRef); + this.components.push(componentRef); // Get the listeners lazily to prevent DI cycles. const listeners = this._injector.get(APP_BOOTSTRAP_LISTENER, []).concat(this._bootstrapListeners); @@ -526,7 +529,7 @@ export class ApplicationRef { private _unloadComponent(componentRef: ComponentRef): void { this.detachView(componentRef.hostView); - remove(this._rootComponents, componentRef); + remove(this.components, componentRef); } /** @internal */ @@ -539,11 +542,6 @@ export class ApplicationRef { * Returns the number of attached views. */ get viewCount() { return this._views.length; } - - /** - * Returns an Observable that indicates when the application is stable or unstable. - */ - get isStable(): Observable { return this._isStable; } } function remove(list: T[], el: T): void { diff --git a/packages/core/src/change_detection/differs/default_iterable_differ.ts b/packages/core/src/change_detection/differs/default_iterable_differ.ts index b74c7a7a13..dc2c08ec18 100644 --- a/packages/core/src/change_detection/differs/default_iterable_differ.ts +++ b/packages/core/src/change_detection/differs/default_iterable_differ.ts @@ -26,8 +26,8 @@ const trackByIdentity = (index: number, item: any) => item; * @deprecated v4.0.0 - Should not be part of public API. */ export class DefaultIterableDiffer implements IterableDiffer, IterableChanges { - private _length: number = 0; - private _collection: NgIterable|null = null; + public readonly length: number = 0; + public readonly collection: V[]|Iterable|null; // Keeps track of the used records at any point in time (during & across `_check()` calls) private _linkedRecords: _DuplicateMap|null = null; // Keeps track of the removed records at any point in time during `_check()` calls. @@ -48,10 +48,6 @@ export class DefaultIterableDiffer implements IterableDiffer, IterableChan constructor(trackByFn?: TrackByFunction) { this._trackByFn = trackByFn || trackByIdentity; } - get collection() { return this._collection; } - - get length(): number { return this._length; } - forEachItem(fn: (record: IterableChangeRecord_) => void) { let record: IterableChangeRecord_|null; for (record = this._itHead; record !== null; record = record._next) { @@ -171,9 +167,9 @@ export class DefaultIterableDiffer implements IterableDiffer, IterableChan let item: V; let itemTrackBy: any; if (Array.isArray(collection)) { - this._length = collection.length; + (this as{length: number}).length = collection.length; - for (let index = 0; index < this._length; index++) { + for (let index = 0; index < this.length; index++) { item = collection[index]; itemTrackBy = this._trackByFn(index, item); if (record === null || !looseIdentical(record.trackById, itemTrackBy)) { @@ -206,11 +202,11 @@ export class DefaultIterableDiffer implements IterableDiffer, IterableChan record = record._next; index++; }); - this._length = index; + (this as{length: number}).length = index; } this._truncate(record); - this._collection = collection; + (this as{collection: V[] | Iterable}).collection = collection; return this.isDirty; } diff --git a/packages/core/src/di/injection_token.ts b/packages/core/src/di/injection_token.ts index 5d9b8327b3..9fd360fa62 100644 --- a/packages/core/src/di/injection_token.ts +++ b/packages/core/src/di/injection_token.ts @@ -29,10 +29,10 @@ * @stable */ export class InjectionToken { + /** @internal */ + readonly ngMetadataName = 'InjectionToken'; + constructor(protected _desc: string) {} toString(): string { return `InjectionToken ${this._desc}`; } - - /** @internal */ - get ngMetadataName() { return 'InjectionToken'; } } diff --git a/packages/core/src/di/reflective_injector.ts b/packages/core/src/di/reflective_injector.ts index 6b7f4c47d0..1d4999fd1c 100644 --- a/packages/core/src/di/reflective_injector.ts +++ b/packages/core/src/di/reflective_injector.ts @@ -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_ = 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); diff --git a/packages/core/src/di/reflective_key.ts b/packages/core/src/di/reflective_key.ts index 765f3fded6..bc51fcb649 100644 --- a/packages/core/src/di/reflective_key.ts +++ b/packages/core/src/di/reflective_key.ts @@ -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. */ diff --git a/packages/core/src/linker/query_list.ts b/packages/core/src/linker/query_list.ts index 8dae2c824f..34fc10d5b2 100644 --- a/packages/core/src/linker/query_list.ts +++ b/packages/core/src/linker/query_list.ts @@ -37,11 +37,10 @@ import {getSymbolIterator} from '../util'; * @stable */ export class QueryList/* implements Iterable */ { - private _dirty = true; + public readonly dirty = true; private _results: Array = []; - private _emitter = new EventEmitter(); + public readonly changes: Observable = new EventEmitter(); - get changes(): Observable { return this._emitter; } get length(): number { return this._results.length; } get first(): T { return this._results[0]; } get last(): T { return this._results[this.length - 1]; } @@ -98,21 +97,18 @@ export class QueryList/* implements Iterable */ { reset(res: Array): void { this._results = flatten(res); - this._dirty = false; + (this as{dirty: boolean}).dirty = false; } - notifyOnChanges(): void { this._emitter.emit(this); } + notifyOnChanges(): void { (this.changes as EventEmitter).emit(this); } /** internal */ - setDirty() { this._dirty = true; } - - /** internal */ - get dirty() { return this._dirty; } + setDirty() { (this as{dirty: boolean}).dirty = true; } /** internal */ destroy(): void { - this._emitter.complete(); - this._emitter.unsubscribe(); + (this.changes as EventEmitter).complete(); + (this.changes as EventEmitter).unsubscribe(); } } diff --git a/packages/core/src/version.ts b/packages/core/src/version.ts index 3a662a849c..0d5b462866 100644 --- a/packages/core/src/version.ts +++ b/packages/core/src/version.ts @@ -12,13 +12,15 @@ * @stable */ export class Version { - constructor(public full: string) {} + public readonly major: string; + public readonly minor: string; + public readonly patch: string; - get major(): string { return this.full.split('.')[0]; } - - get minor(): string { return this.full.split('.')[1]; } - - get patch(): string { return this.full.split('.').slice(2).join('.'); } + constructor(public full: string) { + this.major = full.split('.')[0]; + this.minor = full.split('.')[1]; + this.patch = full.split('.').slice(2).join('.'); + } } /** diff --git a/packages/core/src/view/refs.ts b/packages/core/src/view/refs.ts index bb9040f601..df2f6bfa8b 100644 --- a/packages/core/src/view/refs.ts +++ b/packages/core/src/view/refs.ts @@ -101,18 +101,21 @@ class ComponentFactory_ extends ComponentFactory { } class ComponentRef_ extends ComponentRef { + public readonly hostView: ViewRef; + public readonly instance: any; + public readonly changeDetectorRef: ChangeDetectorRef; private _elDef: NodeDef; constructor(private _view: ViewData, private _viewRef: ViewRef, private _component: any) { super(); this._elDef = this._view.def.nodes[0]; + this.hostView = _viewRef; + this.changeDetectorRef = _viewRef; + this.instance = _component; } get location(): ElementRef { return new ElementRef(asElementData(this._view, this._elDef.index).renderElement); } get injector(): Injector { return new Injector_(this._view, this._elDef); } - get instance(): any { return this._component; }; - get hostView(): ViewRef { return this._viewRef; }; - get changeDetectorRef(): ChangeDetectorRef { return this._viewRef; }; get componentType(): Type { return this._component.constructor; } destroy(): void { this._viewRef.destroy(); }