Skip to content

Commit

Permalink
refactor(core): deprecate coreBootstrap, `PLATFORM_PIPES/DIRECTIVES…
Browse files Browse the repository at this point in the history
…` 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
  • Loading branch information
tbosch committed Jul 8, 2016
1 parent 245b091 commit daa9da4
Show file tree
Hide file tree
Showing 20 changed files with 167 additions and 76 deletions.
4 changes: 1 addition & 3 deletions modules/@angular/compiler-cli/src/codegen.ts
Expand Up @@ -132,9 +132,7 @@ export class CodeGenerator {
genDebugInfo: options.debug === true,
defaultEncapsulation: ViewEncapsulation.Emulated,
logBindingUpdate: false,
useJit: false,
platformDirectives: [],
platformPipes: []
useJit: false
});
const normalizer = new DirectiveNormalizer(xhr, urlResolver, htmlParser, config);
const parser = new Parser(new Lexer());
Expand Down
4 changes: 1 addition & 3 deletions modules/@angular/compiler-cli/src/extract_i18n.ts
Expand Up @@ -142,9 +142,7 @@ class Extractor {
genDebugInfo: true,
defaultEncapsulation: ViewEncapsulation.Emulated,
logBindingUpdate: false,
useJit: false,
platformDirectives: [],
platformPipes: []
useJit: false
});
const normalizer = new DirectiveNormalizer(xhr, urlResolver, htmlParser, config);
const parser = new Parser(new Lexer());
Expand Down
8 changes: 4 additions & 4 deletions modules/@angular/compiler/src/compiler.ts
Expand Up @@ -92,8 +92,8 @@ export class _RuntimeCompilerFactory extends CompilerFactory {
const inj = ReflectiveInjector.resolveAndCreate(options.deprecatedAppProviders);
const compilerConfig: CompilerConfig = inj.get(CompilerConfig, null);
if (compilerConfig) {
platformDirectivesFromAppProviders = compilerConfig.platformDirectives;
platformPipesFromAppProviders = compilerConfig.platformPipes;
platformDirectivesFromAppProviders = compilerConfig.deprecatedPlatformDirectives;
platformPipesFromAppProviders = compilerConfig.deprecatedPlatformPipes;
useJitFromAppProviders = compilerConfig.useJit;
useDebugFromAppProviders = compilerConfig.genDebugInfo;
defaultEncapsulationFromAppProviders = compilerConfig.defaultEncapsulation;
Expand Down Expand Up @@ -133,9 +133,9 @@ export class _RuntimeCompilerFactory extends CompilerFactory {
provide: CompilerConfig,
useFactory: (platformDirectives: any[], platformPipes: any[]) => {
return new CompilerConfig({
platformDirectives:
deprecatedPlatformDirectives:
_mergeArrays(platformDirectivesFromAppProviders, platformDirectives),
platformPipes: _mergeArrays(platformPipesFromAppProviders, platformPipes),
deprecatedPlatformPipes: _mergeArrays(platformPipesFromAppProviders, platformPipes),
// let explicit values from the compiler options overwrite options
// from the app providers. E.g. important for the testing platform.
genDebugInfo: _firstDefined(options.useDebug, useDebugFromAppProviders, isDevMode()),
Expand Down
26 changes: 18 additions & 8 deletions modules/@angular/compiler/src/config.ts
Expand Up @@ -19,28 +19,38 @@ export class CompilerConfig {
private _genDebugInfo: boolean;
private _logBindingUpdate: boolean;
public useJit: boolean;
public platformDirectives: any[];
public platformPipes: any[];
/**
* @deprecated Providing platform directives via the {@link CompilerConfig} deprecated. Provide
* platform
* directives via an {@link AppModule} instead.
*/
public deprecatedPlatformDirectives: any[];
/**
* @deprecated Providing platform pipes via the {@link CompilerConfig} deprecated. Provide
* platform pipes
* via an {@link AppModule} instead.
*/
public deprecatedPlatformPipes: any[];

constructor(
{renderTypes = new DefaultRenderTypes(), defaultEncapsulation = ViewEncapsulation.Emulated,
genDebugInfo, logBindingUpdate, useJit = true, platformDirectives = [],
platformPipes = []}: {
genDebugInfo, logBindingUpdate, useJit = true, deprecatedPlatformDirectives = [],
deprecatedPlatformPipes = []}: {
renderTypes?: RenderTypes,
defaultEncapsulation?: ViewEncapsulation,
genDebugInfo?: boolean,
logBindingUpdate?: boolean,
useJit?: boolean,
platformDirectives?: any[],
platformPipes?: any[]
deprecatedPlatformDirectives?: any[],
deprecatedPlatformPipes?: any[]
} = {}) {
this.renderTypes = renderTypes;
this.defaultEncapsulation = defaultEncapsulation;
this._genDebugInfo = genDebugInfo;
this._logBindingUpdate = logBindingUpdate;
this.useJit = useJit;
this.platformDirectives = platformDirectives;
this.platformPipes = platformPipes;
this.deprecatedPlatformDirectives = deprecatedPlatformDirectives;
this.deprecatedPlatformPipes = deprecatedPlatformPipes;
}

get genDebugInfo(): boolean {
Expand Down
4 changes: 2 additions & 2 deletions modules/@angular/compiler/src/metadata_resolver.ts
Expand Up @@ -301,7 +301,7 @@ export class CompileMetadataResolver {

getViewDirectivesMetadata(component: Type): cpl.CompileDirectiveMetadata[] {
var view = this._viewResolver.resolve(component);
var directives = flattenDirectives(view, this._config.platformDirectives);
var directives = flattenDirectives(view, this._config.deprecatedPlatformDirectives);
for (var i = 0; i < directives.length; i++) {
if (!isValidType(directives[i])) {
throw new BaseException(
Expand All @@ -313,7 +313,7 @@ export class CompileMetadataResolver {

getViewPipesMetadata(component: Type): cpl.CompilePipeMetadata[] {
var view = this._viewResolver.resolve(component);
var pipes = flattenPipes(view, this._config.platformPipes);
var pipes = flattenPipes(view, this._config.deprecatedPlatformPipes);
for (var i = 0; i < pipes.length; i++) {
if (!isValidType(pipes[i])) {
throw new BaseException(
Expand Down
24 changes: 23 additions & 1 deletion modules/@angular/compiler/src/runtime_compiler.ts
Expand Up @@ -7,6 +7,7 @@
*/

import {AppModuleFactory, AppModuleMetadata, Compiler, ComponentFactory, ComponentResolver, ComponentStillLoadingError, Injectable, Injector, OptionalMetadata, Provider, SkipSelfMetadata} from '@angular/core';
import {Console} from '../core_private';

import {BaseException} from '../src/facade/exceptions';
import {ConcreteType, IS_DART, Type, isBlank, isString, stringify} from '../src/facade/lang';
Expand Down Expand Up @@ -42,11 +43,28 @@ export class RuntimeCompiler implements ComponentResolver, Compiler {
private _compiledHostTemplateCache = new Map<Type, CompiledTemplate>();
private _compiledAppModuleCache = new Map<Type, AppModuleFactory<any>>();

private _warnOnComponentResolver = true;

constructor(
private _injector: Injector, private _metadataResolver: CompileMetadataResolver,
private _templateNormalizer: DirectiveNormalizer, private _templateParser: TemplateParser,
private _styleCompiler: StyleCompiler, private _viewCompiler: ViewCompiler,
private _appModuleCompiler: AppModuleCompiler, private _genConfig: CompilerConfig) {}
private _appModuleCompiler: AppModuleCompiler, private _genConfig: CompilerConfig,
private _console: Console) {
const flatDeprecatedPlatformDirectives =
ListWrapper.flatten(_genConfig.deprecatedPlatformDirectives);
if (flatDeprecatedPlatformDirectives.length > 0) {
this._console.warn(
`Providing platform directives via the PLATFORM_DIRECTIVES provider or the "CompilerConfig" is deprecated. Provide platform directives via an @AppModule instead. Directives: ` +
flatDeprecatedPlatformDirectives.map(stringify));
}
const flatDeprecatedPlatformPipes = ListWrapper.flatten(_genConfig.deprecatedPlatformPipes);
if (flatDeprecatedPlatformPipes.length > 0) {
this._console.warn(
`Providing platform pipes via the PLATFORM_PIPES provider or the "CompilerConfig" is deprecated. Provide platform pipes via an @AppModule instead. Pipes: ` +
flatDeprecatedPlatformPipes.map(stringify));
}
}

get injector(): Injector { return this._injector; }

Expand All @@ -55,6 +73,10 @@ export class RuntimeCompiler implements ComponentResolver, Compiler {
return PromiseWrapper.reject(
new BaseException(`Cannot resolve component using '${component}'.`), null);
}
if (this._warnOnComponentResolver) {
this._console.warn(ComponentResolver.DynamicCompilationDeprecationMsg);
this._warnOnComponentResolver = false;
}
return this.compileComponentAsync(<ConcreteType<any>>component);
}

Expand Down
4 changes: 2 additions & 2 deletions modules/@angular/compiler/test/metadata_resolver_spec.ts
Expand Up @@ -115,8 +115,8 @@ export function main() {
configureCompiler({
providers: [{
provide: CompilerConfig,
useValue:
new CompilerConfig({genDebugInfo: true, platformDirectives: [ADirective]})
useValue: new CompilerConfig(
{genDebugInfo: true, deprecatedPlatformDirectives: [ADirective]})
}]
});
});
Expand Down
8 changes: 6 additions & 2 deletions modules/@angular/core/src/application_ref.ts
Expand Up @@ -235,10 +235,12 @@ export function bootstrapModule<M>(
* Shortcut for ApplicationRef.bootstrap.
* Requires a platform to be created first.
*
* @experimental APIs related to application bootstrap are currently under review.
* @deprecated Use {@link bootstrapModuleFactory} instead.
*/
export function coreBootstrap<C>(
componentFactory: ComponentFactory<C>, injector: Injector): ComponentRef<C> {
let console = injector.get(Console);
console.warn('coreBootstrap is deprecated. Use bootstrapModuleFactory instead.');
var appRef: ApplicationRef = injector.get(ApplicationRef);
return appRef.bootstrap(componentFactory);
}
Expand All @@ -248,10 +250,12 @@ export function coreBootstrap<C>(
* waits for asynchronous initializers and bootstraps the component.
* Requires a platform to be created first.
*
* @experimental APIs related to application bootstrap are currently under review.
* @deprecated Use {@link bootstrapModule} instead.
*/
export function coreLoadAndBootstrap(
componentType: Type, injector: Injector): Promise<ComponentRef<any>> {
let console = injector.get(Console);
console.warn('coreLoadAndBootstrap is deprecated. Use bootstrapModule instead.');
var appRef: ApplicationRef = injector.get(ApplicationRef);
return appRef.run(() => {
var componentResolver: ComponentResolver = injector.get(ComponentResolver);
Expand Down
15 changes: 14 additions & 1 deletion modules/@angular/core/src/linker/component_resolver.ts
Expand Up @@ -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';
Expand All @@ -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;
}
Expand All @@ -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);
Expand Down
19 changes: 16 additions & 3 deletions modules/@angular/core/src/linker/systemjs_component_resolver.ts
Expand Up @@ -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';
Expand All @@ -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)) {
Expand All @@ -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)
Expand Down
12 changes: 7 additions & 5 deletions modules/@angular/core/src/platform_directives_and_pipes.ts
Expand Up @@ -9,7 +9,7 @@
import {OpaqueToken} from './di';

/**
A token that can be provided when bootstrapping an application to make an array of directives
* A token that can be provided when bootstrapping an application to make an array of directives
* available in every component of the application.
*
* ### Example
Expand All @@ -32,9 +32,10 @@ import {OpaqueToken} from './di';
* bootstrap(MyComponent, [{provide: PLATFORM_DIRECTIVES, useValue: [OtherDirective],
multi:true}]);
* ```
* @stable
*
* @deprecated Providing platform directives via a provider is deprecated. Provide platform
* directives via an {@link AppModule} instead.
*/

export const PLATFORM_DIRECTIVES: OpaqueToken =
/*@ts2dart_const*/ new OpaqueToken('Platform Directives');

Expand All @@ -60,7 +61,8 @@ export const PLATFORM_DIRECTIVES: OpaqueToken =
*
* bootstrap(MyComponent, [{provide: PLATFORM_PIPES, useValue: [OtherPipe], multi:true}]);
* ```
* @stable
*
* @deprecated Providing platform pipes via a provider is deprecated. Provide platform pipes via an
* {@link AppModule} instead.
*/

export const PLATFORM_PIPES: OpaqueToken = /*@ts2dart_const*/ new OpaqueToken('Platform Pipes');
Expand Up @@ -12,6 +12,12 @@ import {ComponentResolver, ReflectorComponentResolver} from '@angular/core/src/l
import {ReflectionInfo, reflector} from '@angular/core/src/reflection/reflection';
import {afterEach, beforeEach, beforeEachProviders, ddescribe, describe, expect, iit, inject, it, xdescribe, xit} from '@angular/core/testing/testing_internal';
import {AsyncTestCompleter} from '@angular/core/testing/testing_internal';
import {Console} from '../../src/console';

class DummyConsole implements Console {
log(message: string) {}
warn(message: string) {}
}

export function main() {
describe('Compiler', () => {
Expand All @@ -21,7 +27,7 @@ export function main() {
beforeEach(() => {
someCompFactory = new ComponentFactory(null, null, null);
reflector.registerType(SomeComponent, new ReflectionInfo([someCompFactory]));
compiler = new ReflectorComponentResolver();
compiler = new ReflectorComponentResolver(new DummyConsole());
});

it('should read the template from an annotation',
Expand Down

0 comments on commit daa9da4

Please sign in to comment.