chore: update public api and integrate minor review comments
This commit is contained in:
parent
34624b2db2
commit
3d53b33391
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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';
|
||||
|
|
|
@ -23,7 +23,7 @@ export const APP_INITIALIZER: any = new OpaqueToken('Application Initializer');
|
|||
* @experimental
|
||||
*/
|
||||
@Injectable()
|
||||
export class AppInitStatus {
|
||||
export class ApplicationInitStatus {
|
||||
private _donePromise: Promise<any>;
|
||||
private _done = false;
|
||||
|
||||
|
|
|
@ -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<Type|{[k: string]: any}|any[]>
|
|||
providers: [
|
||||
ApplicationRef_,
|
||||
{provide: ApplicationRef, useExisting: ApplicationRef_},
|
||||
AppInitStatus,
|
||||
ApplicationInitStatus,
|
||||
Compiler,
|
||||
{provide: ComponentResolver, useExisting: Compiler},
|
||||
APP_ID_RANDOM_PROVIDER,
|
||||
|
|
|
@ -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<any>;
|
||||
|
||||
|
@ -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();
|
||||
|
|
|
@ -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
|
||||
*/
|
||||
|
|
|
@ -108,7 +108,7 @@ export abstract class NgModuleInjector<T> 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();
|
||||
|
|
|
@ -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<Type|any[]>
|
||||
bootstrap: Array<Type|any[]>;
|
||||
|
||||
schemas: Array<SchemaMetadata|any[]>;
|
||||
schemas: Array<SchemaMetadata|any[]>;
|
||||
|
||||
constructor(options: NgModuleMetadataType = {}) {
|
||||
// We cannot use destructuring of the constructor argument because `exports` is a
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 {
|
||||
}
|
||||
|
|
|
@ -548,9 +548,6 @@ export class RootRouter extends Router {
|
|||
return promise;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
ngOnDestroy() { this.dispose(); }
|
||||
|
||||
dispose(): void {
|
||||
|
|
|
@ -196,9 +196,6 @@ export class Router {
|
|||
this.config = config;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
ngOnDestroy() { this.dispose(); }
|
||||
|
||||
/**
|
||||
|
|
|
@ -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<Type | {
|
|||
[k: string]: any;
|
||||
} | any[]>;
|
||||
|
||||
/** @experimental */
|
||||
export declare class ApplicationInitStatus {
|
||||
done: boolean;
|
||||
donePromise: Promise<any>;
|
||||
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<any>[];
|
||||
/** @deprecated */ injector: Injector;
|
||||
/** @deprecated */ zone: NgZone;
|
||||
abstract bootstrap<C>(componentFactory: ComponentFactory<C> | ConcreteType<C>): ComponentRef<C>;
|
||||
abstract dispose(): void;
|
||||
abstract registerBootstrapListener(listener: (ref: ComponentRef<any>) => void): void;
|
||||
abstract registerDisposeListener(dispose: () => void): void;
|
||||
abstract run(callback: Function): any;
|
||||
/** @deprecated */ abstract dispose(): void;
|
||||
/** @deprecated */ abstract registerBootstrapListener(listener: (ref: ComponentRef<any>) => void): void;
|
||||
/** @deprecated */ abstract registerDisposeListener(dispose: () => void): void;
|
||||
/** @deprecated */ abstract run(callback: Function): any;
|
||||
abstract tick(): void;
|
||||
abstract waitForAsyncInitializers(): Promise<any>;
|
||||
/** @deprecated */ abstract waitForAsyncInitializers(): Promise<any>;
|
||||
}
|
||||
|
||||
/** @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<Type | any[]>;
|
||||
declarations: Array<Type | any[]>;
|
||||
entryComponents: Array<Type | any[]>;
|
||||
exports: Array<Type | any[]>;
|
||||
|
@ -817,6 +829,7 @@ export interface NgModuleMetadataFactory {
|
|||
|
||||
/** @experimental */
|
||||
export interface NgModuleMetadataType {
|
||||
bootstrap?: Array<Type | any[]>;
|
||||
declarations?: Array<Type | any[]>;
|
||||
entryComponents?: Array<Type | any[]>;
|
||||
exports?: Array<Type | any[]>;
|
||||
|
@ -830,6 +843,8 @@ export declare abstract class NgModuleRef<T> {
|
|||
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<M>(moduleType: ConcreteType<M>, compilerOptions?: CompilerOptions | CompilerOptions[]): Promise<NgModuleRef<M>>;
|
||||
/** @experimental */ bootstrapModuleFactory<M>(moduleFactory: NgModuleFactory<M>): Promise<NgModuleRef<M>>;
|
||||
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 */
|
||||
|
|
|
@ -62,6 +62,9 @@ export declare type MetadataOverride<T> = {
|
|||
/** @deprecated */
|
||||
export declare function resetBaseTestProviders(): void;
|
||||
|
||||
/** @experimental */
|
||||
export declare function resetFakeAsyncZone(): void;
|
||||
|
||||
/** @deprecated */
|
||||
export declare function setBaseTestProviders(platformProviders: Array<Type | Provider | any[]>, applicationProviders: Array<Type | Provider | any[]>): void;
|
||||
|
||||
|
|
|
@ -162,6 +162,7 @@ export declare class Router {
|
|||
isActive(url: string | UrlTree, exact: boolean): boolean;
|
||||
navigate(commands: any[], extras?: NavigationExtras): Promise<boolean>;
|
||||
navigateByUrl(url: string | UrlTree): Promise<boolean>;
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -14,8 +14,8 @@ export declare class UpgradeAdapter {
|
|||
export declare class UpgradeAdapterRef {
|
||||
ng1Injector: angular.IInjectorService;
|
||||
ng1RootScope: angular.IRootScopeService;
|
||||
ng2ApplicationRef: ApplicationRef;
|
||||
ng2Injector: Injector;
|
||||
ng2ModuleRef: NgModuleRef<any>;
|
||||
dispose(): void;
|
||||
ready(fn: (upgradeAdapterRef?: UpgradeAdapterRef) => void): void;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue