From 3d53b333919c81b292cb0f4b3e338a686f5a6a85 Mon Sep 17 00:00:00 2001 From: Tobias Bosch Date: Tue, 2 Aug 2016 07:54:14 -0700 Subject: [PATCH] chore: update public api and integrate minor review comments --- .../src/view_compiler/lifecycle_binder.ts | 4 +- modules/@angular/core/index.ts | 2 +- modules/@angular/core/src/application_init.ts | 2 +- .../@angular/core/src/application_module.ts | 4 +- modules/@angular/core/src/application_ref.ts | 12 +++--- .../@angular/core/src/application_tokens.ts | 5 ++- .../core/src/linker/ng_module_factory.ts | 2 +- .../@angular/core/src/metadata/ng_module.ts | 4 +- .../core/test/application_init_spec.ts | 12 +++--- .../test/linker/ng_module_integration_spec.ts | 2 +- .../@angular/router-deprecated/src/router.ts | 3 -- modules/@angular/router/src/router.ts | 3 -- tools/public_api_guard/core/index.d.ts | 40 ++++++++++++++----- tools/public_api_guard/core/testing.d.ts | 3 ++ tools/public_api_guard/router/index.d.ts | 2 +- tools/public_api_guard/upgrade/index.d.ts | 2 +- 16 files changed, 61 insertions(+), 41 deletions(-) diff --git a/modules/@angular/compiler/src/view_compiler/lifecycle_binder.ts b/modules/@angular/compiler/src/view_compiler/lifecycle_binder.ts index af1c2b5104..2b59655f17 100644 --- a/modules/@angular/compiler/src/view_compiler/lifecycle_binder.ts +++ b/modules/@angular/compiler/src/view_compiler/lifecycle_binder.ts @@ -78,11 +78,11 @@ export function bindDirectiveAfterViewLifecycleCallbacks( } export function bindInjectableDestroyLifecycleCallbacks( - provider: ProviderAst, directiveInstance: o.Expression, compileElement: CompileElement) { + provider: ProviderAst, providerInstance: o.Expression, compileElement: CompileElement) { var onDestroyMethod = compileElement.view.destroyMethod; onDestroyMethod.resetDebugInfo(compileElement.nodeIndex, compileElement.sourceAst); if (provider.lifecycleHooks.indexOf(LifecycleHooks.OnDestroy) !== -1) { - onDestroyMethod.addStmt(directiveInstance.callMethod('ngOnDestroy', []).toStmt()); + onDestroyMethod.addStmt(providerInstance.callMethod('ngOnDestroy', []).toStmt()); } } diff --git a/modules/@angular/core/index.ts b/modules/@angular/core/index.ts index 301cfbbea6..7e44261010 100644 --- a/modules/@angular/core/index.ts +++ b/modules/@angular/core/index.ts @@ -16,7 +16,7 @@ export * from './src/util'; export * from './src/di'; export {createPlatform, assertPlatform, disposePlatform, getPlatform, coreBootstrap, coreLoadAndBootstrap, PlatformRef, ApplicationRef, enableProdMode, lockRunMode, isDevMode, createPlatformFactory} from './src/application_ref'; export {APP_ID, PACKAGE_ROOT_URL, PLATFORM_INITIALIZER, APP_BOOTSTRAP_LISTENER} from './src/application_tokens'; -export {APP_INITIALIZER, AppInitStatus} from './src/application_init'; +export {APP_INITIALIZER, ApplicationInitStatus} from './src/application_init'; export * from './src/zone'; export * from './src/render'; export * from './src/linker'; diff --git a/modules/@angular/core/src/application_init.ts b/modules/@angular/core/src/application_init.ts index 547017c604..e7c27af6ee 100644 --- a/modules/@angular/core/src/application_init.ts +++ b/modules/@angular/core/src/application_init.ts @@ -23,7 +23,7 @@ export const APP_INITIALIZER: any = new OpaqueToken('Application Initializer'); * @experimental */ @Injectable() -export class AppInitStatus { +export class ApplicationInitStatus { private _donePromise: Promise; private _done = false; diff --git a/modules/@angular/core/src/application_module.ts b/modules/@angular/core/src/application_module.ts index b102c1c2e4..bb7d148538 100644 --- a/modules/@angular/core/src/application_module.ts +++ b/modules/@angular/core/src/application_module.ts @@ -8,7 +8,7 @@ import {Type} from '../src/facade/lang'; -import {AppInitStatus} from './application_init'; +import {ApplicationInitStatus} from './application_init'; import {ApplicationRef, ApplicationRef_, isDevMode} from './application_ref'; import {APP_ID_RANDOM_PROVIDER} from './application_tokens'; import {IterableDiffers, KeyValueDiffers, defaultIterableDiffers, defaultKeyValueDiffers} from './change_detection/change_detection'; @@ -45,7 +45,7 @@ export const APPLICATION_COMMON_PROVIDERS: Array providers: [ ApplicationRef_, {provide: ApplicationRef, useExisting: ApplicationRef_}, - AppInitStatus, + ApplicationInitStatus, Compiler, {provide: ComponentResolver, useExisting: Compiler}, APP_ID_RANDOM_PROVIDER, diff --git a/modules/@angular/core/src/application_ref.ts b/modules/@angular/core/src/application_ref.ts index 9b75ed78bf..605f86fb1d 100644 --- a/modules/@angular/core/src/application_ref.ts +++ b/modules/@angular/core/src/application_ref.ts @@ -11,7 +11,7 @@ import {ListWrapper} from '../src/facade/collection'; import {BaseException, ExceptionHandler, unimplemented} from '../src/facade/exceptions'; import {ConcreteType, Type, isBlank, isPresent, isPromise, stringify} from '../src/facade/lang'; -import {AppInitStatus} from './application_init'; +import {ApplicationInitStatus} from './application_init'; import {APP_BOOTSTRAP_LISTENER, PLATFORM_INITIALIZER} from './application_tokens'; import {ChangeDetectorRef} from './change_detection/change_detector_ref'; import {Console} from './console'; @@ -275,7 +275,7 @@ export abstract class PlatformRef { abstract destroy(): void; /** - * @deprecated Use `destroyd` instead + * @deprecated Use `destroyed` instead */ get disposed(): boolean { throw unimplemented(); } get destroyed(): boolean { throw unimplemented(); } @@ -327,7 +327,7 @@ export class PlatformRef_ extends PlatformRef { destroy() { if (this._destroyed) { - throw new BaseException('The platform is already destroyed!'); + throw new BaseException('The platform has already been destroyed!'); } ListWrapper.clone(this._modules).forEach((app) => app.destroy()); this._destroyListeners.forEach((dispose) => dispose()); @@ -360,7 +360,7 @@ export class PlatformRef_ extends PlatformRef { exceptionHandler.call(error.error, error.stackTrace); }); return _callAndReportToExceptionHandler(exceptionHandler, () => { - const initStatus: AppInitStatus = moduleRef.injector.get(AppInitStatus); + const initStatus: ApplicationInitStatus = moduleRef.injector.get(ApplicationInitStatus); return initStatus.donePromise.then(() => { this._moduleDoBootstrap(moduleRef); return moduleRef; @@ -421,7 +421,7 @@ export abstract class ApplicationRef { * Returns a promise that resolves when all asynchronous application initializers * are done. * - * @deprecated Use the {@link AppInitStatus} class instead. + * @deprecated Use the {@link ApplicationInitStatus} class instead. */ abstract waitForAsyncInitializers(): Promise; @@ -514,7 +514,7 @@ export class ApplicationRef_ extends ApplicationRef { private _zone: NgZone, private _console: Console, private _injector: Injector, private _exceptionHandler: ExceptionHandler, private _componentFactoryResolver: ComponentFactoryResolver, - private _initStatus: AppInitStatus, + private _initStatus: ApplicationInitStatus, @Optional() private _testabilityRegistry: TestabilityRegistry, @Optional() private _testability: Testability) { super(); diff --git a/modules/@angular/core/src/application_tokens.ts b/modules/@angular/core/src/application_tokens.ts index 9992d81818..8b8a0f5ac9 100644 --- a/modules/@angular/core/src/application_tokens.ts +++ b/modules/@angular/core/src/application_tokens.ts @@ -48,7 +48,10 @@ function _randomChar(): string { export const PLATFORM_INITIALIZER: any = new OpaqueToken('Platform Initializer'); /** - * All callbacks provided via this token will be called when a component has been bootstrapped. + * All callbacks provided via this token will be called for every component that is bootstrapped. + * Signature of the callback: + * + * `(componentRef: ComponentRef) => void`. * * @experimental */ diff --git a/modules/@angular/core/src/linker/ng_module_factory.ts b/modules/@angular/core/src/linker/ng_module_factory.ts index fc08933fcd..c6a18ede85 100644 --- a/modules/@angular/core/src/linker/ng_module_factory.ts +++ b/modules/@angular/core/src/linker/ng_module_factory.ts @@ -108,7 +108,7 @@ export abstract class NgModuleInjector extends CodegenComponentFactoryResolve destroy(): void { if (this._destroyed) { throw new BaseException( - `This module is already destroyed (${stringify(this.instance.constructor)})`); + `The ng module ${stringify(this.instance.constructor)} has already been destroyed.`); } this._destroyed = true; this.destroyInternal(); diff --git a/modules/@angular/core/src/metadata/ng_module.ts b/modules/@angular/core/src/metadata/ng_module.ts index 744d52adc7..077fe264f1 100644 --- a/modules/@angular/core/src/metadata/ng_module.ts +++ b/modules/@angular/core/src/metadata/ng_module.ts @@ -150,9 +150,9 @@ export class NgModuleMetadata extends InjectableMetadata implements NgModuleMeta * this module is bootstrapped. The components listed here * will automatically be added to `entryComponents`. */ - bootstrap: Array + bootstrap: Array; - schemas: Array; + schemas: Array; constructor(options: NgModuleMetadataType = {}) { // We cannot use destructuring of the constructor argument because `exports` is a diff --git a/modules/@angular/core/test/application_init_spec.ts b/modules/@angular/core/test/application_init_spec.ts index c86a768476..7f5e615741 100644 --- a/modules/@angular/core/test/application_init_spec.ts +++ b/modules/@angular/core/test/application_init_spec.ts @@ -5,19 +5,21 @@ * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ -import {APP_INITIALIZER, AppInitStatus} from '../src/application_init'; +import {APP_INITIALIZER, ApplicationInitStatus} from '../src/application_init'; import {PromiseCompleter, PromiseWrapper} from '../src/facade/async'; import {TestBed, async, inject, withModule} from '../testing'; export function main() { - describe('AppInitStatus', () => { + describe('ApplicationInitStatus', () => { describe('no initializers', () => { it('should return true for `done`', - inject([AppInitStatus], (status: AppInitStatus) => { expect(status.done).toBe(true); })); + inject([ApplicationInitStatus], (status: ApplicationInitStatus) => { + expect(status.done).toBe(true); + })); it('should return a promise that resolves immediately for `donePromise`', - async(inject([AppInitStatus], (status: AppInitStatus) => { + async(inject([ApplicationInitStatus], (status: ApplicationInitStatus) => { status.donePromise.then(() => { expect(status.done).toBe(true); }); }))); }); @@ -32,7 +34,7 @@ export function main() { }); it('should updat the status once all async initializers are done', - async(inject([AppInitStatus], (status: AppInitStatus) => { + async(inject([ApplicationInitStatus], (status: ApplicationInitStatus) => { let completerResolver = false; setTimeout(() => { completerResolver = true; diff --git a/modules/@angular/core/test/linker/ng_module_integration_spec.ts b/modules/@angular/core/test/linker/ng_module_integration_spec.ts index b03ae13fc3..b9b1ebf4ab 100644 --- a/modules/@angular/core/test/linker/ng_module_integration_spec.ts +++ b/modules/@angular/core/test/linker/ng_module_integration_spec.ts @@ -311,7 +311,7 @@ function declareTests({useJit}: {useJit: boolean}) { .toBe(SomeComp); }); - it('should crate ComponentFactories in imported modules', () => { + it('should create ComponentFactories in imported modules', () => { @NgModule({declarations: [SomeComp], entryComponents: [SomeComp]}) class SomeImportedModule { } diff --git a/modules/@angular/router-deprecated/src/router.ts b/modules/@angular/router-deprecated/src/router.ts index fc0ce6750d..8c315574b4 100644 --- a/modules/@angular/router-deprecated/src/router.ts +++ b/modules/@angular/router-deprecated/src/router.ts @@ -548,9 +548,6 @@ export class RootRouter extends Router { return promise; } - /** - * @internal - */ ngOnDestroy() { this.dispose(); } dispose(): void { diff --git a/modules/@angular/router/src/router.ts b/modules/@angular/router/src/router.ts index 20d266d8cb..9ca2f6d37f 100644 --- a/modules/@angular/router/src/router.ts +++ b/modules/@angular/router/src/router.ts @@ -196,9 +196,6 @@ export class Router { this.config = config; } - /** - * @internal - */ ngOnDestroy() { this.dispose(); } /** diff --git a/tools/public_api_guard/core/index.d.ts b/tools/public_api_guard/core/index.d.ts index 7c70f042dd..f1c11707a0 100644 --- a/tools/public_api_guard/core/index.d.ts +++ b/tools/public_api_guard/core/index.d.ts @@ -118,6 +118,9 @@ export declare abstract class AnimationWithStepsMetadata extends AnimationMetada constructor(); } +/** @experimental */ +export declare const APP_BOOTSTRAP_LISTENER: OpaqueToken; + /** @experimental */ export declare const APP_ID: any; @@ -129,6 +132,13 @@ export declare const APPLICATION_COMMON_PROVIDERS: Array; +/** @experimental */ +export declare class ApplicationInitStatus { + done: boolean; + donePromise: Promise; + constructor(appInits: (() => any)[]); +} + /** @experimental */ export declare class ApplicationModule { } @@ -136,15 +146,16 @@ export declare class ApplicationModule { /** @experimental */ export declare abstract class ApplicationRef { componentTypes: Type[]; - injector: Injector; - zone: NgZone; + components: ComponentRef[]; + /** @deprecated */ injector: Injector; + /** @deprecated */ zone: NgZone; abstract bootstrap(componentFactory: ComponentFactory | ConcreteType): ComponentRef; - abstract dispose(): void; - abstract registerBootstrapListener(listener: (ref: ComponentRef) => void): void; - abstract registerDisposeListener(dispose: () => void): void; - abstract run(callback: Function): any; + /** @deprecated */ abstract dispose(): void; + /** @deprecated */ abstract registerBootstrapListener(listener: (ref: ComponentRef) => void): void; + /** @deprecated */ abstract registerDisposeListener(dispose: () => void): void; + /** @deprecated */ abstract run(callback: Function): any; abstract tick(): void; - abstract waitForAsyncInitializers(): Promise; + /** @deprecated */ abstract waitForAsyncInitializers(): Promise; } /** @experimental */ @@ -518,7 +529,7 @@ export interface DirectiveMetadataType { selector?: string; } -/** @experimental */ +/** @deprecated */ export declare function disposePlatform(): void; /** @stable */ @@ -800,6 +811,7 @@ export declare abstract class NgModuleFactoryLoader { /** @experimental */ export declare class NgModuleMetadata extends InjectableMetadata implements NgModuleMetadataType { + bootstrap: Array; declarations: Array; entryComponents: Array; exports: Array; @@ -817,6 +829,7 @@ export interface NgModuleMetadataFactory { /** @experimental */ export interface NgModuleMetadataType { + bootstrap?: Array; declarations?: Array; entryComponents?: Array; exports?: Array; @@ -830,6 +843,8 @@ export declare abstract class NgModuleRef { componentFactoryResolver: ComponentFactoryResolver; injector: Injector; instance: T; + abstract destroy(): void; + abstract onDestroy(callback: () => void): void; } /** @experimental */ @@ -977,12 +992,15 @@ export declare const platformCore: (extraProviders?: any[]) => PlatformRef; /** @experimental */ export declare abstract class PlatformRef { - disposed: boolean; + destroyed: boolean; + /** @deprecated */ disposed: boolean; injector: Injector; /** @stable */ bootstrapModule(moduleType: ConcreteType, compilerOptions?: CompilerOptions | CompilerOptions[]): Promise>; /** @experimental */ bootstrapModuleFactory(moduleFactory: NgModuleFactory): Promise>; - abstract dispose(): void; - abstract registerDisposeListener(dispose: () => void): void; + abstract destroy(): void; + /** @deprecated */ abstract dispose(): void; + abstract onDestroy(callback: () => void): void; + /** @deprecated */ abstract registerDisposeListener(dispose: () => void): void; } /** @deprecated */ diff --git a/tools/public_api_guard/core/testing.d.ts b/tools/public_api_guard/core/testing.d.ts index 534fbfe06f..2aed47e4f4 100644 --- a/tools/public_api_guard/core/testing.d.ts +++ b/tools/public_api_guard/core/testing.d.ts @@ -62,6 +62,9 @@ export declare type MetadataOverride = { /** @deprecated */ export declare function resetBaseTestProviders(): void; +/** @experimental */ +export declare function resetFakeAsyncZone(): void; + /** @deprecated */ export declare function setBaseTestProviders(platformProviders: Array, applicationProviders: Array): void; diff --git a/tools/public_api_guard/router/index.d.ts b/tools/public_api_guard/router/index.d.ts index e96aafc0f9..cb9ac236d8 100644 --- a/tools/public_api_guard/router/index.d.ts +++ b/tools/public_api_guard/router/index.d.ts @@ -162,6 +162,7 @@ export declare class Router { isActive(url: string | UrlTree, exact: boolean): boolean; navigate(commands: any[], extras?: NavigationExtras): Promise; navigateByUrl(url: string | UrlTree): Promise; + ngOnDestroy(): void; parseUrl(url: string): UrlTree; resetConfig(config: Routes): void; serializeUrl(url: UrlTree): string; @@ -222,7 +223,6 @@ export declare class RouterLinkWithHref implements OnChanges, OnDestroy { /** @experimental */ export declare class RouterModule { - constructor(injector: Injector, appRef: ApplicationRef); static forChild(routes: Routes): ModuleWithProviders; static forRoot(routes: Routes, config?: ExtraOptions): ModuleWithProviders; } diff --git a/tools/public_api_guard/upgrade/index.d.ts b/tools/public_api_guard/upgrade/index.d.ts index 9eb8d43d67..054a819ea2 100644 --- a/tools/public_api_guard/upgrade/index.d.ts +++ b/tools/public_api_guard/upgrade/index.d.ts @@ -14,8 +14,8 @@ export declare class UpgradeAdapter { export declare class UpgradeAdapterRef { ng1Injector: angular.IInjectorService; ng1RootScope: angular.IRootScopeService; - ng2ApplicationRef: ApplicationRef; ng2Injector: Injector; + ng2ModuleRef: NgModuleRef; dispose(): void; ready(fn: (upgradeAdapterRef?: UpgradeAdapterRef) => void): void; }