refactor(core): change module semantics

This contains major changes to the compiler, bootstrap of the platforms
and test environment initialization.

Main part of #10043
Closes #10164

BREAKING CHANGE:
- Semantics and name of `@AppModule` (now `@NgModule`) changed quite a bit.
  This is actually not breaking as `@AppModules` were not part of rc.4.
  We will have detailed docs on `@NgModule` separately.
- `coreLoadAndBootstrap` and `coreBootstrap` can't be used any more (without migration support).
  Use `bootstrapModule` / `bootstrapModuleFactory` instead.
- All Components listed in routes have to be part of the `declarations` of an NgModule.
  Either directly on the bootstrap module / lazy loaded module, or in an NgModule imported by them.
This commit is contained in:
Tobias Bosch
2016-07-18 03:50:31 -07:00
parent ca16fc29a6
commit 46b212706b
129 changed files with 3580 additions and 3366 deletions

View File

@ -80,6 +80,10 @@ export declare const COMMON_DIRECTIVES: Type[][];
/** @experimental */
export declare const COMMON_PIPES: (typeof AsyncPipe | typeof SlicePipe | typeof ReplacePipe | typeof I18nPluralPipe | typeof I18nSelectPipe)[];
/** @experimental */
export declare class CommonModule {
}
/** @experimental */
export declare class Control extends AbstractControl {
constructor(value?: any, validator?: ValidatorFn, asyncValidator?: AsyncValidatorFn);

View File

@ -124,11 +124,15 @@ export declare const APP_ID: any;
/** @experimental */
export declare const APP_INITIALIZER: any;
/** @stable */
/** @deprecated */
export declare const APPLICATION_COMMON_PROVIDERS: Array<Type | {
[k: string]: any;
} | any[]>;
/** @experimental */
export declare class ApplicationModule {
}
/** @experimental */
export declare abstract class ApplicationRef {
componentTypes: Type[];
@ -143,68 +147,6 @@ export declare abstract class ApplicationRef {
abstract waitForAsyncInitializers(): Promise<any>;
}
/** @stable */
export declare var AppModule: AppModuleMetadataFactory;
/** @stable */
export interface AppModuleDecorator extends TypeDecorator {
}
/** @stable */
export declare class AppModuleFactory<T> {
moduleType: ConcreteType<T>;
constructor(_injectorClass: {
new (parentInjector: Injector): AppModuleInjector<T>;
}, _moduleype: ConcreteType<T>);
create(parentInjector?: Injector): AppModuleRef<T>;
}
/** @experimental */
export declare abstract class AppModuleFactoryLoader {
abstract load(path: string): Promise<AppModuleFactory<any>>;
}
/** @stable */
export declare class AppModuleMetadata extends InjectableMetadata {
directives: Array<Type | any[]>;
modules: Array<Type | any[]>;
pipes: Array<Type | any[]>;
precompile: Array<Type | any[]>;
providers: any[];
constructor({providers, directives, pipes, precompile, modules}?: {
providers?: any[];
directives?: Array<Type | any[]>;
pipes?: Array<Type | any[]>;
precompile?: Array<Type | any[]>;
modules?: Array<Type | any[]>;
});
}
/** @stable */
export interface AppModuleMetadataFactory {
(obj: {
providers?: any[];
directives?: Array<Type | any[]>;
pipes?: Array<Type | any[]>;
precompile?: Array<Type | any[]>;
modules?: Array<Type | any[]>;
}): AppModuleDecorator;
new (obj: {
providers?: any[];
directives?: Array<Type | any[]>;
pipes?: Array<Type | any[]>;
precompile?: Array<Type | any[]>;
modules?: Array<Type | any[]>;
}): AppModuleMetadata;
}
/** @stable */
export declare abstract class AppModuleRef<T> {
componentFactoryResolver: ComponentFactoryResolver;
injector: Injector;
instance: T;
}
/** @experimental */
export declare function asNativeElements(debugEls: DebugElement[]): any;
@ -259,10 +201,10 @@ export declare class Binding extends Provider {
}
/** @stable */
export declare function bootstrapModule<M>(moduleType: ConcreteType<M>, platform: PlatformRef, compilerOptions?: CompilerOptions): Promise<AppModuleRef<M>>;
export declare function bootstrapModule<M>(moduleType: ConcreteType<M>, platform: PlatformRef, compilerOptions?: CompilerOptions | CompilerOptions[]): Promise<NgModuleRef<M>>;
/** @experimental */
export declare function bootstrapModuleFactory<M>(moduleFactory: AppModuleFactory<M>, platform: PlatformRef): AppModuleRef<M>;
export declare function bootstrapModuleFactory<M>(moduleFactory: NgModuleFactory<M>, platform: PlatformRef): NgModuleRef<M>;
/** @stable */
export declare enum ChangeDetectionStrategy {
@ -301,30 +243,21 @@ export declare class CollectionChangeRecord {
/** @stable */
export declare class Compiler {
injector: Injector;
clearCache(): void;
clearCacheFor(type: Type): void;
compileAppModuleAsync<T>(moduleType: ConcreteType<T>, metadata?: AppModuleMetadata): Promise<AppModuleFactory<T>>;
compileAppModuleSync<T>(moduleType: ConcreteType<T>, metadata?: AppModuleMetadata): AppModuleFactory<T>;
compileComponentAsync<T>(component: ConcreteType<T>): Promise<ComponentFactory<T>>;
compileComponentSync<T>(component: ConcreteType<T>): ComponentFactory<T>;
compileComponentAsync<T>(component: ConcreteType<T>, ngModule?: Type): Promise<ComponentFactory<T>>;
compileComponentSync<T>(component: ConcreteType<T>, ngModule?: Type): ComponentFactory<T>;
compileModuleAsync<T>(moduleType: ConcreteType<T>): Promise<NgModuleFactory<T>>;
compileModuleSync<T>(moduleType: ConcreteType<T>): NgModuleFactory<T>;
}
/** @experimental */
export declare abstract class CompilerFactory {
abstract createCompiler(options?: CompilerOptions): Compiler;
withDefaults(options?: CompilerOptions): CompilerFactory;
static mergeOptions(defaultOptions?: CompilerOptions, newOptions?: CompilerOptions): CompilerOptions;
abstract createCompiler(options?: CompilerOptions[]): Compiler;
}
/** @experimental */
export declare type CompilerOptions = {
useDebug?: boolean;
useJit?: boolean;
defaultEncapsulation?: ViewEncapsulation;
providers?: any[];
deprecatedAppProviders?: any[];
};
export declare const CompilerOptions: OpaqueToken;
/** @stable */
export declare var Component: ComponentMetadataFactory;
@ -536,11 +469,14 @@ export declare function coreBootstrap<C>(componentFactory: ComponentFactory<C>,
/** @deprecated */
export declare function coreLoadAndBootstrap(componentType: Type, injector: Injector): Promise<ComponentRef<any>>;
/** @experimental */
export declare const corePlatform: (extraProviders?: any[]) => PlatformRef;
/** @experimental */
export declare function createPlatform(injector: Injector): PlatformRef;
/** @experimental */
export declare function createPlatformFactory(name: string, providers: any[]): () => PlatformRef;
export declare function createPlatformFactory(parentPlaformFactory: PlatformFactory, name: string, providers?: any[]): PlatformFactory;
/** @stable */
export declare class CyclicDependencyError extends AbstractProviderError {
@ -927,6 +863,68 @@ export declare class KeyValueDiffers {
/** @deprecated */
export declare function lockRunMode(): void;
/** @experimental */
export declare var NgModule: NgModuleMetadataFactory;
/** @stable */
export interface NgModuleDecorator extends TypeDecorator {
}
/** @experimental */
export declare class NgModuleFactory<T> {
moduleType: ConcreteType<T>;
constructor(_injectorClass: {
new (parentInjector: Injector): NgModuleInjector<T>;
}, _moduleype: ConcreteType<T>);
create(parentInjector: Injector): NgModuleRef<T>;
}
/** @experimental */
export declare abstract class NgModuleFactoryLoader {
abstract load(path: string): Promise<NgModuleFactory<any>>;
}
/** @experimental */
export declare class NgModuleMetadata extends InjectableMetadata {
declarations: Array<Type | any[]>;
exports: Array<Type | any[]>;
imports: Array<Type | any[]>;
precompile: Array<Type | any[]>;
providers: any[];
constructor({providers, declarations, imports, exports, precompile}?: {
providers?: any[];
declarations?: Array<Type | any[]>;
imports?: Array<Type | any[]>;
exports?: Array<Type | any[]>;
precompile?: Array<Type | any[]>;
});
}
/** @experimental */
export interface NgModuleMetadataFactory {
(obj?: {
providers?: any[];
declarations?: Array<Type | any[]>;
imports?: Array<Type | any[]>;
exports?: Array<Type | any[]>;
precompile?: Array<Type | any[]>;
}): NgModuleDecorator;
new (obj?: {
providers?: any[];
declarations?: Array<Type | any[]>;
imports?: Array<Type | any[]>;
exports?: Array<Type | any[]>;
precompile?: Array<Type | any[]>;
}): NgModuleMetadata;
}
/** @experimental */
export declare abstract class NgModuleRef<T> {
componentFactoryResolver: ComponentFactoryResolver;
injector: Injector;
instance: T;
}
/** @experimental */
export declare class NgZone {
hasPendingMacrotasks: boolean;
@ -1058,8 +1056,8 @@ export interface PipeTransform {
transform(value: any, ...args: any[]): any;
}
/** @experimental */
export declare const PLATFORM_COMMON_PROVIDERS: Array<any | Type | Provider | any[]>;
/** @deprecated */
export declare const PLATFORM_COMMON_PROVIDERS: any[];
/** @deprecated */
export declare const PLATFORM_DIRECTIVES: OpaqueToken;
@ -1336,12 +1334,6 @@ export declare function style(tokens: string | {
[key: string]: string | number;
}>): AnimationStyleMetadata;
/** @experimental */
export declare class SystemJsAppModuleLoader implements AppModuleFactoryLoader {
constructor(_compiler: Compiler);
load(path: string): Promise<AppModuleFactory<any>>;
}
/** @deprecated */
export declare class SystemJsCmpFactoryResolver implements ComponentResolver {
constructor(_console: Console);
@ -1356,6 +1348,12 @@ export declare class SystemJsComponentResolver implements ComponentResolver {
resolveComponent(componentType: string | Type): Promise<ComponentFactory<any>>;
}
/** @experimental */
export declare class SystemJsNgModuleLoader implements NgModuleFactoryLoader {
constructor(_compiler: Compiler);
load(path: string): Promise<NgModuleFactory<any>>;
}
/** @stable */
export declare abstract class TemplateRef<C> {
elementRef: ElementRef;

View File

@ -37,10 +37,9 @@ export declare function configureCompiler(config: {
/** @stable */
export declare function configureModule(moduleDef: {
providers?: any[];
directives?: any[];
pipes?: any[];
declarations?: any[];
imports?: any[];
precompile?: any[];
modules?: any[];
}): void;
/** @experimental */
@ -62,7 +61,7 @@ export declare function getTestBed(): TestBed;
export declare function getTestInjector(): TestBed;
/** @experimental */
export declare function initTestEnvironment(appModule: Type, platform: PlatformRef): void;
export declare function initTestEnvironment(ngModule: Type, platform: PlatformRef): Injector;
/** @stable */
export declare function inject(tokens: any[], fn: Function): () => any;
@ -71,10 +70,9 @@ export declare function inject(tokens: any[], fn: Function): () => any;
export declare class InjectSetupWrapper {
constructor(_moduleDef: () => {
providers?: any[];
directives?: any[];
pipes?: any[];
declarations?: any[];
imports?: any[];
precompile?: any[];
modules?: any[];
});
inject(tokens: any[], fn: Function): () => any;
}
@ -90,7 +88,7 @@ export declare function setBaseTestProviders(platformProviders: Array<Type | Pro
/** @experimental */
export declare class TestBed implements Injector {
appModule: Type;
ngModule: Type;
platform: PlatformRef;
configureCompiler(config: {
providers?: any[];
@ -98,15 +96,14 @@ export declare class TestBed implements Injector {
}): void;
configureModule(moduleDef: {
providers?: any[];
directives?: any[];
pipes?: any[];
declarations?: any[];
imports?: any[];
precompile?: any[];
modules?: any[];
}): void;
createAppModuleFactory(): Promise<AppModuleFactory<any>>;
createModuleFactory(): Promise<NgModuleFactory<any>>;
execute(tokens: any[], fn: Function): any;
get(token: any, notFoundValue?: any): any;
initTestAppModule(): void;
initTestModule(): void;
reset(): void;
}
@ -114,10 +111,10 @@ export declare class TestBed implements Injector {
export declare class TestComponentBuilder {
protected _injector: Injector;
constructor(_injector: Injector);
createAsync<T>(rootComponentType: ConcreteType<T>): Promise<ComponentFixture<T>>;
createFakeAsync<T>(rootComponentType: ConcreteType<T>): ComponentFixture<T>;
createAsync<T>(rootComponentType: ConcreteType<T>, ngModule?: ConcreteType<any>): Promise<ComponentFixture<T>>;
createFakeAsync<T>(rootComponentType: ConcreteType<T>, ngModule?: ConcreteType<any>): ComponentFixture<T>;
protected createFromFactory<C>(ngZone: NgZone, componentFactory: ComponentFactory<C>): ComponentFixture<C>;
createSync<T>(rootComponentType: ConcreteType<T>): ComponentFixture<T>;
createSync<T>(rootComponentType: ConcreteType<T>, ngModule?: ConcreteType<any>): ComponentFixture<T>;
overrideAnimations(componentType: Type, animations: AnimationEntryMetadata[]): TestComponentBuilder;
overrideDirective(componentType: Type, from: Type, to: Type): TestComponentBuilder;
overrideProviders(type: Type, providers: any[]): TestComponentBuilder;
@ -137,10 +134,9 @@ export declare function tick(millis?: number): void;
/** @experimental */
export declare function withModule(moduleDef: () => {
providers?: any[];
directives?: any[];
pipes?: any[];
declarations?: any[];
imports?: any[];
precompile?: any[];
modules?: any[];
}): InjectSetupWrapper;
/** @experimental */

View File

@ -2,22 +2,19 @@
export declare function bootstrap<C>(appComponentType: ConcreteType<C>, customProviders?: Array<any>): Promise<ComponentRef<C>>;
/** @deprecated */
export declare function bootstrapWorkerApp(appComponentType: Type, customProviders?: Array<any>): Promise<ComponentRef<any>>;
export declare function bootstrapWorkerApp<T>(appComponentType: ConcreteType<T>, customProviders?: Array<any>): Promise<ComponentRef<T>>;
/** @deprecated */
export declare function bootstrapWorkerUi(workerScriptUri: string, customProviders?: Array<any>): Promise<ApplicationRef>;
/** @experimental */
export declare function bootstrapWorkerUi(workerScriptUri: string, customProviders?: Array<any>): Promise<PlatformRef>;
/** @deprecated */
export declare const BROWSER_APP_COMPILER_PROVIDERS: Array<any>;
/** @experimental */
export declare const BROWSER_DYNAMIC_COMPILER_FACTORY: CompilerFactory;
/** @experimental */
export declare const BROWSER_DYNAMIC_PLATFORM_PROVIDERS: Array<any>;
/** @experimental */
export declare const browserDynamicPlatform: () => PlatformRef;
export declare const browserDynamicPlatform: (extraProviders?: any[]) => PlatformRef;
/** @experimental */
export declare const CACHED_TEMPLATE_PROVIDER: Array<any>;
/** @experimental */
export declare const workerAppDynamicPlatform: (extraProviders?: any[]) => PlatformRef;

View File

@ -1,12 +1,9 @@
/** @experimental */
export declare const BROWSER_DYNAMIC_TEST_COMPILER_FACTORY: CompilerFactory;
/** @stable */
export declare class BrowserDynamicTestModule {
export declare class BrowserDynamicTestingModule {
}
/** @experimental */
export declare const browserDynamicTestPlatform: () => PlatformRef;
export declare const browserDynamicTestingPlatform: (extraProviders?: any[]) => PlatformRef;
/** @deprecated */
export declare const TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS: Array<any>;

View File

@ -1,13 +1,16 @@
/** @experimental */
export declare const _WORKER_UI_PLATFORM_PROVIDERS: Array<any>;
/** @experimental */
export declare abstract class AnimationDriver {
abstract animate(element: any, startingStyles: AnimationStyles, keyframes: AnimationKeyframe[], duration: number, delay: number, easing: string): AnimationPlayer;
static NOOP: AnimationDriver;
}
/** @experimental */
/** @deprecated */
export declare const BROWSER_APP_PROVIDERS: Array<any>;
/** @experimental */
/** @deprecated */
export declare const BROWSER_PLATFORM_PROVIDERS: Array<any>;
/** @experimental */
@ -18,7 +21,7 @@ export declare class BrowserModule {
}
/** @experimental */
export declare const browserPlatform: () => PlatformRef;
export declare const browserPlatform: (extraProviders?: any[]) => PlatformRef;
/** @stable */
export declare class BrowserPlatformLocation extends PlatformLocation {
@ -186,7 +189,7 @@ export declare class WebWorkerInstance {
worker: Worker;
}
/** @experimental */
/** @deprecated */
export declare const WORKER_APP_APPLICATION_PROVIDERS: Array<any>;
/** @experimental */
@ -200,13 +203,13 @@ export declare const WORKER_APP_LOCATION_PROVIDERS: ({
deps: (typeof PlatformLocation | typeof NgZone)[];
})[];
/** @experimental */
/** @deprecated */
export declare const WORKER_APP_PLATFORM_PROVIDERS: Array<any>;
/** @experimental */
export declare const WORKER_SCRIPT: OpaqueToken;
/** @experimental */
/** @deprecated */
export declare const WORKER_UI_APPLICATION_PROVIDERS: Array<any>;
/** @experimental */
@ -217,7 +220,7 @@ export declare const WORKER_UI_LOCATION_PROVIDERS: (typeof MessageBasedPlatformL
deps: typeof Injector[];
})[];
/** @experimental */
/** @deprecated */
export declare const WORKER_UI_PLATFORM_PROVIDERS: Array<any>;
/** @experimental */
@ -228,11 +231,7 @@ export declare class WorkerAppModule {
}
/** @experimental */
export declare const workerAppPlatform: () => PlatformRef;
export declare const workerAppPlatform: (extraProviders?: any[]) => PlatformRef;
/** @experimental */
export declare class WorkerUiModule {
}
/** @experimental */
export declare const workerUiPlatform: () => PlatformRef;
export declare const workerUiPlatform: (extraProviders?: any[]) => PlatformRef;

View File

@ -1,12 +1,12 @@
/** @stable */
export declare class BrowserTestModule {
/** @experimental */
export declare class BrowserTestingModule {
}
/** @experimental */
export declare const browserTestPlatform: () => PlatformRef;
export declare const browserTestingPlatform: (extraProviders?: any[]) => PlatformRef;
/** @deprecated */
export declare const TEST_BROWSER_APPLICATION_PROVIDERS: Array<any>;
/** @experimental */
/** @deprecated */
export declare const TEST_BROWSER_PLATFORM_PROVIDERS: Array<any>;

View File

@ -1,11 +1,11 @@
/** @experimental */
/** @deprecated */
export declare const SERVER_PLATFORM_PROVIDERS: Array<any>;
/** @deprecated */
export declare function serverBootstrap(appComponentType: Type, providers: Array<any>): Promise<ComponentRef<any>>;
export declare function serverBootstrap<T>(appComponentType: ConcreteType<T>, customProviders: Array<any>): Promise<ComponentRef<T>>;
/** @experimental */
export declare const serverDynamicPlatform: () => PlatformRef;
export declare const serverDynamicPlatform: (extraProviders?: any[]) => PlatformRef;
/** @experimental */
export declare const serverPlatform: () => PlatformRef;
export declare const serverPlatform: (extraProviders?: any[]) => PlatformRef;

View File

@ -1,9 +1,9 @@
/** @stable */
export declare class ServerTestModule {
/** @experimental */
export declare class ServerTestingModule {
}
/** @experimental */
export declare const serverTestPlatform: () => PlatformRef;
export declare const serverTestingPlatform: (extraProviders?: any[]) => PlatformRef;
/** @deprecated */
export declare const TEST_SERVER_APPLICATION_PROVIDERS: Array<any>;

View File

@ -135,7 +135,7 @@ export declare class Router {
/** @experimental */ navigated: boolean;
routerState: RouterState;
url: string;
constructor(rootComponentType: Type, resolver: ComponentResolver, urlSerializer: UrlSerializer, outletMap: RouterOutletMap, location: Location, injector: Injector, loader: AppModuleFactoryLoader, config: Routes);
constructor(rootComponentType: Type, resolver: ComponentResolver, urlSerializer: UrlSerializer, outletMap: RouterOutletMap, location: Location, injector: Injector, loader: NgModuleFactoryLoader, config: Routes);
createUrlTree(commands: any[], {relativeTo, queryParams, fragment, preserveQueryParams, preserveFragment}?: NavigationExtras): UrlTree;
dispose(): void;
initialNavigation(): void;
@ -203,6 +203,10 @@ export declare class RouterModule {
constructor(injector: Injector);
}
/** @experimental */
export declare class RouterModuleWithoutProviders {
}
/** @stable */
export declare class RouterOutlet {
activateEvents: EventEmitter<any>;