refactor(core): deprecate coreBootstrap, PLATFORM_PIPES/DIRECTIVES providers and ComponentResolver

BREAKING CHANGE (deprecations)

- Instead of `coreBootstrap`, create an `@AppModule` and use `bootstrapModule`.
- Instead of `coreLoadAndBootstarp`, create an `@AppModule` and use `bootstrapModuleFactory`.
- Instead of `bootstrapWorkerApp`, create an `@AppModule` that includes the `WorkerAppModule` and use `bootstrapModule` with the `workerAppPlatform()`.
- Instead of `bootstrapWorkerUi`, create an @AppModule that includes the `WorkerUiModule` and use `bootstrapModule` with the `workerUiPlatform()` instead.
- Instead of `serverBootstrap`, create an @AppModule and use `bootstrapModule` with the `serverDynamicPlatform()` instead.
- Instead of `PLATFORM_PIPES` and `PLATFORM_DIRECTIVES`, provide platform directives/pipes via an `@AppModule`.
- Instead of `ComponentResolver`:
  - use `ComponentFactoryResolver` together with `@AppModule.precompile`/`@Component.precompile` or `ANALYZE_FOR_PRECOMPILE` provider for dynamic component creation.
  - use `AppModuleFactoryLoader` for lazy loading.
- Instead of `SystemJsComponentResolver`, create an `@AppModule` and use `SystemJsAppModuleLoader`.
- Instead of `SystemJsCmpFactoryResolver`, create an `@AppModule` and use `SystemJsAppModuleFactoryLoader`

Closes #9726
This commit is contained in:
Tobias Bosch
2016-07-08 13:40:54 -07:00
parent 245b0910ed
commit daa9da4047
20 changed files with 167 additions and 76 deletions

View File

@ -6,6 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
import {Console} from '../console';
import {Injectable} from '../di/decorators';
import {PromiseWrapper} from '../facade/async';
import {BaseException} from '../facade/exceptions';
@ -18,9 +19,19 @@ import {ComponentFactory} from './component_factory';
/**
* Low-level service for loading {@link ComponentFactory}s, which
* can later be used to create and render a Component instance.
* @experimental
*
* @deprecated Use {@link ComponentFactoryResolver} together with {@link
* AppModule}.precompile}/{@link Component}.precompile or
* {@link ANALYZE_FOR_PRECOMPILE} provider for dynamic component creation.
* Use {@link AppModuleFactoryLoader} for lazy loading.
*/
export abstract class ComponentResolver {
static DynamicCompilationDeprecationMsg =
'ComponentResolver is deprecated for dynamic compilation. Use ComponentFactoryResolver together with @AppModule/@Component.precompile or ANALYZE_FOR_PRECOMPILE provider instead.';
static LazyLoadingDeprecationMsg =
'ComponentResolver is deprecated for lazy loading. Use AppModuleFactoryLoader instead.';
abstract resolveComponent(component: Type|string): Promise<ComponentFactory<any>>;
abstract clearCache(): void;
}
@ -31,11 +42,13 @@ function _isComponentFactory(type: any): boolean {
@Injectable()
export class ReflectorComponentResolver extends ComponentResolver {
constructor(private _console: Console) { super(); }
resolveComponent(component: Type|string): Promise<ComponentFactory<any>> {
if (isString(component)) {
return PromiseWrapper.reject(
new BaseException(`Cannot resolve component using '${component}'.`), null);
}
this._console.warn(ComponentResolver.DynamicCompilationDeprecationMsg);
var metadatas = reflector.annotations(<Type>component);
var componentFactory = metadatas.find(_isComponentFactory);

View File

@ -6,6 +6,8 @@
* found in the LICENSE file at https://angular.io/license
*/
import {Console} from '../console';
import {Injectable} from '../di';
import {Type, global, isString} from '../facade/lang';
import {ComponentFactory} from './component_factory';
@ -15,13 +17,18 @@ const _SEPARATOR = '#';
/**
* Component resolver that can load components lazily
* @experimental
*
* @deprecated Lazy loading of components is deprecated. Use {@link SystemJsAppModuleLoader} to lazy
* load
* {@link AppModuleFactory}s instead.
*/
@Injectable()
export class SystemJsComponentResolver implements ComponentResolver {
constructor(private _resolver: ComponentResolver) {}
constructor(private _resolver: ComponentResolver, private _console: Console) {}
resolveComponent(componentType: string|Type): Promise<ComponentFactory<any>> {
if (isString(componentType)) {
this._console.warn(ComponentResolver.LazyLoadingDeprecationMsg);
let [module, component] = componentType.split(_SEPARATOR);
if (component === void(0)) {
@ -45,11 +52,17 @@ const FACTORY_CLASS_SUFFIX = 'NgFactory';
/**
* Component resolver that can load component factories lazily
* @experimental
*
* @deprecated Lazy loading of components is deprecated. Use {@link SystemJsAppModuleFactoryLoader}
* to lazy
* load {@link AppModuleFactory}s instead.
*/
@Injectable()
export class SystemJsCmpFactoryResolver implements ComponentResolver {
constructor(private _console: Console) {}
resolveComponent(componentType: string|Type): Promise<ComponentFactory<any>> {
if (isString(componentType)) {
this._console.warn(ComponentResolver.LazyLoadingDeprecationMsg);
let [module, factory] = componentType.split(_SEPARATOR);
return (<any>global)
.System.import(module + FACTORY_MODULE_SUFFIX)