chore: update public api and integrate minor review comments

This commit is contained in:
Tobias Bosch 2016-08-02 07:54:14 -07:00
parent 34624b2db2
commit 3d53b33391
16 changed files with 61 additions and 41 deletions

View File

@ -78,11 +78,11 @@ export function bindDirectiveAfterViewLifecycleCallbacks(
} }
export function bindInjectableDestroyLifecycleCallbacks( export function bindInjectableDestroyLifecycleCallbacks(
provider: ProviderAst, directiveInstance: o.Expression, compileElement: CompileElement) { provider: ProviderAst, providerInstance: o.Expression, compileElement: CompileElement) {
var onDestroyMethod = compileElement.view.destroyMethod; var onDestroyMethod = compileElement.view.destroyMethod;
onDestroyMethod.resetDebugInfo(compileElement.nodeIndex, compileElement.sourceAst); onDestroyMethod.resetDebugInfo(compileElement.nodeIndex, compileElement.sourceAst);
if (provider.lifecycleHooks.indexOf(LifecycleHooks.OnDestroy) !== -1) { if (provider.lifecycleHooks.indexOf(LifecycleHooks.OnDestroy) !== -1) {
onDestroyMethod.addStmt(directiveInstance.callMethod('ngOnDestroy', []).toStmt()); onDestroyMethod.addStmt(providerInstance.callMethod('ngOnDestroy', []).toStmt());
} }
} }

View File

@ -16,7 +16,7 @@ export * from './src/util';
export * from './src/di'; export * from './src/di';
export {createPlatform, assertPlatform, disposePlatform, getPlatform, coreBootstrap, coreLoadAndBootstrap, PlatformRef, ApplicationRef, enableProdMode, lockRunMode, isDevMode, createPlatformFactory} from './src/application_ref'; 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_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/zone';
export * from './src/render'; export * from './src/render';
export * from './src/linker'; export * from './src/linker';

View File

