refactor(compiler): make PLATFORM_PIPES / PLATFORM_DIRECTIVES an option on CompilerConfig

This aligns the configuration of platform pipes / directives with offline compilation.

BREAKING CHANGE:
- `PLATFORM_PIPES` and `PLATFORM_DIRECTIVES` now are fields on `CompilerConfig`. 
  Instead of providing a binding to these tokens, provide a binding for `CompilerConfig` instead.
This commit is contained in:
Tobias Bosch
2016-06-13 08:35:31 -07:00
parent 1fb0db4aeb
commit 1745366530
9 changed files with 43 additions and 81 deletions

View File

@ -1,6 +1,6 @@
import {COMMON_DIRECTIVES, COMMON_PIPES, FORM_PROVIDERS, PlatformLocation} from '@angular/common';
import {COMPILER_PROVIDERS, XHR} from '@angular/compiler';
import {APPLICATION_COMMON_PROVIDERS, ComponentRef, ExceptionHandler, OpaqueToken, PLATFORM_COMMON_PROVIDERS, PLATFORM_DIRECTIVES, PLATFORM_INITIALIZER, PLATFORM_PIPES, PlatformRef, ReflectiveInjector, RootRenderer, Testability, Type, assertPlatform, coreLoadAndBootstrap, createPlatform, getPlatform} from '@angular/core';
import {COMPILER_PROVIDERS, CompilerConfig, XHR} from '@angular/compiler';
import {APPLICATION_COMMON_PROVIDERS, ComponentRef, ExceptionHandler, OpaqueToken, PLATFORM_COMMON_PROVIDERS, PLATFORM_INITIALIZER, PlatformRef, ReflectiveInjector, RootRenderer, Testability, Type, assertPlatform, coreLoadAndBootstrap, createPlatform, getPlatform} from '@angular/core';
import {AnimationDriver, NoOpAnimationDriver, ReflectionCapabilities, SanitizationService, reflector, wtfInit} from '../core_private';
import {WebAnimationsDriver} from '../src/dom/web_animations_driver';
@ -17,7 +17,7 @@ import {EVENT_MANAGER_PLUGINS, EventManager} from './dom/events/event_manager';
import {HAMMER_GESTURE_CONFIG, HammerGestureConfig, HammerGesturesPlugin} from './dom/events/hammer_gestures';
import {KeyEventsPlugin} from './dom/events/key_events';
import {DomSharedStylesHost, SharedStylesHost} from './dom/shared_styles_host';
import {isBlank, isPresent} from './facade/lang';
import {assertionsEnabled, isBlank, isPresent} from './facade/lang';
import {DomSanitizationService, DomSanitizationServiceImpl} from './security/dom_sanitization_service';
import {CachedXHR} from './xhr/xhr_cache';
import {XHRImpl} from './xhr/xhr_impl';
@ -50,8 +50,6 @@ export const BROWSER_SANITIZATION_PROVIDERS: Array<any> = [
*/
export const BROWSER_APP_PROVIDERS: Array<any /*Type | Provider | any[]*/> = [
APPLICATION_COMMON_PROVIDERS, FORM_PROVIDERS, BROWSER_SANITIZATION_PROVIDERS,
{provide: PLATFORM_PIPES, useValue: COMMON_PIPES, multi: true},
{provide: PLATFORM_DIRECTIVES, useValue: COMMON_DIRECTIVES, multi: true},
{provide: ExceptionHandler, useFactory: _exceptionHandler, deps: []},
{provide: DOCUMENT, useFactory: _document, deps: []},
{provide: EVENT_MANAGER_PLUGINS, useClass: DomEventsPlugin, multi: true},
@ -65,8 +63,14 @@ export const BROWSER_APP_PROVIDERS: Array<any /*Type | Provider | any[]*/> = [
Testability, EventManager, ELEMENT_PROBE_PROVIDERS
];
function _createCompilerConfig() {
return new CompilerConfig(
assertionsEnabled(), false, true, null, null, COMMON_DIRECTIVES, COMMON_PIPES);
}
export const BROWSER_APP_COMPILER_PROVIDERS: Array<any /*Type | Provider | any[]*/> = [
COMPILER_PROVIDERS,
{provide: CompilerConfig, useFactory: _createCompilerConfig, deps: []},
{provide: XHR, useClass: XHRImpl},
];

View File

@ -1,9 +1,9 @@
import {COMMON_DIRECTIVES, COMMON_PIPES, FORM_PROVIDERS} from '@angular/common';
import {COMPILER_PROVIDERS, XHR} from '@angular/compiler';
import {APPLICATION_COMMON_PROVIDERS, APP_INITIALIZER, ComponentRef, ExceptionHandler, NgZone, OpaqueToken, PLATFORM_COMMON_PROVIDERS, PLATFORM_DIRECTIVES, PLATFORM_PIPES, PlatformRef, ReflectiveInjector, RootRenderer, Type, assertPlatform, coreLoadAndBootstrap, createPlatform, getPlatform} from '@angular/core';
import {COMPILER_PROVIDERS, CompilerConfig, XHR} from '@angular/compiler';
import {APPLICATION_COMMON_PROVIDERS, APP_INITIALIZER, ComponentRef, ExceptionHandler, NgZone, OpaqueToken, PLATFORM_COMMON_PROVIDERS, PlatformRef, ReflectiveInjector, RootRenderer, Type, assertPlatform, coreLoadAndBootstrap, createPlatform, getPlatform} from '@angular/core';
import {BROWSER_SANITIZATION_PROVIDERS} from './browser';
import {isBlank, isPresent, print} from './facade/lang';
import {assertionsEnabled, isBlank, isPresent, print} from './facade/lang';
import {ON_WEB_WORKER} from './web_workers/shared/api';
import {ClientMessageBrokerFactory, ClientMessageBrokerFactory_} from './web_workers/shared/client_message_broker';
import {MessageBus} from './web_workers/shared/message_bus';
@ -29,8 +29,6 @@ export const WORKER_APP_PLATFORM_PROVIDERS: Array<any /*Type | Provider | any[]*
export const WORKER_APP_APPLICATION_PROVIDERS: Array<any /*Type | Provider | any[]*/> = [
APPLICATION_COMMON_PROVIDERS, FORM_PROVIDERS, BROWSER_SANITIZATION_PROVIDERS, Serializer,
{provide: PLATFORM_PIPES, useValue: COMMON_PIPES, multi: true},
{provide: PLATFORM_DIRECTIVES, useValue: COMMON_DIRECTIVES, multi: true},
{provide: ClientMessageBrokerFactory, useClass: ClientMessageBrokerFactory_},
{provide: ServiceMessageBrokerFactory, useClass: ServiceMessageBrokerFactory_},
WebWorkerRootRenderer, {provide: RootRenderer, useExisting: WebWorkerRootRenderer},
@ -47,12 +45,23 @@ export function workerAppPlatform(): PlatformRef {
return assertPlatform(WORKER_APP_PLATFORM_MARKER);
}
function _createCompilerConfig() {
return new CompilerConfig(
assertionsEnabled(), false, true, null, null, COMMON_DIRECTIVES, COMMON_PIPES);
}
export const WORKER_APP_COMPILER_PROVIDERS: Array<any /*Type | Provider | any[]*/> = [
COMPILER_PROVIDERS,
{provide: CompilerConfig, useFactory: _createCompilerConfig, deps: []},
{provide: XHR, useClass: XHRImpl},
];
export function bootstrapApp(
appComponentType: Type,
customProviders?: Array<any /*Type | Provider | any[]*/>): Promise<ComponentRef<any>> {
var appInjector = ReflectiveInjector.resolveAndCreate(
[
WORKER_APP_APPLICATION_PROVIDERS, COMPILER_PROVIDERS, {provide: XHR, useClass: XHRImpl},
WORKER_APP_APPLICATION_PROVIDERS, WORKER_APP_COMPILER_PROVIDERS,
isPresent(customProviders) ? customProviders : []
],
workerAppPlatform().injector);