@ -23,7 +23,7 @@ export const APP_INITIALIZER: any = new OpaqueToken('Application Initializer');
* @experimental * @experimental
*/ */
@Injectable() @Injectable()
export class AppInitStatus { export class ApplicationInitStatus {
private _donePromise: Promise<any>; private _donePromise: Promise<any>;
private _done = false; private _done = false;

View File

@ -8,7 +8,7 @@
import {Type} from '../src/facade/lang'; import {Type} from '../src/facade/lang';
import {AppInitStatus} from './application_init'; import {ApplicationInitStatus} from './application_init';
import {ApplicationRef, ApplicationRef_, isDevMode} from './application_ref'; import {ApplicationRef, ApplicationRef_, isDevMode} from './application_ref';
import {APP_ID_RANDOM_PROVIDER} from './application_tokens'; import {APP_ID_RANDOM_PROVIDER} from './application_tokens';
import {IterableDiffers, KeyValueDiffers, defaultIterableDiffers, defaultKeyValueDiffers} from './change_detection/change_detection'; import {IterableDiffers, KeyValueDiffers, defaultIterableDiffers, defaultKeyValueDiffers} from './change_detection/change_detection';
@ -45,7 +45,7 @@ export const APPLICATION_COMMON_PROVIDERS: Array<Type|{[k: string]: any}|any[]>
providers: [ providers: [
ApplicationRef_, ApplicationRef_,
{provide: ApplicationRef, useExisting: ApplicationRef_}, {provide: ApplicationRef, useExisting: ApplicationRef_},
AppInitStatus, ApplicationInitStatus,
Compiler, Compiler,
{provide: ComponentResolver, useExisting: Compiler}, {provide: ComponentResolver, useExisting: Compiler},
APP_ID_RANDOM_PROVIDER, APP_ID_RANDOM_PROVIDER,

View File

@ -11,7 +11,7 @@ import {ListWrapper} from '../src/facade/collection';
import {BaseException, ExceptionHandler, unimplemented} from '../src/facade/exceptions'; import {BaseException, ExceptionHandler, unimplemented} from '../src/facade/exceptions';
import {ConcreteType, Type, isBlank, isPresent, isPromise, stringify} from '../src/facade/lang'; 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 {APP_BOOTSTRAP_LISTENER, PLATFORM_INITIALIZER} from './application_tokens';
import {ChangeDetectorRef} from './change_detection/change_detector_ref'; import {ChangeDetectorRef} from './change_detection/change_detector_ref';
import {Console} from './console'; import {Console} from './console';
@ -275,7 +275,7 @@ export abstract class PlatformRef {
abstract destroy(): void; abstract destroy(): void;
/** /**
* @deprecated Use `destroyd` instead * @deprecated Use `destroyed` instead
*/ */
get disposed(): boolean { throw unimplemented(); } get disposed(): boolean { throw unimplemented(); }
get destroyed(): boolean { throw unimplemented(); } get destroyed(): boolean { throw unimplemented(); }
@ -327,7 +327,7 @@ export class PlatformRef_ extends PlatformRef {
destroy() { destroy() {
if (this._destroyed) { 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()); ListWrapper.clone(this._modules).forEach((app) => app.destroy());
this._destroyListeners.forEach((dispose) => dispose()); this._destroyListeners.forEach((dispose) => dispose());
@ -360,7 +360,7 @@ export class PlatformRef_ extends PlatformRef {
exceptionHandler.call(error.error, error.stackTrace); exceptionHandler.call(error.error, error.stackTrace);
}); });
return _callAndReportToExceptionHandler(exceptionHandler, () => { return _callAndReportToExceptionHandler(exceptionHandler, () => {
const initStatus: AppInitStatus = moduleRef.injector.get(AppInitStatus); const initStatus: ApplicationInitStatus = moduleRef.injector.get(ApplicationInitStatus);
return initStatus.donePromise.then(() => { return initStatus.donePromise.then(() => {
this._moduleDoBootstrap(moduleRef); this._moduleDoBootstrap(moduleRef);
return moduleRef; return moduleRef;
@ -421,7 +421,7 @@ export abstract class ApplicationRef {
* Returns a promise that resolves when all asynchronous application initializers * Returns a promise that resolves when all asynchronous application initializers
* are done. * are done.
* *
* @deprecated Use the {@link AppInitStatus} class instead. * @deprecated Use the {@link ApplicationInitStatus} class instead.
*/ */
abstract waitForAsyncInitializers(): Promise<any>; abstract waitForAsyncInitializers(): Promise<any>;
@ -514,7 +514,7 @@ export class ApplicationRef_ extends ApplicationRef {
private _zone: NgZone, private _console: Console, private _injector: Injector, private _zone: NgZone, private _console: Console, private _injector: Injector,
private _exceptionHandler: ExceptionHandler, private _exceptionHandler: ExceptionHandler,
private _componentFactoryResolver: ComponentFactoryResolver, private _componentFactoryResolver: ComponentFactoryResolver,
private _initStatus: AppInitStatus, private _initStatus: ApplicationInitStatus,
@Optional() private _testabilityRegistry: TestabilityRegistry, @Optional() private _testabilityRegistry: TestabilityRegistry,
@Optional() private _testability: Testability) { @Optional() private _testability: Testability) {
super(); super();

View File

@ -48,7 +48,10 @@ function _randomChar(): string {
export const PLATFORM_INITIALIZER: any = new OpaqueToken('Platform Initializer'); 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 * @experimental
*/ */

View File

@ -108,7 +108,7 @@ export abstract class NgModuleInjector<T> extends CodegenComponentFactoryResolve
destroy(): void { destroy(): void {
if (this._destroyed) { if (this._destroyed) {
throw new BaseException( 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._destroyed = true;
this.destroyInternal(); this.destroyInternal();

View File

@ -150,7 +150,7 @@ export class NgModuleMetadata extends InjectableMetadata implements NgModuleMeta
* this module is bootstrapped. The components listed here * this module is bootstrapped. The components listed here
* will automatically be added to `entryComponents`. * will automatically be added to `entryComponents`.
*/ */
bootstrap: Array<Type|any[]> bootstrap: Array<Type|any[]>;
schemas: Array<SchemaMetadata|any[]>; schemas: Array<SchemaMetadata|any[]>;

View File

@ -5,19 +5,21 @@
* Use of this source code is governed by an MIT-style license that can be * 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 * 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 {PromiseCompleter, PromiseWrapper} from '../src/facade/async';
import {TestBed, async, inject, withModule} from '../testing'; import {TestBed, async, inject, withModule} from '../testing';
export function main() { export function main() {
describe('AppInitStatus', () => { describe('ApplicationInitStatus', () => {
describe('no initializers', () => { describe('no initializers', () => {
it('should return true for `done`', 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`', 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); }); 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', it('should updat the status once all async initializers are done',
async(inject([AppInitStatus], (status: AppInitStatus) => { async(inject([ApplicationInitStatus], (status: ApplicationInitStatus) => {
let completerResolver = false; let completerResolver = false;
setTimeout(() => { setTimeout(() => {
completerResolver = true; completerResolver = true;

View File

@ -311,7 +311,7 @@ function declareTests({useJit}: {useJit: boolean}) {
.toBe(SomeComp); .toBe(SomeComp);
}); });
it('should crate ComponentFactories in imported modules', () => { it('should create ComponentFactories in imported modules', () => {
@NgModule({declarations: [SomeComp], entryComponents: [SomeComp]}) @NgModule({declarations: [SomeComp], entryComponents: [SomeComp]})
class SomeImportedModule { class SomeImportedModule {
} }

View File

@ -548,9 +548,6 @@ export class RootRouter extends Router {
return promise; return promise;
} }
/**
* @internal
*/
ngOnDestroy() { this.dispose(); } ngOnDestroy() { this.dispose(); }
dispose(): void { dispose(): void {

View File

@ -196,9 +196,6 @@ export class Router {
this.config = config; this.config = config;
} }
/**
* @internal
*/
ngOnDestroy() { this.dispose(); } ngOnDestroy() { this.dispose(); }
/** /**

View File

@ -118,6 +118,9 @@ export declare abstract class AnimationWithStepsMetadata extends AnimationMetada
constructor(); constructor();
} }
/** @experimental */
export declare const APP_BOOTSTRAP_LISTENER: OpaqueToken;
/** @experimental */ /** @experimental */
export declare const APP_ID: any; export declare const APP_ID: any;
@ -129,6 +132,13 @@ export declare const APPLICATION_COMMON_PROVIDERS: Array<Type | {
[k: string]: any; [k: string]: any;
} | any[]>; } | any[]>;
/** @experimental */
export declare class ApplicationInitStatus {
done: boolean;
donePromise: Promise<any>;
constructor(appInits: (() => any)[]);
}
/** @experimental */ /** @experimental */
export declare class ApplicationModule { export declare class ApplicationModule {
} }
@ -136,15 +146,16 @@ export declare class ApplicationModule {
/** @experimental */ /** @experimental */
export declare abstract class ApplicationRef { export declare abstract class ApplicationRef {
componentTypes: Type[]; componentTypes: Type[];
injector: Injector; components: ComponentRef<any>[];
zone: NgZone; /** @deprecated */ injector: Injector;
/** @deprecated */ zone: NgZone;
abstract bootstrap<C>(componentFactory: ComponentFactory<C> | ConcreteType<C>): ComponentRef<C>; abstract bootstrap<C>(componentFactory: ComponentFactory<C> | ConcreteType<C>): ComponentRef<C>;
abstract dispose(): void; /** @deprecated */ abstract dispose(): void;
abstract registerBootstrapListener(listener: (ref: ComponentRef<any>) => void): void; /** @deprecated */ abstract registerBootstrapListener(listener: (ref: ComponentRef<any>) => void): void;
abstract registerDisposeListener(dispose: () => void): void; /** @deprecated */ abstract registerDisposeListener(dispose: () => void): void;
abstract run(callback: Function): any; /** @deprecated */ abstract run(callback: Function): any;
abstract tick(): void; abstract tick(): void;
abstract waitForAsyncInitializers(): Promise<any>; /** @deprecated */ abstract waitForAsyncInitializers(): Promise<any>;
} }
/** @experimental */ /** @experimental */
@ -518,7 +529,7 @@ export interface DirectiveMetadataType {
selector?: string; selector?: string;
} }
/** @experimental */ /** @deprecated */
export declare function disposePlatform(): void; export declare function disposePlatform(): void;
/** @stable */ /** @stable */
@ -800,6 +811,7 @@ export declare abstract class NgModuleFactoryLoader {
/** @experimental */ /** @experimental */
export declare class NgModuleMetadata extends InjectableMetadata implements NgModuleMetadataType { export declare class NgModuleMetadata extends InjectableMetadata implements NgModuleMetadataType {
bootstrap: Array<Type | any[]>;
declarations: Array<Type | any[]>; declarations: Array<Type | any[]>;
entryComponents: Array<Type | any[]>; entryComponents: Array<Type | any[]>;
exports: Array<Type | any[]>; exports: Array<Type | any[]>;
@ -817,6 +829,7 @@ export interface NgModuleMetadataFactory {
/** @experimental */ /** @experimental */
export interface NgModuleMetadataType { export interface NgModuleMetadataType {
bootstrap?: Array<Type | any[]>;
declarations?: Array<Type | any[]>; declarations?: Array<Type | any[]>;
entryComponents?: Array<Type | any[]>; entryComponents?: Array<Type | any[]>;
exports?: Array<Type | any[]>; exports?: Array<Type | any[]>;
@ -830,6 +843,8 @@ export declare abstract class NgModuleRef<T> {
componentFactoryResolver: ComponentFactoryResolver; componentFactoryResolver: ComponentFactoryResolver;
injector: Injector; injector: Injector;
instance: T; instance: T;
abstract destroy(): void;
abstract onDestroy(callback: () => void): void;
} }
/** @experimental */ /** @experimental */
@ -977,12 +992,15 @@ export declare const platformCore: (extraProviders?: any[]) => PlatformRef;
/** @experimental */ /** @experimental */
export declare abstract class PlatformRef { export declare abstract class PlatformRef {
disposed: boolean; destroyed: boolean;
/** @deprecated */ disposed: boolean;
injector: Injector; injector: Injector;
/** @stable */ bootstrapModule<M>(moduleType: ConcreteType<M>, compilerOptions?: CompilerOptions | CompilerOptions[]): Promise<NgModuleRef<M>>; /** @stable */ bootstrapModule<M>(moduleType: ConcreteType<M>, compilerOptions?: CompilerOptions | CompilerOptions[]): Promise<NgModuleRef<M>>;
/** @experimental */ bootstrapModuleFactory<M>(moduleFactory: NgModuleFactory<M>): Promise<NgModuleRef<M>>; /** @experimental */ bootstrapModuleFactory<M>(moduleFactory: NgModuleFactory<M>): Promise<NgModuleRef<M>>;
abstract dispose(): void; abstract destroy(): void;
abstract registerDisposeListener(dispose: () => void): void; /** @deprecated */ abstract dispose(): void;
abstract onDestroy(callback: () => void): void;
/** @deprecated */ abstract registerDisposeListener(dispose: () => void): void;
} }
/** @deprecated */ /** @deprecated */

View File

@ -62,6 +62,9 @@ export declare type MetadataOverride<T> = {
/** @deprecated */ /** @deprecated */
export declare function resetBaseTestProviders(): void; export declare function resetBaseTestProviders(): void;
/** @experimental */
export declare function resetFakeAsyncZone(): void;
/** @deprecated */ /** @deprecated */
export declare function setBaseTestProviders(platformProviders: Array<Type | Provider | any[]>, applicationProviders: Array<Type | Provider | any[]>): void; export declare function setBaseTestProviders(platformProviders: Array<Type | Provider | any[]>, applicationProviders: Array<Type | Provider | any[]>): void;

View File

@ -162,6 +162,7 @@ export declare class Router {
isActive(url: string | UrlTree, exact: boolean): boolean; isActive(url: string | UrlTree, exact: boolean): boolean;
navigate(commands: any[], extras?: NavigationExtras): Promise<boolean>; navigate(commands: any[], extras?: NavigationExtras): Promise<boolean>;
navigateByUrl(url: string | UrlTree): Promise<boolean>; navigateByUrl(url: string | UrlTree): Promise<boolean>;
ngOnDestroy(): void;
parseUrl(url: string): UrlTree; parseUrl(url: string): UrlTree;
resetConfig(config: Routes): void; resetConfig(config: Routes): void;
serializeUrl(url: UrlTree): string; serializeUrl(url: UrlTree): string;
@ -222,7 +223,6 @@ export declare class RouterLinkWithHref implements OnChanges, OnDestroy {
/** @experimental */ /** @experimental */
export declare class RouterModule { export declare class RouterModule {
constructor(injector: Injector, appRef: ApplicationRef);
static forChild(routes: Routes): ModuleWithProviders; static forChild(routes: Routes): ModuleWithProviders;
static forRoot(routes: Routes, config?: ExtraOptions): ModuleWithProviders; static forRoot(routes: Routes, config?: ExtraOptions): ModuleWithProviders;
} }

View File

@ -14,8 +14,8 @@ export declare class UpgradeAdapter {
export declare class UpgradeAdapterRef { export declare class UpgradeAdapterRef {
ng1Injector: angular.IInjectorService; ng1Injector: angular.IInjectorService;
ng1RootScope: angular.IRootScopeService; ng1RootScope: angular.IRootScopeService;
ng2ApplicationRef: ApplicationRef;
ng2Injector: Injector; ng2Injector: Injector;
ng2ModuleRef: NgModuleRef<any>;
dispose(): void; dispose(): void;
ready(fn: (upgradeAdapterRef?: UpgradeAdapterRef) => void): void; ready(fn: (upgradeAdapterRef?: UpgradeAdapterRef) => void): void;
} }