diff --git a/modules/@angular/common/test/directives/ng_if_spec.ts b/modules/@angular/common/test/directives/ng_if_spec.ts index 0a561f126b..4e780cc917 100644 --- a/modules/@angular/common/test/directives/ng_if_spec.ts +++ b/modules/@angular/common/test/directives/ng_if_spec.ts @@ -8,7 +8,7 @@ import { xit, } from '@angular/core/testing/testing_internal'; import {expect} from '@angular/platform-browser/testing'; -import {TestComponentBuilder, ComponentFixture} from '@angular/compiler/testing'; +import {TestComponentBuilder} from '@angular/compiler/testing'; import {AsyncTestCompleter} from '@angular/core/testing/testing_internal'; import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter'; diff --git a/modules/@angular/compiler_cli/integrationtest/src/bootstrap.ts b/modules/@angular/compiler_cli/integrationtest/src/bootstrap.ts index b9021ceb51..ae7d4f5689 100644 --- a/modules/@angular/compiler_cli/integrationtest/src/bootstrap.ts +++ b/modules/@angular/compiler_cli/integrationtest/src/bootstrap.ts @@ -1,8 +1,8 @@ import {coreBootstrap, ReflectiveInjector} from '@angular/core'; -import {browserPlatform, BROWSER_APP_STATIC_PROVIDERS} from '@angular/platform-browser'; +import {browserPlatform, BROWSER_APP_PROVIDERS} from '@angular/platform-browser'; import {BasicNgFactory} from './basic.ngfactory'; import {Basic} from './basic'; const appInjector = - ReflectiveInjector.resolveAndCreate(BROWSER_APP_STATIC_PROVIDERS, browserPlatform().injector); + ReflectiveInjector.resolveAndCreate(BROWSER_APP_PROVIDERS, browserPlatform().injector); coreBootstrap(BasicNgFactory, appInjector); diff --git a/modules/@angular/compiler_cli/integrationtest/test/basic_spec.ts b/modules/@angular/compiler_cli/integrationtest/test/basic_spec.ts index 97a310cd46..2f42c0b338 100644 --- a/modules/@angular/compiler_cli/integrationtest/test/basic_spec.ts +++ b/modules/@angular/compiler_cli/integrationtest/test/basic_spec.ts @@ -3,7 +3,7 @@ import * as path from 'path'; import {BasicNgFactory} from '../src/basic.ngfactory'; import {MyComp} from '../src/a/multiple_components'; import {ReflectiveInjector, DebugElement, getDebugNode} from '@angular/core'; -import {browserPlatform, BROWSER_APP_STATIC_PROVIDERS} from '@angular/platform-browser'; +import {browserPlatform, BROWSER_APP_PROVIDERS} from '@angular/platform-browser'; describe("template codegen output", () => { const outDir = path.join('dist', 'all', '@angular', 'compiler_cli', 'integrationtest', 'src'); @@ -29,14 +29,14 @@ describe("template codegen output", () => { }); it("should be able to create the basic component", () => { - const appInjector = ReflectiveInjector.resolveAndCreate(BROWSER_APP_STATIC_PROVIDERS, + const appInjector = ReflectiveInjector.resolveAndCreate(BROWSER_APP_PROVIDERS, browserPlatform().injector); var comp = BasicNgFactory.create(appInjector); expect(comp.instance).toBeTruthy(); }); it("should support ngIf", () => { - const appInjector = ReflectiveInjector.resolveAndCreate(BROWSER_APP_STATIC_PROVIDERS, + const appInjector = ReflectiveInjector.resolveAndCreate(BROWSER_APP_PROVIDERS, browserPlatform().injector); var comp = BasicNgFactory.create(appInjector); var debugElement = getDebugNode(comp.location.nativeElement); @@ -49,7 +49,7 @@ describe("template codegen output", () => { }); it("should support ngFor", () => { - const appInjector = ReflectiveInjector.resolveAndCreate(BROWSER_APP_STATIC_PROVIDERS, + const appInjector = ReflectiveInjector.resolveAndCreate(BROWSER_APP_PROVIDERS, browserPlatform().injector); var comp = BasicNgFactory.create(appInjector); var debugElement = getDebugNode(comp.location.nativeElement); diff --git a/modules/@angular/compiler_cli/integrationtest/test/projection_spec.ts b/modules/@angular/compiler_cli/integrationtest/test/projection_spec.ts index 5c34ad2212..baa634cfa5 100644 --- a/modules/@angular/compiler_cli/integrationtest/test/projection_spec.ts +++ b/modules/@angular/compiler_cli/integrationtest/test/projection_spec.ts @@ -1,12 +1,11 @@ import {MainCompNgFactory} from '../src/projection.ngfactory'; import {CompWithProjection} from '../src/projection'; import {ReflectiveInjector, DebugElement, getDebugNode} from '@angular/core'; -import {browserPlatform, BROWSER_APP_STATIC_PROVIDERS, By} from '@angular/platform-browser'; +import {browserPlatform, BROWSER_APP_PROVIDERS, By} from '@angular/platform-browser'; describe("content projection", () => { it("should support basic content projection", () => { - const appInjector = ReflectiveInjector.resolveAndCreate(BROWSER_APP_STATIC_PROVIDERS, - browserPlatform().injector); + const appInjector = ReflectiveInjector.resolveAndCreate(BROWSER_APP_PROVIDERS, browserPlatform().injector); var mainComp = MainCompNgFactory.create(appInjector); var debugElement = getDebugNode(mainComp.location.nativeElement); diff --git a/modules/@angular/examples/core/ts/platform/platform.ts b/modules/@angular/examples/core/ts/platform/platform.ts index ec75ab1192..68e59ccbe0 100644 --- a/modules/@angular/examples/core/ts/platform/platform.ts +++ b/modules/@angular/examples/core/ts/platform/platform.ts @@ -1,5 +1,5 @@ import {Component, createPlatform, coreLoadAndBootstrap, ReflectiveInjector} from '@angular/core'; -import {BROWSER_PLATFORM_PROVIDERS, BROWSER_APP_STATIC_PROVIDERS} from '@angular/platform-browser'; +import {BROWSER_PLATFORM_PROVIDERS, BROWSER_APP_PROVIDERS} from '@angular/platform-browser'; var appProviders: any[] = []; @@ -9,7 +9,6 @@ class MyApp { } var platform = createPlatform(ReflectiveInjector.resolveAndCreate(BROWSER_PLATFORM_PROVIDERS)); -var appInjector = ReflectiveInjector.resolveAndCreate([BROWSER_APP_STATIC_PROVIDERS, appProviders], - platform.injector); +var appInjector = ReflectiveInjector.resolveAndCreate([BROWSER_APP_PROVIDERS, appProviders], platform.injector); coreLoadAndBootstrap(MyApp, appInjector); // #enddocregion diff --git a/modules/@angular/integration_test/public_api_spec.ts b/modules/@angular/integration_test/public_api_spec.ts index c46a9bae6d..34296ad4dc 100644 --- a/modules/@angular/integration_test/public_api_spec.ts +++ b/modules/@angular/integration_test/public_api_spec.ts @@ -370,12 +370,8 @@ var PLATFORM_BROWSER: string[] = [ 'bootstrap', 'bootstrapApp', 'bootstrapRender', - 'bootstrapStatic', - 'bootstrapStaticApp', - 'bootstrapStaticRender', - 'BROWSER_APP_COMMON_PROVIDERS', 'BROWSER_APP_PROVIDERS', - 'BROWSER_APP_STATIC_PROVIDERS', + 'BROWSER_APP_COMPILER_PROVIDERS', 'BROWSER_PLATFORM_PROVIDERS', 'BROWSER_SANITIZATION_PROVIDERS', 'browserPlatform', @@ -408,18 +404,13 @@ var PLATFORM_BROWSER: string[] = [ 'UrlChangeEvent:dart', 'UrlChangeListener:dart', 'WebWorkerInstance', - 'WORKER_APP_APPLICATION_COMMON_PROVIDERS', 'WORKER_APP_APPLICATION_PROVIDERS', 'WORKER_APP_LOCATION_PROVIDERS', 'WORKER_APP_PLATFORM_PROVIDERS', - 'WORKER_APP_STATIC_APPLICATION_PROVIDERS', - 'WORKER_RENDER_APPLICATION_COMMON_PROVIDERS', - 'WORKER_RENDER_APPLICATION_PROVIDERS', 'WORKER_RENDER_APPLICATION_PROVIDERS', 'WORKER_RENDER_LOCATION_PROVIDERS', 'WORKER_RENDER_PLATFORM_PROVIDERS', 'WORKER_RENDER_STARTABLE_MESSAGING_SERVICE', - 'WORKER_RENDER_STATIC_APPLICATION_PROVIDERS', 'WORKER_SCRIPT', 'workerAppPlatform', 'workerRenderPlatform' diff --git a/modules/@angular/platform-browser/index.ts b/modules/@angular/platform-browser/index.ts index 3a469db2b7..dd424be5ae 100644 --- a/modules/@angular/platform-browser/index.ts +++ b/modules/@angular/platform-browser/index.ts @@ -20,9 +20,7 @@ export { SecurityContext } from './src/security/dom_sanitization_service'; -export * from './src/platform/common/browser'; -export * from './src/platform/static/browser'; -export * from './src/platform/dynamic/browser'; +export * from './src/browser'; // Web Workers export { @@ -41,12 +39,8 @@ export * from './src/web_workers/shared/message_bus'; export {WORKER_APP_LOCATION_PROVIDERS} from './src/web_workers/worker/location_providers'; export {WORKER_RENDER_LOCATION_PROVIDERS} from './src/web_workers/ui/location_providers'; -export * from './src/platform/common/worker_render'; -export * from './src/platform/common/worker_app'; -export * from './src/platform/dynamic/worker_render'; -export * from './src/platform/dynamic/worker_app'; -export * from './src/platform/static/worker_render'; -export * from './src/platform/static/worker_app'; +export * from './src/worker_render'; +export * from './src/worker_app'; export * from './private_export'; diff --git a/modules/@angular/platform-browser/private_export.ts b/modules/@angular/platform-browser/private_export.ts index e33dd19e0a..2b1dbe40cb 100644 --- a/modules/@angular/platform-browser/private_export.ts +++ b/modules/@angular/platform-browser/private_export.ts @@ -1,11 +1,4 @@ -import * as animation_builder from './src/animate/animation_builder'; -import * as css_animation_builder from './src/animate/css_animation_builder'; -import * as browser_details from './src/animate/browser_details'; -import * as css_animation_options from './src/animate/css_animation_options'; -import * as animation from './src/animate/animation'; import * as dom_adapter from './src/dom/dom_adapter'; -import * as browser_adapter from './src/browser/browser_adapter'; -import * as browser_common from './src/platform/common/browser'; export namespace __platform_browser_private__ { export type DomAdapter = dom_adapter.DomAdapter; diff --git a/modules/@angular/platform-browser/src/browser.ts b/modules/@angular/platform-browser/src/browser.ts new file mode 100644 index 0000000000..c496ca77d2 --- /dev/null +++ b/modules/@angular/platform-browser/src/browser.ts @@ -0,0 +1,200 @@ +import { + PLATFORM_INITIALIZER, + PLATFORM_DIRECTIVES, + PLATFORM_PIPES, + ExceptionHandler, + RootRenderer, + APPLICATION_COMMON_PROVIDERS, + PLATFORM_COMMON_PROVIDERS, + OpaqueToken, + Testability, + PlatformRef, + getPlatform, + createPlatform, + assertPlatform, + ReflectiveInjector, + reflector, + coreLoadAndBootstrap, + Type, + ComponentRef +} from "@angular/core"; +import {isBlank, isPresent} from "./facade/lang"; +import {wtfInit, SanitizationService, ReflectionCapabilities} from "../core_private"; +import {COMMON_DIRECTIVES, COMMON_PIPES, FORM_PROVIDERS, PlatformLocation} from "@angular/common"; +import {DomSanitizationService, DomSanitizationServiceImpl} from "./security/dom_sanitization_service"; +import {BrowserDomAdapter} from "./browser/browser_adapter"; +import {BrowserGetTestability} from "./browser/testability"; +import {getDOM} from "./dom/dom_adapter"; +import {DOCUMENT} from "./dom/dom_tokens"; +import {EVENT_MANAGER_PLUGINS, EventManager} from "./dom/events/event_manager"; +import {DomRootRenderer, DomRootRenderer_} from "./dom/dom_renderer"; +import {SharedStylesHost, DomSharedStylesHost} from "./dom/shared_styles_host"; +import {KeyEventsPlugin} from "./dom/events/key_events"; +import {ELEMENT_PROBE_PROVIDERS} from "./dom/debug/ng_probe"; +import {DomEventsPlugin} from "./dom/events/dom_events"; +import {HAMMER_GESTURE_CONFIG, HammerGestureConfig, HammerGesturesPlugin} from "./dom/events/hammer_gestures"; +import {AnimationBuilder} from "./animate/animation_builder"; +import {BrowserDetails} from "./animate/browser_details"; +import {BrowserPlatformLocation} from "./browser/location/browser_platform_location"; +import {COMPILER_PROVIDERS, XHR} from "@angular/compiler"; +import {CachedXHR} from "./xhr/xhr_cache"; +import {XHRImpl} from "./xhr/xhr_impl"; + +export const CACHED_TEMPLATE_PROVIDER: Array = + [{provide: XHR, useClass: CachedXHR}]; + +const BROWSER_PLATFORM_MARKER = new OpaqueToken('BrowserPlatformMarker'); + +/** + * A set of providers to initialize the Angular platform in a web browser. + * + * Used automatically by `bootstrap`, or can be passed to {@link platform}. + */ +export const BROWSER_PLATFORM_PROVIDERS: Array = [ + {provide: BROWSER_PLATFORM_MARKER, useValue: true}, + PLATFORM_COMMON_PROVIDERS, + {provide: PLATFORM_INITIALIZER, useValue: initDomAdapter, multi: true}, + {provide: PlatformLocation, useClass: BrowserPlatformLocation} +]; + +export const BROWSER_SANITIZATION_PROVIDERS: Array = [ + {provide: SanitizationService, useExisting: DomSanitizationService}, + {provide: DomSanitizationService, useClass: DomSanitizationServiceImpl}, +]; + +/** + * A set of providers to initialize an Angular application in a web browser. + * + * Used automatically by `bootstrap`, or can be passed to {@link PlatformRef.application}. + */ +export const BROWSER_APP_PROVIDERS: Array = + [ + 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}, + {provide: EVENT_MANAGER_PLUGINS, useClass: KeyEventsPlugin, multi: true}, + {provide: EVENT_MANAGER_PLUGINS, useClass: HammerGesturesPlugin, multi: true}, + {provide: HAMMER_GESTURE_CONFIG, useClass: HammerGestureConfig}, + {provide: DomRootRenderer, useClass: DomRootRenderer_}, + {provide: RootRenderer, useExisting: DomRootRenderer}, + {provide: SharedStylesHost, useExisting: DomSharedStylesHost}, + DomSharedStylesHost, + Testability, + BrowserDetails, + AnimationBuilder, + EventManager, + ELEMENT_PROBE_PROVIDERS + ]; + +export const BROWSER_APP_COMPILER_PROVIDERS: Array = + [ + COMPILER_PROVIDERS, + {provide: XHR, useClass: XHRImpl}, + ]; + +export function browserPlatform(): PlatformRef { + if (isBlank(getPlatform())) { + createPlatform(ReflectiveInjector.resolveAndCreate(BROWSER_PLATFORM_PROVIDERS)); + } + return assertPlatform(BROWSER_PLATFORM_MARKER); +} + +/** + * Bootstrapping for Angular applications. + * + * You instantiate an Angular application by explicitly specifying a component to use + * as the root component for your application via the `bootstrap()` method. + * + * ## Simple Example + * + * Assuming this `index.html`: + * + * ```html + * + * + * + * loading... + * + * + * ``` + * + * An application is bootstrapped inside an existing browser DOM, typically `index.html`. + * Unlike Angular 1, Angular 2 does not compile/process providers in `index.html`. This is + * mainly for security reasons, as well as architectural changes in Angular 2. This means + * that `index.html` can safely be processed using server-side technologies such as + * providers. Bindings can thus use double-curly `{{ syntax }}` without collision from + * Angular 2 component double-curly `{{ syntax }}`. + * + * We can use this script code: + * + * {@example core/ts/bootstrap/bootstrap.ts region='bootstrap'} + * + * When the app developer invokes `bootstrap()` with the root component `MyApp` as its + * argument, Angular performs the following tasks: + * + * 1. It uses the component's `selector` property to locate the DOM element which needs + * to be upgraded into the angular component. + * 2. It creates a new child injector (from the platform injector). Optionally, you can + * also override the injector configuration for an app by invoking `bootstrap` with the + * `componentInjectableBindings` argument. + * 3. It creates a new `Zone` and connects it to the angular application's change detection + * domain instance. + * 4. It creates an emulated or shadow DOM on the selected component's host element and loads the + * template into it. + * 5. It instantiates the specified component. + * 6. Finally, Angular performs change detection to apply the initial data providers for the + * application. + * + * + * ## Bootstrapping Multiple Applications + * + * When working within a browser window, there are many singleton resources: cookies, title, + * location, and others. Angular services that represent these resources must likewise be + * shared across all Angular applications that occupy the same browser window. For this + * reason, Angular creates exactly one global platform object which stores all shared + * services, and each angular application injector has the platform injector as its parent. + * + * Each application has its own private injector as well. When there are multiple + * applications on a page, Angular treats each application injector's services as private + * to that application. + * + * ## API + * + * - `appComponentType`: The root component which should act as the application. This is + * a reference to a `Type` which is annotated with `@Component(...)`. + * - `customProviders`: An additional set of providers that can be added to the + * app injector to override default injection behavior. + * + * Returns a `Promise` of {@link ComponentRef}. + */ +export function bootstrap( + appComponentType: Type, + customProviders?: Array): Promise> { + reflector.reflectionCapabilities = new ReflectionCapabilities(); + let providers = [ + BROWSER_APP_PROVIDERS, + BROWSER_APP_COMPILER_PROVIDERS, + isPresent(customProviders) ? customProviders : [] + ]; + var appInjector = ReflectiveInjector.resolveAndCreate(providers, browserPlatform().injector); + return coreLoadAndBootstrap(appComponentType, appInjector); +} + +function initDomAdapter() { + BrowserDomAdapter.makeCurrent(); + wtfInit(); + BrowserGetTestability.init(); +} + +function _exceptionHandler(): ExceptionHandler { + return new ExceptionHandler(getDOM()); +} + +function _document(): any { + return getDOM().defaultDoc(); +} diff --git a/modules/@angular/platform-browser/src/dom/debug/ng_probe.ts b/modules/@angular/platform-browser/src/dom/debug/ng_probe.ts index 8c23d79202..893b3c6c95 100644 --- a/modules/@angular/platform-browser/src/dom/debug/ng_probe.ts +++ b/modules/@angular/platform-browser/src/dom/debug/ng_probe.ts @@ -12,7 +12,7 @@ import {getDOM} from '../dom_adapter'; import {DomRootRenderer} from '../dom_renderer'; -const CORE_TOKENS = /*@ts2dart_const*/ {'ApplicationRef': ApplicationRef, 'NgZone': NgZone}; +const CORE_TOKENS = {'ApplicationRef': ApplicationRef, 'NgZone': NgZone}; const INSPECT_GLOBAL_NAME = 'ng.probe'; const CORE_TOKENS_GLOBAL_NAME = 'ng.coreTokens'; @@ -42,16 +42,16 @@ function _createRootRenderer(rootRenderer) { /** * Providers which support debugging Angular applications (e.g. via `ng.probe`). */ -export const ELEMENT_PROBE_PROVIDERS: any[] = /*@ts2dart_const*/[ - /*@ts2dart_Provider*/ { +export const ELEMENT_PROBE_PROVIDERS: any[] = [ + { provide: RootRenderer, useFactory: _createConditionalRootRenderer, deps: [DomRootRenderer] } ]; -export const ELEMENT_PROBE_PROVIDERS_PROD_MODE: any[] = /*@ts2dart_const*/[ - /*@ts2dart_Provider*/ { +export const ELEMENT_PROBE_PROVIDERS_PROD_MODE: any[] = [ + { provide: RootRenderer, useFactory: _createRootRenderer, deps: [DomRootRenderer] diff --git a/modules/@angular/platform-browser/src/dom/dom_renderer.ts b/modules/@angular/platform-browser/src/dom/dom_renderer.ts index 840fa6de7a..550339cc9b 100644 --- a/modules/@angular/platform-browser/src/dom/dom_renderer.ts +++ b/modules/@angular/platform-browser/src/dom/dom_renderer.ts @@ -28,7 +28,6 @@ import {getDOM} from './dom_adapter'; import {camelCaseToDashCase} from './util'; const NAMESPACE_URIS = - /*@ts2dart_const*/ {'xlink': 'http://www.w3.org/1999/xlink', 'svg': 'http://www.w3.org/2000/svg'}; const TEMPLATE_COMMENT_TEXT = 'template bindings={}'; var TEMPLATE_BINDINGS_EXP = /^template bindings=(.*)$/g; @@ -304,8 +303,8 @@ function decoratePreventDefault(eventHandler: Function): Function { var COMPONENT_REGEX = /%COMP%/g; export const COMPONENT_VARIABLE = '%COMP%'; -export const HOST_ATTR = /*@ts2dart_const*/ `_nghost-${COMPONENT_VARIABLE}`; -export const CONTENT_ATTR = /*@ts2dart_const*/ `_ngcontent-${COMPONENT_VARIABLE}`; +export const HOST_ATTR = `_nghost-${COMPONENT_VARIABLE}`; +export const CONTENT_ATTR = `_ngcontent-${COMPONENT_VARIABLE}`; function _shimContentAttribute(componentShortId: string): string { return StringWrapper.replaceAll(CONTENT_ATTR, COMPONENT_REGEX, componentShortId); diff --git a/modules/@angular/platform-browser/src/dom/dom_tokens.ts b/modules/@angular/platform-browser/src/dom/dom_tokens.ts index 800ef71b5e..450a1637ac 100644 --- a/modules/@angular/platform-browser/src/dom/dom_tokens.ts +++ b/modules/@angular/platform-browser/src/dom/dom_tokens.ts @@ -6,4 +6,4 @@ import {OpaqueToken} from '@angular/core'; * Note: Document might not be available in the Application Context when Application and Rendering * Contexts are not the same (e.g. when running the application into a Web Worker). */ -export const DOCUMENT: OpaqueToken = /*@ts2dart_const*/ new OpaqueToken('DocumentToken'); +export const DOCUMENT: OpaqueToken = new OpaqueToken('DocumentToken'); diff --git a/modules/@angular/platform-browser/src/dom/events/event_manager.ts b/modules/@angular/platform-browser/src/dom/events/event_manager.ts index 78ff4930bb..1fdc14e5fa 100644 --- a/modules/@angular/platform-browser/src/dom/events/event_manager.ts +++ b/modules/@angular/platform-browser/src/dom/events/event_manager.ts @@ -4,8 +4,7 @@ import {BaseException} from '../../../src/facade/exceptions'; import {ListWrapper} from '../../../src/facade/collection'; -export const EVENT_MANAGER_PLUGINS: OpaqueToken = - /*@ts2dart_const*/ new OpaqueToken("EventManagerPlugins"); +export const EVENT_MANAGER_PLUGINS: OpaqueToken = new OpaqueToken("EventManagerPlugins"); @Injectable() export class EventManager { diff --git a/modules/@angular/platform-browser/src/dom/events/hammer_gestures.ts b/modules/@angular/platform-browser/src/dom/events/hammer_gestures.ts index 0f70788990..6cab3d8552 100644 --- a/modules/@angular/platform-browser/src/dom/events/hammer_gestures.ts +++ b/modules/@angular/platform-browser/src/dom/events/hammer_gestures.ts @@ -3,8 +3,7 @@ import {isPresent} from '../../../src/facade/lang'; import {BaseException} from '../../../src/facade/exceptions'; import {HammerGesturesPluginCommon} from './hammer_common'; -export const HAMMER_GESTURE_CONFIG: OpaqueToken = - /*@ts2dart_const*/ new OpaqueToken("HammerGestureConfig"); +export const HAMMER_GESTURE_CONFIG: OpaqueToken = new OpaqueToken("HammerGestureConfig"); export interface HammerInstance { on(eventName: string, callback: Function): void; diff --git a/modules/@angular/platform-browser/src/platform/common/browser.ts b/modules/@angular/platform-browser/src/platform/common/browser.ts deleted file mode 100644 index 782d4af8d1..0000000000 --- a/modules/@angular/platform-browser/src/platform/common/browser.ts +++ /dev/null @@ -1,104 +0,0 @@ -import { - PLATFORM_INITIALIZER, - PLATFORM_DIRECTIVES, - PLATFORM_PIPES, - ExceptionHandler, - RootRenderer, - APPLICATION_COMMON_PROVIDERS, - PLATFORM_COMMON_PROVIDERS, - OpaqueToken, - Testability, - PlatformRef, - getPlatform, - createPlatform, - assertPlatform, - ReflectiveInjector -} from "@angular/core"; -import {isBlank} from "../../facade/lang"; -import {wtfInit, SanitizationService} from "../../../core_private"; -import {COMMON_DIRECTIVES, COMMON_PIPES, FORM_PROVIDERS, PlatformLocation} from "@angular/common"; -import {DomSanitizationService, DomSanitizationServiceImpl} from "../../security/dom_sanitization_service"; -import {BrowserDomAdapter} from "../../browser/browser_adapter"; -import {BrowserGetTestability} from "../../browser/testability"; -import {getDOM} from "../../dom/dom_adapter"; -import {DOCUMENT} from "../../dom/dom_tokens"; -import {EVENT_MANAGER_PLUGINS, EventManager} from "../../dom/events/event_manager"; -import {DomRootRenderer, DomRootRenderer_} from "../../dom/dom_renderer"; -import {SharedStylesHost, DomSharedStylesHost} from "../../dom/shared_styles_host"; -import {KeyEventsPlugin} from "../../dom/events/key_events"; -import {ELEMENT_PROBE_PROVIDERS} from "../../dom/debug/ng_probe"; -import {DomEventsPlugin} from "../../dom/events/dom_events"; -import {HAMMER_GESTURE_CONFIG, HammerGestureConfig, HammerGesturesPlugin} from "../../dom/events/hammer_gestures"; -import {AnimationBuilder} from "../../animate/animation_builder"; -import {BrowserDetails} from "../../animate/browser_details"; -import {BrowserPlatformLocation} from "../../browser/location/browser_platform_location"; - -const BROWSER_PLATFORM_MARKER = - /*@ts2dart_const*/ new OpaqueToken('BrowserPlatformMarker'); - -/** - * A set of providers to initialize the Angular platform in a web browser. - * - * Used automatically by `bootstrap`, or can be passed to {@link platform}. - */ -export const BROWSER_PLATFORM_PROVIDERS: Array = /*@ts2dart_const*/[ - /*@ts2dart_Provider*/ {provide: BROWSER_PLATFORM_MARKER, useValue: true}, - PLATFORM_COMMON_PROVIDERS, - /*@ts2dart_Provider*/ {provide: PLATFORM_INITIALIZER, useValue: initDomAdapter, multi: true}, - /*@ts2dart_Provider*/ {provide: PlatformLocation, useClass: BrowserPlatformLocation} -]; - -export const BROWSER_SANITIZATION_PROVIDERS: Array = /*@ts2dart_const*/[ - /* @ts2dart_Provider */ {provide: SanitizationService, useExisting: DomSanitizationService}, - /* @ts2dart_Provider */ {provide: DomSanitizationService, useClass: DomSanitizationServiceImpl}, -]; - -/** - * A set of providers to initialize an Angular application in a web browser. - * - * Used automatically by `bootstrap`, or can be passed to {@link PlatformRef.application}. - */ -export const BROWSER_APP_COMMON_PROVIDERS: Array = - /*@ts2dart_const*/[ - APPLICATION_COMMON_PROVIDERS, - FORM_PROVIDERS, - BROWSER_SANITIZATION_PROVIDERS, - /* @ts2dart_Provider */ {provide: PLATFORM_PIPES, useValue: COMMON_PIPES, multi: true}, - /* @ts2dart_Provider */ {provide: PLATFORM_DIRECTIVES, useValue: COMMON_DIRECTIVES, multi: true}, - /* @ts2dart_Provider */ {provide: ExceptionHandler, useFactory: _exceptionHandler, deps: []}, - /* @ts2dart_Provider */ {provide: DOCUMENT, useFactory: _document, deps: []}, - /* @ts2dart_Provider */ {provide: EVENT_MANAGER_PLUGINS, useClass: DomEventsPlugin, multi: true}, - /* @ts2dart_Provider */ {provide: EVENT_MANAGER_PLUGINS, useClass: KeyEventsPlugin, multi: true}, - /* @ts2dart_Provider */ {provide: EVENT_MANAGER_PLUGINS, useClass: HammerGesturesPlugin, multi: true}, - /* @ts2dart_Provider */ {provide: HAMMER_GESTURE_CONFIG, useClass: HammerGestureConfig}, - /* @ts2dart_Provider */ {provide: DomRootRenderer, useClass: DomRootRenderer_}, - /* @ts2dart_Provider */ {provide: RootRenderer, useExisting: DomRootRenderer}, - /* @ts2dart_Provider */ {provide: SharedStylesHost, useExisting: DomSharedStylesHost}, - DomSharedStylesHost, - Testability, - BrowserDetails, - AnimationBuilder, - EventManager, - ELEMENT_PROBE_PROVIDERS - ]; - -export function browserPlatform(): PlatformRef { - if (isBlank(getPlatform())) { - createPlatform(ReflectiveInjector.resolveAndCreate(BROWSER_PLATFORM_PROVIDERS)); - } - return assertPlatform(BROWSER_PLATFORM_MARKER); -} - -function initDomAdapter() { - BrowserDomAdapter.makeCurrent(); - wtfInit(); - BrowserGetTestability.init(); -} - -function _exceptionHandler(): ExceptionHandler { - return new ExceptionHandler(getDOM()); -} - -function _document(): any { - return getDOM().defaultDoc(); -} diff --git a/modules/@angular/platform-browser/src/platform/common/worker_app.ts b/modules/@angular/platform-browser/src/platform/common/worker_app.ts deleted file mode 100644 index cca990628c..0000000000 --- a/modules/@angular/platform-browser/src/platform/common/worker_app.ts +++ /dev/null @@ -1,74 +0,0 @@ -import {WebWorkerRootRenderer} from '../../web_workers/worker/renderer'; -import {print, isBlank} from '../../../src/facade/lang'; -import { - PLATFORM_DIRECTIVES, - PLATFORM_PIPES, - ExceptionHandler, - APPLICATION_COMMON_PROVIDERS, - PLATFORM_COMMON_PROVIDERS, - OpaqueToken, - RootRenderer, - PlatformRef, - getPlatform, - createPlatform, - assertPlatform, - ReflectiveInjector -} from '@angular/core'; -import {COMMON_DIRECTIVES, COMMON_PIPES, FORM_PROVIDERS} from '@angular/common'; -import { - ClientMessageBrokerFactory, - ClientMessageBrokerFactory_ -} from '../../web_workers/shared/client_message_broker'; -import { - ServiceMessageBrokerFactory, - ServiceMessageBrokerFactory_ -} from '../../web_workers/shared/service_message_broker'; -import {Serializer} from '../../web_workers/shared/serializer'; -import {ON_WEB_WORKER} from '../../web_workers/shared/api'; -import {RenderStore} from '../../web_workers/shared/render_store'; -import {BROWSER_SANITIZATION_PROVIDERS} from './browser'; - -class PrintLogger { - log = print; - logError = print; - logGroup = print; - logGroupEnd() {} -} - -const WORKER_APP_PLATFORM_MARKER = - /*@ts2dart_const*/ new OpaqueToken('WorkerAppPlatformMarker'); - -export const WORKER_APP_PLATFORM_PROVIDERS: Array = - /*@ts2dart_const*/[ - PLATFORM_COMMON_PROVIDERS, - /*@ts2dart_const*/ ( - /* @ts2dart_Provider */ {provide: WORKER_APP_PLATFORM_MARKER, useValue: true}) - ]; - -export const WORKER_APP_APPLICATION_COMMON_PROVIDERS: Array = - /*@ts2dart_const*/[ - APPLICATION_COMMON_PROVIDERS, - FORM_PROVIDERS, - BROWSER_SANITIZATION_PROVIDERS, - Serializer, - /* @ts2dart_Provider */ {provide: PLATFORM_PIPES, useValue: COMMON_PIPES, multi: true}, - /* @ts2dart_Provider */ {provide: PLATFORM_DIRECTIVES, useValue: COMMON_DIRECTIVES, multi: true}, - /* @ts2dart_Provider */ {provide: ClientMessageBrokerFactory, useClass: ClientMessageBrokerFactory_}, - /* @ts2dart_Provider */ {provide: ServiceMessageBrokerFactory, useClass: ServiceMessageBrokerFactory_}, - WebWorkerRootRenderer, - /* @ts2dart_Provider */ {provide: RootRenderer, useExisting: WebWorkerRootRenderer}, - /* @ts2dart_Provider */ {provide: ON_WEB_WORKER, useValue: true}, - RenderStore, - /* @ts2dart_Provider */ {provide: ExceptionHandler, useFactory: _exceptionHandler, deps: []} - ]; - -export function workerAppPlatform(): PlatformRef { - if (isBlank(getPlatform())) { - createPlatform(ReflectiveInjector.resolveAndCreate(WORKER_APP_PLATFORM_PROVIDERS)); - } - return assertPlatform(WORKER_APP_PLATFORM_MARKER); -} - -function _exceptionHandler(): ExceptionHandler { - return new ExceptionHandler(new PrintLogger()); -} \ No newline at end of file diff --git a/modules/@angular/platform-browser/src/platform/common/worker_render.ts b/modules/@angular/platform-browser/src/platform/common/worker_render.ts deleted file mode 100644 index b7c78d6ae6..0000000000 --- a/modules/@angular/platform-browser/src/platform/common/worker_render.ts +++ /dev/null @@ -1,121 +0,0 @@ -import {isBlank} from "../../../src/facade/lang"; -import {MessageBus} from "../../web_workers/shared/message_bus"; -import { - NgZone, - Injector, - OpaqueToken, - Testability, - ExceptionHandler, - APPLICATION_COMMON_PROVIDERS, - PLATFORM_COMMON_PROVIDERS, - RootRenderer, - PLATFORM_INITIALIZER, - PlatformRef, - getPlatform, - createPlatform, - assertPlatform, - ReflectiveInjector -} from "@angular/core"; -import {wtfInit} from "../../../core_private"; -import {getDOM} from "../../dom/dom_adapter"; -import {DomEventsPlugin} from "../../dom/events/dom_events"; -import {KeyEventsPlugin} from "../../dom/events/key_events"; -import {HammerGesturesPlugin, HAMMER_GESTURE_CONFIG, HammerGestureConfig} from "../../dom/events/hammer_gestures"; -import {DOCUMENT} from "../../dom/dom_tokens"; -import {DomRootRenderer, DomRootRenderer_} from "../../dom/dom_renderer"; -import {DomSharedStylesHost, SharedStylesHost} from "../../dom/shared_styles_host"; -import {BrowserDetails} from "../../animate/browser_details"; -import {AnimationBuilder} from "../../animate/animation_builder"; -import {BrowserGetTestability} from "../../browser/testability"; -import {BrowserDomAdapter} from "../../browser/browser_adapter"; -import {MessageBasedRenderer} from "../../web_workers/ui/renderer"; -import { - ServiceMessageBrokerFactory, - ServiceMessageBrokerFactory_ -} from "../../web_workers/shared/service_message_broker"; -import {ClientMessageBrokerFactory, ClientMessageBrokerFactory_} from "../../web_workers/shared/client_message_broker"; -import {Serializer} from "../../web_workers/shared/serializer"; -import {ON_WEB_WORKER} from "../../web_workers/shared/api"; -import {RenderStore} from "../../web_workers/shared/render_store"; -import {EventManager, EVENT_MANAGER_PLUGINS} from "../../dom/events/event_manager"; -import {BROWSER_SANITIZATION_PROVIDERS} from "../common/browser"; - -const WORKER_RENDER_PLATFORM_MARKER = - /*@ts2dart_const*/ new OpaqueToken('WorkerRenderPlatformMarker'); - -export const WORKER_SCRIPT: OpaqueToken = /*@ts2dart_const*/ new OpaqueToken("WebWorkerScript"); - -/** - * A multiple providers used to automatically call the `start()` method after the service is - * created. - * - * TODO(vicb): create an interface for startable services to implement - */ -export const WORKER_RENDER_STARTABLE_MESSAGING_SERVICE = - /*@ts2dart_const*/ new OpaqueToken('WorkerRenderStartableMsgService'); - -export const WORKER_RENDER_PLATFORM_PROVIDERS: Array = /*@ts2dart_const*/[ - PLATFORM_COMMON_PROVIDERS, - /*@ts2dart_const*/ (/* @ts2dart_Provider */ {provide: WORKER_RENDER_PLATFORM_MARKER, useValue: true}), - /* @ts2dart_Provider */ {provide: PLATFORM_INITIALIZER, useValue: initWebWorkerRenderPlatform, multi: true} -]; - -export const WORKER_RENDER_APPLICATION_COMMON_PROVIDERS: Array = - /*@ts2dart_const*/[ - APPLICATION_COMMON_PROVIDERS, - MessageBasedRenderer, - /* @ts2dart_Provider */ {provide: WORKER_RENDER_STARTABLE_MESSAGING_SERVICE, useExisting: MessageBasedRenderer, multi: true}, - BROWSER_SANITIZATION_PROVIDERS, - /* @ts2dart_Provider */ {provide: ExceptionHandler, useFactory: _exceptionHandler, deps: []}, - /* @ts2dart_Provider */ {provide: DOCUMENT, useFactory: _document, deps: []}, - // TODO(jteplitz602): Investigate if we definitely need EVENT_MANAGER on the render thread - // #5298 - /* @ts2dart_Provider */ {provide: EVENT_MANAGER_PLUGINS, useClass: DomEventsPlugin, multi: true}, - /* @ts2dart_Provider */ {provide: EVENT_MANAGER_PLUGINS, useClass: KeyEventsPlugin, multi: true}, - /* @ts2dart_Provider */ {provide: EVENT_MANAGER_PLUGINS, useClass: HammerGesturesPlugin, multi: true}, - /* @ts2dart_Provider */ {provide: HAMMER_GESTURE_CONFIG, useClass: HammerGestureConfig}, - /* @ts2dart_Provider */ {provide: DomRootRenderer, useClass: DomRootRenderer_}, - /* @ts2dart_Provider */ {provide: RootRenderer, useExisting: DomRootRenderer}, - /* @ts2dart_Provider */ {provide: SharedStylesHost, useExisting: DomSharedStylesHost}, - /* @ts2dart_Provider */ {provide: ServiceMessageBrokerFactory, useClass: ServiceMessageBrokerFactory_}, - /* @ts2dart_Provider */ {provide: ClientMessageBrokerFactory, useClass: ClientMessageBrokerFactory_}, - Serializer, - /* @ts2dart_Provider */ {provide: ON_WEB_WORKER, useValue: false}, - RenderStore, - DomSharedStylesHost, - Testability, - BrowserDetails, - AnimationBuilder, - EventManager - ]; - -export function initializeGenericWorkerRenderer(injector: Injector) { - var bus = injector.get(MessageBus); - let zone = injector.get(NgZone); - bus.attachToZone(zone); - - // initialize message services after the bus has been created - let services = injector.get(WORKER_RENDER_STARTABLE_MESSAGING_SERVICE); - zone.runGuarded(() => { services.forEach((svc) => { svc.start(); }); }); -} - -function initWebWorkerRenderPlatform(): void { - BrowserDomAdapter.makeCurrent(); - wtfInit(); - BrowserGetTestability.init(); -} - -export function workerRenderPlatform(): PlatformRef { - if (isBlank(getPlatform())) { - createPlatform(ReflectiveInjector.resolveAndCreate(WORKER_RENDER_PLATFORM_PROVIDERS)); - } - return assertPlatform(WORKER_RENDER_PLATFORM_MARKER); -} - -function _exceptionHandler(): ExceptionHandler { - return new ExceptionHandler(getDOM()); -} - -function _document(): any { - return getDOM().defaultDoc(); -} diff --git a/modules/@angular/platform-browser/src/platform/dynamic/browser.ts b/modules/@angular/platform-browser/src/platform/dynamic/browser.ts deleted file mode 100644 index 7ca0eb6bc2..0000000000 --- a/modules/@angular/platform-browser/src/platform/dynamic/browser.ts +++ /dev/null @@ -1,106 +0,0 @@ -import { - reflector, - ReflectiveInjector, - coreLoadAndBootstrap, - Type, - ComponentRef -} from '@angular/core'; - -import {COMPILER_PROVIDERS, XHR} from '@angular/compiler'; -import {CachedXHR} from '../../../src/xhr/xhr_cache'; -import {isPresent} from '../../../src/facade/lang'; -import {XHRImpl} from '../../../src/xhr/xhr_impl'; -import {browserPlatform, BROWSER_APP_COMMON_PROVIDERS} from '../common/browser'; - -import {ReflectionCapabilities} from '../../../core_private'; - -export const CACHED_TEMPLATE_PROVIDER: Array = - /*@ts2dart_const*/[{provide: XHR, useClass: CachedXHR}]; - -/** - * An array of providers that should be passed into `application()` when bootstrapping a component. - */ -export const BROWSER_APP_PROVIDERS: Array = - /*@ts2dart_const*/[ - BROWSER_APP_COMMON_PROVIDERS, - COMPILER_PROVIDERS, - {provide: XHR, useClass: XHRImpl}, - ]; - -/** - * Bootstrapping for Angular applications. - * - * You instantiate an Angular application by explicitly specifying a component to use - * as the root component for your application via the `bootstrap()` method. - * - * ## Simple Example - * - * Assuming this `index.html`: - * - * ```html - * - * - * - * loading... - * - * - * ``` - * - * An application is bootstrapped inside an existing browser DOM, typically `index.html`. - * Unlike Angular 1, Angular 2 does not compile/process providers in `index.html`. This is - * mainly for security reasons, as well as architectural changes in Angular 2. This means - * that `index.html` can safely be processed using server-side technologies such as - * providers. Bindings can thus use double-curly `{{ syntax }}` without collision from - * Angular 2 component double-curly `{{ syntax }}`. - * - * We can use this script code: - * - * {@example core/ts/bootstrap/bootstrap.ts region='bootstrap'} - * - * When the app developer invokes `bootstrap()` with the root component `MyApp` as its - * argument, Angular performs the following tasks: - * - * 1. It uses the component's `selector` property to locate the DOM element which needs - * to be upgraded into the angular component. - * 2. It creates a new child injector (from the platform injector). Optionally, you can - * also override the injector configuration for an app by invoking `bootstrap` with the - * `customProviders` argument. - * 3. It creates a new `Zone` and connects it to the angular application's change detection - * domain instance. - * 4. It creates an emulated or shadow DOM on the selected component's host element and loads the - * template into it. - * 5. It instantiates the specified component. - * 6. Finally, Angular performs change detection to apply the initial data providers for the - * application. - * - * - * ## Bootstrapping Multiple Applications - * - * When working within a browser window, there are many singleton resources: cookies, title, - * location, and others. Angular services that represent these resources must likewise be - * shared across all Angular applications that occupy the same browser window. For this - * reason, Angular creates exactly one global platform object which stores all shared - * services, and each angular application injector has the platform injector as its parent. - * - * Each application has its own private injector as well. When there are multiple - * applications on a page, Angular treats each application injector's services as private - * to that application. - * - * ## API - * - * - `appComponentType`: The root component which should act as the application. This is - * a reference to a `Type` which is annotated with `@Component(...)`. - * - `customProviders`: An additional set of providers that can be added to the - * app injector to override default injection behavior. - * - * Returns a `Promise` of {@link ComponentRef}. - */ -export function bootstrap( - appComponentType: Type, - customProviders?: Array): Promise> { - reflector.reflectionCapabilities = new ReflectionCapabilities(); - var appInjector = ReflectiveInjector.resolveAndCreate( - [BROWSER_APP_PROVIDERS, isPresent(customProviders) ? customProviders : []], - browserPlatform().injector); - return coreLoadAndBootstrap(appComponentType, appInjector); -} diff --git a/modules/@angular/platform-browser/src/platform/dynamic/worker_app.ts b/modules/@angular/platform-browser/src/platform/dynamic/worker_app.ts deleted file mode 100644 index 4dd08fb9a3..0000000000 --- a/modules/@angular/platform-browser/src/platform/dynamic/worker_app.ts +++ /dev/null @@ -1,27 +0,0 @@ -import {WORKER_APP_STATIC_APPLICATION_PROVIDERS} from '../static/worker_app'; -import {workerAppPlatform} from '../common/worker_app'; -import {COMPILER_PROVIDERS, XHR} from '@angular/compiler'; -import {XHRImpl} from '../../xhr/xhr_impl'; -import {isPresent} from '../../facade/lang'; - -import { - Type, - ComponentRef, - ReflectiveInjector, - coreLoadAndBootstrap, -} from '@angular/core'; - -export const WORKER_APP_APPLICATION_PROVIDERS: Array = [ - WORKER_APP_STATIC_APPLICATION_PROVIDERS, - COMPILER_PROVIDERS, - /* @ts2dart_Provider */ {provide: XHR, useClass: XHRImpl}, -]; - -export function bootstrapApp( - appComponentType: Type, - customProviders?: Array): Promise> { - var appInjector = ReflectiveInjector.resolveAndCreate( - [WORKER_APP_APPLICATION_PROVIDERS, isPresent(customProviders) ? customProviders : []], - workerAppPlatform().injector); - return coreLoadAndBootstrap(appComponentType, appInjector); -} diff --git a/modules/@angular/platform-browser/src/platform/dynamic/worker_render.ts b/modules/@angular/platform-browser/src/platform/dynamic/worker_render.ts deleted file mode 100644 index bfddb97a93..0000000000 --- a/modules/@angular/platform-browser/src/platform/dynamic/worker_render.ts +++ /dev/null @@ -1,25 +0,0 @@ -import {WORKER_RENDER_STATIC_APPLICATION_PROVIDERS} from "../static/worker_render"; -import {ApplicationRef, ReflectiveInjector} from "@angular/core"; -import {workerRenderPlatform, WORKER_SCRIPT} from "../common/worker_render"; -import {isPresent} from "../../facade/lang"; -import {PromiseWrapper} from "../../facade/async"; - -export const WORKER_RENDER_APPLICATION_PROVIDERS: Array = [ - WORKER_RENDER_STATIC_APPLICATION_PROVIDERS -]; - -export function bootstrapRender( - workerScriptUri: string, - customProviders?: Array): Promise { - var app = ReflectiveInjector.resolveAndCreate( - [ - WORKER_RENDER_APPLICATION_PROVIDERS, - /* @ts2dart_Provider */ {provide: WORKER_SCRIPT, useValue: workerScriptUri}, - isPresent(customProviders) ? customProviders : [] - ], - workerRenderPlatform().injector); - // Return a promise so that we keep the same semantics as Dart, - // and we might want to wait for the app side to come up - // in the future... - return PromiseWrapper.resolve(app.get(ApplicationRef)); -} diff --git a/modules/@angular/platform-browser/src/platform/static/browser.ts b/modules/@angular/platform-browser/src/platform/static/browser.ts deleted file mode 100644 index d49639ad0d..0000000000 --- a/modules/@angular/platform-browser/src/platform/static/browser.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { - ComponentRef, - coreLoadAndBootstrap, - ReflectiveInjector -} from '@angular/core'; -import {Type, isPresent} from '../../facade/lang'; -import { - BROWSER_APP_COMMON_PROVIDERS, - browserPlatform -} from '../common/browser'; - -/** - * An array of providers that should be passed into `application()` when bootstrapping a component - * when all templates have been pre-compiled. - */ -export const BROWSER_APP_STATIC_PROVIDERS: Array = - /*@ts2dart_const*/ BROWSER_APP_COMMON_PROVIDERS; - -/** - * See {@link bootstrap} for more information. - */ -export function bootstrapStatic(appComponentType: Type, - customProviders?: Array, - initReflector?: Function): Promise> { - if (isPresent(initReflector)) { - initReflector(); - } - - let appProviders = isPresent(customProviders) ? [BROWSER_APP_STATIC_PROVIDERS, customProviders] : - BROWSER_APP_STATIC_PROVIDERS; - var appInjector = - ReflectiveInjector.resolveAndCreate(appProviders, browserPlatform().injector); - return coreLoadAndBootstrap(appComponentType, appInjector); -} diff --git a/modules/@angular/platform-browser/src/platform/static/worker_app.ts b/modules/@angular/platform-browser/src/platform/static/worker_app.ts deleted file mode 100644 index 9e0ed96c10..0000000000 --- a/modules/@angular/platform-browser/src/platform/static/worker_app.ts +++ /dev/null @@ -1,45 +0,0 @@ -import {APP_INITIALIZER, NgZone, ReflectiveInjector, ComponentRef, coreLoadAndBootstrap} from '@angular/core'; -import {Type, isPresent} from '../../../src/facade/lang'; -import {workerAppPlatform} from '../common/worker_app'; -import {WorkerDomAdapter} from '../../web_workers/worker/worker_adapter'; -import { - PostMessageBus, - PostMessageBusSink, - PostMessageBusSource -} from '../../web_workers/shared/post_message_bus'; -import {WORKER_APP_APPLICATION_COMMON_PROVIDERS} from '../common/worker_app'; -import {MessageBus} from '../../web_workers/shared/message_bus'; - -// TODO(jteplitz602) remove this and compile with lib.webworker.d.ts (#3492) -let _postMessage = { - postMessage: (message: any, transferrables?:[ArrayBuffer]) => { - (postMessage)(message, transferrables); - } -}; - -export const WORKER_APP_STATIC_APPLICATION_PROVIDERS: Array = [ - WORKER_APP_APPLICATION_COMMON_PROVIDERS, - /* @ts2dart_Provider */ {provide: MessageBus, useFactory: createMessageBus, deps: [NgZone]}, - /* @ts2dart_Provider */ {provide: APP_INITIALIZER, useValue: setupWebWorker, multi: true} -]; - -export function bootstrapStaticApp( - appComponentType: Type, - customProviders?: Array): Promise> { - var appInjector = ReflectiveInjector.resolveAndCreate( - [WORKER_APP_STATIC_APPLICATION_PROVIDERS, isPresent(customProviders) ? customProviders : []], - workerAppPlatform().injector); - return coreLoadAndBootstrap(appComponentType, appInjector); -} - -function createMessageBus(zone: NgZone): MessageBus { - let sink = new PostMessageBusSink(_postMessage); - let source = new PostMessageBusSource(); - let bus = new PostMessageBus(sink, source); - bus.attachToZone(zone); - return bus; -} - -function setupWebWorker(): void { - WorkerDomAdapter.makeCurrent(); -} \ No newline at end of file diff --git a/modules/@angular/platform-browser/src/platform/static/worker_render.ts b/modules/@angular/platform-browser/src/platform/static/worker_render.ts deleted file mode 100644 index de445ae25f..0000000000 --- a/modules/@angular/platform-browser/src/platform/static/worker_render.ts +++ /dev/null @@ -1,100 +0,0 @@ -import { - PostMessageBus, - PostMessageBusSink, - PostMessageBusSource -} from '../../web_workers/shared/post_message_bus'; -import {MessageBus} from '../../web_workers/shared/message_bus'; -import {Injector, Injectable, APP_INITIALIZER} from '@angular/core'; -import { - WORKER_RENDER_APPLICATION_COMMON_PROVIDERS, - WORKER_SCRIPT, - initializeGenericWorkerRenderer -} from '../common/worker_render'; -import {BaseException} from '../../../src/facade/exceptions'; - - -import {isPresent} from '../../facade/lang'; -import {PromiseWrapper} from '../../facade/async'; -import { - ApplicationRef, - ReflectiveInjector, -} from '@angular/core'; -import {workerRenderPlatform} from '../common/worker_render'; - -/** - * Wrapper class that exposes the Worker - * and underlying {@link MessageBus} for lower level message passing. - */ -@Injectable() -export class WebWorkerInstance { - public worker: Worker; - public bus: MessageBus; - - /** @internal */ - public init(worker: Worker, bus: MessageBus) { - this.worker = worker; - this.bus = bus; - } -} - -/** - * An array of providers that should be passed into `application()` when initializing a new Worker. - */ -export const WORKER_RENDER_STATIC_APPLICATION_PROVIDERS: Array = /*@ts2dart_const*/[ - WORKER_RENDER_APPLICATION_COMMON_PROVIDERS, WebWorkerInstance, - /*@ts2dart_Provider*/ { - provide: APP_INITIALIZER, - useFactory: (injector => () => initWebWorkerApplication(injector)), - multi: true, - deps: [Injector] - }, - /*@ts2dart_Provider*/ { - provide: MessageBus, - useFactory: (instance) => instance.bus, - deps: [WebWorkerInstance] - } -]; - -export function bootstrapStaticRender( - workerScriptUri: string, - customProviders?: Array): Promise { - var app = ReflectiveInjector.resolveAndCreate( - [ - WORKER_RENDER_STATIC_APPLICATION_PROVIDERS, - /* @ts2dart_Provider */ {provide: WORKER_SCRIPT, useValue: workerScriptUri}, - isPresent(customProviders) ? customProviders : [] - ], - workerRenderPlatform().injector); - // Return a promise so that we keep the same semantics as Dart, - // and we might want to wait for the app side to come up - // in the future... - return PromiseWrapper.resolve(app.get(ApplicationRef)); -} - - -function initWebWorkerApplication(injector: Injector): void { - var scriptUri: string; - try { - scriptUri = injector.get(WORKER_SCRIPT); - } catch (e) { - throw new BaseException( - "You must provide your WebWorker's initialization script with the WORKER_SCRIPT token"); - } - - let instance = injector.get(WebWorkerInstance); - spawnWebWorker(scriptUri, instance); - - initializeGenericWorkerRenderer(injector); -} - -/** - * Spawns a new class and initializes the WebWorkerInstance - */ -function spawnWebWorker(uri: string, instance: WebWorkerInstance): void { - var webWorker: Worker = new Worker(uri); - var sink = new PostMessageBusSink(webWorker); - var source = new PostMessageBusSource(webWorker); - var bus = new PostMessageBus(sink, source); - - instance.init(webWorker, bus); -} diff --git a/modules/@angular/platform-browser/src/web_workers/shared/api.ts b/modules/@angular/platform-browser/src/web_workers/shared/api.ts index e94d68237a..810be509ea 100644 --- a/modules/@angular/platform-browser/src/web_workers/shared/api.ts +++ b/modules/@angular/platform-browser/src/web_workers/shared/api.ts @@ -1,3 +1,3 @@ import {OpaqueToken} from '@angular/core'; -export const ON_WEB_WORKER = /*@ts2dart_const*/ new OpaqueToken('WebWorker.onWebWorker'); +export const ON_WEB_WORKER = new OpaqueToken('WebWorker.onWebWorker'); diff --git a/modules/@angular/platform-browser/src/web_workers/shared/serializer.ts b/modules/@angular/platform-browser/src/web_workers/shared/serializer.ts index f53b005815..481d7a9d06 100644 --- a/modules/@angular/platform-browser/src/web_workers/shared/serializer.ts +++ b/modules/@angular/platform-browser/src/web_workers/shared/serializer.ts @@ -8,7 +8,7 @@ import {LocationType} from './serialized_types'; // PRIMITIVE is any type that does not need to be serialized (string, number, boolean) // We set it to String so that it is considered a Type. -export const PRIMITIVE: Type = /*@ts2dart_const*/ String; +export const PRIMITIVE: Type = String; @Injectable() export class Serializer { diff --git a/modules/@angular/platform-browser/src/web_workers/ui/location_providers.ts b/modules/@angular/platform-browser/src/web_workers/ui/location_providers.ts index b83b889857..a394aaee31 100644 --- a/modules/@angular/platform-browser/src/web_workers/ui/location_providers.ts +++ b/modules/@angular/platform-browser/src/web_workers/ui/location_providers.ts @@ -6,10 +6,10 @@ import {APP_INITIALIZER, Injector, NgZone} from '@angular/core'; * A list of {@link Provider}s. To use the router in a Worker enabled application you must * include these providers when setting up the render thread. */ -export const WORKER_RENDER_LOCATION_PROVIDERS = /*@ts2dart_const*/[ +export const WORKER_RENDER_LOCATION_PROVIDERS = [ MessageBasedPlatformLocation, BrowserPlatformLocation, - /* @ts2dart_Provider */ {provide: APP_INITIALIZER, useFactory: initUiLocation, multi: true, deps: [Injector]} + {provide: APP_INITIALIZER, useFactory: initUiLocation, multi: true, deps: [Injector]} ]; function initUiLocation(injector: Injector): () => void { diff --git a/modules/@angular/platform-browser/src/web_workers/worker/location_providers.ts b/modules/@angular/platform-browser/src/web_workers/worker/location_providers.ts index 1f15d8fb89..0efbd42ad1 100644 --- a/modules/@angular/platform-browser/src/web_workers/worker/location_providers.ts +++ b/modules/@angular/platform-browser/src/web_workers/worker/location_providers.ts @@ -6,8 +6,8 @@ import {WebWorkerPlatformLocation} from './platform_location'; * Those providers should be added when the router is used in a worker context in addition to the * {@link ROUTER_PROVIDERS} and after them. */ -export const WORKER_APP_LOCATION_PROVIDERS = /*@ts2dart_const*/[ - /* @ts2dart_Provider */ {provide: PlatformLocation, useClass: WebWorkerPlatformLocation}, +export const WORKER_APP_LOCATION_PROVIDERS = [ + {provide: PlatformLocation, useClass: WebWorkerPlatformLocation}, { provide: APP_INITIALIZER, useFactory: (platformLocation: WebWorkerPlatformLocation, zone: NgZone) => () => diff --git a/modules/@angular/platform-browser/src/worker_app.ts b/modules/@angular/platform-browser/src/worker_app.ts new file mode 100644 index 0000000000..4287b4e8f3 --- /dev/null +++ b/modules/@angular/platform-browser/src/worker_app.ts @@ -0,0 +1,110 @@ +import {WebWorkerRootRenderer} from "./web_workers/worker/renderer"; +import {print, isBlank, isPresent} from "./facade/lang"; +import { + PLATFORM_DIRECTIVES, + PLATFORM_PIPES, + ExceptionHandler, + APPLICATION_COMMON_PROVIDERS, + PLATFORM_COMMON_PROVIDERS, + OpaqueToken, + RootRenderer, + PlatformRef, + getPlatform, + createPlatform, + assertPlatform, + ReflectiveInjector, + APP_INITIALIZER, + NgZone, + Type, + ComponentRef, + coreLoadAndBootstrap +} from "@angular/core"; +import {COMMON_DIRECTIVES, COMMON_PIPES, FORM_PROVIDERS} from "@angular/common"; +import {ClientMessageBrokerFactory, ClientMessageBrokerFactory_} from "./web_workers/shared/client_message_broker"; +import {ServiceMessageBrokerFactory, ServiceMessageBrokerFactory_} from "./web_workers/shared/service_message_broker"; +import {Serializer} from "./web_workers/shared/serializer"; +import {ON_WEB_WORKER} from "./web_workers/shared/api"; +import {RenderStore} from "./web_workers/shared/render_store"; +import {BROWSER_SANITIZATION_PROVIDERS} from "./browser"; +import {WorkerDomAdapter} from "./web_workers/worker/worker_adapter"; +import {PostMessageBus, PostMessageBusSink, PostMessageBusSource} from "./web_workers/shared/post_message_bus"; +import {MessageBus} from "./web_workers/shared/message_bus"; +import {COMPILER_PROVIDERS, XHR} from "@angular/compiler"; +import {XHRImpl} from "./xhr/xhr_impl"; + +class PrintLogger { + log = print; + logError = print; + logGroup = print; + logGroupEnd() {} +} + +const WORKER_APP_PLATFORM_MARKER = new OpaqueToken('WorkerAppPlatformMarker'); + +export const WORKER_APP_PLATFORM_PROVIDERS: Array = + [ + PLATFORM_COMMON_PROVIDERS, + {provide: WORKER_APP_PLATFORM_MARKER, useValue: true} + ]; + +export const WORKER_APP_APPLICATION_PROVIDERS: Array = + [ + 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}, + {provide: ON_WEB_WORKER, useValue: true}, + RenderStore, + {provide: ExceptionHandler, useFactory: _exceptionHandler, deps: []}, + {provide: MessageBus, useFactory: createMessageBus, deps: [NgZone]}, + {provide: APP_INITIALIZER, useValue: setupWebWorker, multi: true} + ]; + +export function workerAppPlatform(): PlatformRef { + if (isBlank(getPlatform())) { + createPlatform(ReflectiveInjector.resolveAndCreate(WORKER_APP_PLATFORM_PROVIDERS)); + } + return assertPlatform(WORKER_APP_PLATFORM_MARKER); +} + +export function bootstrapApp( + appComponentType: Type, + customProviders?: Array): Promise> { + var appInjector = ReflectiveInjector.resolveAndCreate([ + WORKER_APP_APPLICATION_PROVIDERS, + COMPILER_PROVIDERS, + {provide: XHR, useClass: XHRImpl}, + isPresent(customProviders) ? customProviders : []], + workerAppPlatform().injector); + return coreLoadAndBootstrap(appComponentType, appInjector); +} + + +function _exceptionHandler(): ExceptionHandler { + return new ExceptionHandler(new PrintLogger()); +} + +// TODO(jteplitz602) remove this and compile with lib.webworker.d.ts (#3492) +let _postMessage = { + postMessage: (message: any, transferrables?:[ArrayBuffer]) => { + (postMessage)(message, transferrables); + } +}; + +function createMessageBus(zone: NgZone): MessageBus { + let sink = new PostMessageBusSink(_postMessage); + let source = new PostMessageBusSource(); + let bus = new PostMessageBus(sink, source); + bus.attachToZone(zone); + return bus; +} + +function setupWebWorker(): void { + WorkerDomAdapter.makeCurrent(); +} \ No newline at end of file diff --git a/modules/@angular/platform-browser/src/worker_render.ts b/modules/@angular/platform-browser/src/worker_render.ts new file mode 100644 index 0000000000..2264639608 --- /dev/null +++ b/modules/@angular/platform-browser/src/worker_render.ts @@ -0,0 +1,194 @@ +import {isBlank, isPresent} from "./facade/lang"; +import {MessageBus} from "./web_workers/shared/message_bus"; +import { + NgZone, + Injector, + OpaqueToken, + Testability, + ExceptionHandler, + APPLICATION_COMMON_PROVIDERS, + PLATFORM_COMMON_PROVIDERS, + RootRenderer, + PLATFORM_INITIALIZER, + PlatformRef, + getPlatform, + createPlatform, + assertPlatform, + ReflectiveInjector, + Injectable, + APP_INITIALIZER, + ApplicationRef +} from "@angular/core"; +import {wtfInit} from "../core_private"; +import {getDOM} from "./dom/dom_adapter"; +import {DomEventsPlugin} from "./dom/events/dom_events"; +import {KeyEventsPlugin} from "./dom/events/key_events"; +import {HammerGesturesPlugin, HAMMER_GESTURE_CONFIG, HammerGestureConfig} from "./dom/events/hammer_gestures"; +import {DOCUMENT} from "./dom/dom_tokens"; +import {DomRootRenderer, DomRootRenderer_} from "./dom/dom_renderer"; +import {DomSharedStylesHost, SharedStylesHost} from "./dom/shared_styles_host"; +import {BrowserDetails} from "./animate/browser_details"; +import {AnimationBuilder} from "./animate/animation_builder"; +import {BrowserGetTestability} from "./browser/testability"; +import {BrowserDomAdapter} from "./browser/browser_adapter"; +import {MessageBasedRenderer} from "./web_workers/ui/renderer"; +import {ServiceMessageBrokerFactory, ServiceMessageBrokerFactory_} from "./web_workers/shared/service_message_broker"; +import {ClientMessageBrokerFactory, ClientMessageBrokerFactory_} from "./web_workers/shared/client_message_broker"; +import {Serializer} from "./web_workers/shared/serializer"; +import {ON_WEB_WORKER} from "./web_workers/shared/api"; +import {RenderStore} from "./web_workers/shared/render_store"; +import {EventManager, EVENT_MANAGER_PLUGINS} from "./dom/events/event_manager"; +import {BROWSER_SANITIZATION_PROVIDERS, BROWSER_APP_COMPILER_PROVIDERS} from "./browser"; +import {PostMessageBus, PostMessageBusSink, PostMessageBusSource} from "./web_workers/shared/post_message_bus"; +import {BaseException} from "./facade/exceptions"; +import {PromiseWrapper} from "./facade/async"; + +const WORKER_RENDER_PLATFORM_MARKER = new OpaqueToken('WorkerRenderPlatformMarker'); + +/** + * Wrapper class that exposes the Worker + * and underlying {@link MessageBus} for lower level message passing. + */ +@Injectable() +export class WebWorkerInstance { + public worker: Worker; + public bus: MessageBus; + + /** @internal */ + public init(worker: Worker, bus: MessageBus) { + this.worker = worker; + this.bus = bus; + } +} + +export const WORKER_SCRIPT: OpaqueToken = new OpaqueToken("WebWorkerScript"); + +/** + * A multiple providers used to automatically call the `start()` method after the service is + * created. + * + * TODO(vicb): create an interface for startable services to implement + */ +export const WORKER_RENDER_STARTABLE_MESSAGING_SERVICE = new OpaqueToken('WorkerRenderStartableMsgService'); + +export const WORKER_RENDER_PLATFORM_PROVIDERS: Array = [ + PLATFORM_COMMON_PROVIDERS, + {provide: WORKER_RENDER_PLATFORM_MARKER, useValue: true}, + {provide: PLATFORM_INITIALIZER, useValue: initWebWorkerRenderPlatform, multi: true} +]; + +export const WORKER_RENDER_APPLICATION_PROVIDERS: Array = + [ + APPLICATION_COMMON_PROVIDERS, + MessageBasedRenderer, + {provide: WORKER_RENDER_STARTABLE_MESSAGING_SERVICE, useExisting: MessageBasedRenderer, multi: true}, + BROWSER_SANITIZATION_PROVIDERS, + {provide: ExceptionHandler, useFactory: _exceptionHandler, deps: []}, + {provide: DOCUMENT, useFactory: _document, deps: []}, + // TODO(jteplitz602): Investigate if we definitely need EVENT_MANAGER on the render thread + // #5298 + {provide: EVENT_MANAGER_PLUGINS, useClass: DomEventsPlugin, multi: true}, + {provide: EVENT_MANAGER_PLUGINS, useClass: KeyEventsPlugin, multi: true}, + {provide: EVENT_MANAGER_PLUGINS, useClass: HammerGesturesPlugin, multi: true}, + {provide: HAMMER_GESTURE_CONFIG, useClass: HammerGestureConfig}, + {provide: DomRootRenderer, useClass: DomRootRenderer_}, + {provide: RootRenderer, useExisting: DomRootRenderer}, + {provide: SharedStylesHost, useExisting: DomSharedStylesHost}, + {provide: ServiceMessageBrokerFactory, useClass: ServiceMessageBrokerFactory_}, + {provide: ClientMessageBrokerFactory, useClass: ClientMessageBrokerFactory_}, + Serializer, + {provide: ON_WEB_WORKER, useValue: false}, + RenderStore, + DomSharedStylesHost, + Testability, + BrowserDetails, + AnimationBuilder, + EventManager, + WebWorkerInstance, + { + provide: APP_INITIALIZER, + useFactory: (injector => () => initWebWorkerApplication(injector)), + multi: true, + deps: [Injector] + }, + { + provide: MessageBus, + useFactory: (instance) => instance.bus, + deps: [WebWorkerInstance] + } + ]; + +export function initializeGenericWorkerRenderer(injector: Injector) { + var bus = injector.get(MessageBus); + let zone = injector.get(NgZone); + bus.attachToZone(zone); + + // initialize message services after the bus has been created + let services = injector.get(WORKER_RENDER_STARTABLE_MESSAGING_SERVICE); + zone.runGuarded(() => { services.forEach((svc) => { svc.start(); }); }); +} + +export function bootstrapRender( + workerScriptUri: string, + customProviders?: Array): Promise { + var app = ReflectiveInjector.resolveAndCreate( + [ + WORKER_RENDER_APPLICATION_PROVIDERS, + BROWSER_APP_COMPILER_PROVIDERS, + {provide: WORKER_SCRIPT, useValue: workerScriptUri}, + isPresent(customProviders) ? customProviders : [] + ], + workerRenderPlatform().injector); + // Return a promise so that we keep the same semantics as Dart, + // and we might want to wait for the app side to come up + // in the future... + return PromiseWrapper.resolve(app.get(ApplicationRef)); +} + +function initWebWorkerRenderPlatform(): void { + BrowserDomAdapter.makeCurrent(); + wtfInit(); + BrowserGetTestability.init(); +} + +export function workerRenderPlatform(): PlatformRef { + if (isBlank(getPlatform())) { + createPlatform(ReflectiveInjector.resolveAndCreate(WORKER_RENDER_PLATFORM_PROVIDERS)); + } + return assertPlatform(WORKER_RENDER_PLATFORM_MARKER); +} + +function _exceptionHandler(): ExceptionHandler { + return new ExceptionHandler(getDOM()); +} + +function _document(): any { + return getDOM().defaultDoc(); +} + +function initWebWorkerApplication(injector: Injector): void { + var scriptUri: string; + try { + scriptUri = injector.get(WORKER_SCRIPT); + } catch (e) { + throw new BaseException( + "You must provide your WebWorker's initialization script with the WORKER_SCRIPT token"); + } + + let instance = injector.get(WebWorkerInstance); + spawnWebWorker(scriptUri, instance); + + initializeGenericWorkerRenderer(injector); +} + +/** + * Spawns a new class and initializes the WebWorkerInstance + */ +function spawnWebWorker(uri: string, instance: WebWorkerInstance): void { + var webWorker: Worker = new Worker(uri); + var sink = new PostMessageBusSink(webWorker); + var source = new PostMessageBusSource(webWorker); + var bus = new PostMessageBus(sink, source); + + instance.init(webWorker, bus); +} diff --git a/modules/@angular/platform-browser/test/browser/bootstrap_spec.ts b/modules/@angular/platform-browser/test/browser/bootstrap_spec.ts index b8e20d3a81..db902f251e 100644 --- a/modules/@angular/platform-browser/test/browser/bootstrap_spec.ts +++ b/modules/@angular/platform-browser/test/browser/bootstrap_spec.ts @@ -1,40 +1,40 @@ import { beforeEach, afterEach, - ddescribe, describe, expect, - iit, inject, it, - xdescribe, - xit -} from '@angular/core/testing/testing_internal'; -import {Log} from '@angular/core/testing'; -import {AsyncTestCompleter} from '@angular/core/testing/testing_internal'; -import {stringify} from '../../src/facade/lang'; -import {BROWSER_PLATFORM_PROVIDERS} from '@angular/platform-browser'; -import {BROWSER_APP_PROVIDERS} from '@angular/platform-browser'; -import {bootstrap} from '@angular/platform-browser'; -import {ApplicationRef} from '@angular/core/src/application_ref'; -import {Console} from '@angular/core/src/console'; -import {Component, Directive, OnDestroy} from '@angular/core'; -import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter'; -import {DOCUMENT} from '@angular/platform-browser/src/dom/dom_tokens'; -import {PromiseWrapper} from '../../src/facade/async'; + AsyncTestCompleter +} from "@angular/core/testing/testing_internal"; +import {Log} from "@angular/core/testing"; +import {stringify} from "../../src/facade/lang"; import { + BROWSER_PLATFORM_PROVIDERS, + BROWSER_APP_PROVIDERS, + BROWSER_APP_COMPILER_PROVIDERS, + bootstrap +} from "@angular/platform-browser"; +import {ApplicationRef, disposePlatform} from "@angular/core/src/application_ref"; +import {Console} from "@angular/core/src/console"; +import { + Component, + Directive, + OnDestroy, provide, Inject, PLATFORM_INITIALIZER, APP_INITIALIZER, coreLoadAndBootstrap, createPlatform, - ReflectiveInjector -} from '@angular/core'; -import {disposePlatform} from '@angular/core/src/application_ref'; -import {ExceptionHandler, BaseException} from '@angular/core'; -import {Testability, TestabilityRegistry} from '@angular/core/src/testability/testability'; -import {ComponentRef} from '@angular/core/src/linker/component_factory'; + ReflectiveInjector, + ExceptionHandler +} from "@angular/core"; +import {getDOM} from "@angular/platform-browser/src/dom/dom_adapter"; +import {DOCUMENT} from "@angular/platform-browser/src/dom/dom_tokens"; +import {PromiseWrapper} from "../../src/facade/async"; +import {Testability, TestabilityRegistry} from "@angular/core/src/testability/testability"; +import {ComponentRef} from "@angular/core/src/linker/component_factory"; @Component({selector: 'hello-app', template: '{{greeting}} world!'}) class HelloRootCmp { @@ -211,7 +211,7 @@ export function main() { inject([AsyncTestCompleter], (async) => { var platform = createPlatform(ReflectiveInjector.resolveAndCreate(BROWSER_PLATFORM_PROVIDERS)); var app = - ReflectiveInjector.resolveAndCreate([BROWSER_APP_PROVIDERS, testProviders], + ReflectiveInjector.resolveAndCreate([BROWSER_APP_PROVIDERS, BROWSER_APP_COMPILER_PROVIDERS, testProviders], platform.injector) .get(ApplicationRef); coreLoadAndBootstrap(HelloRootCmp, app.injector) diff --git a/modules/@angular/platform-browser/test/testing_public_spec.ts b/modules/@angular/platform-browser/test/testing_public_spec.ts index af4c27b825..4e9fdaca05 100644 --- a/modules/@angular/platform-browser/test/testing_public_spec.ts +++ b/modules/@angular/platform-browser/test/testing_public_spec.ts @@ -13,13 +13,11 @@ import { import { fakeAsync, async, - flushMicrotasks, withProviders, - Log, tick, } from '@angular/core/testing'; import {TestComponentBuilder} from '@angular/compiler/testing'; -import {Injectable, bind, Component, ViewMetadata} from '@angular/core'; +import {Injectable, provide, Component, ViewMetadata} from '@angular/core'; import {NgIf} from '@angular/common'; import {PromiseWrapper} from '../../http/src/facade/promise'; @@ -136,7 +134,7 @@ export function main() { describe('using the test injector with the inject helper', () => { describe('setting up Providers', () => { - beforeEachProviders(() => [bind(FancyService).toValue(new FancyService())]); + beforeEachProviders(() => [provide(FancyService, {useValue: new FancyService()})]); it('should use set up providers', inject([FancyService], (service) => { expect(service.value).toEqual('real value'); })); @@ -187,12 +185,12 @@ export function main() { describe('per test providers', () => { it('should allow per test providers', - withProviders(() => [bind(FancyService).toValue(new FancyService())]) + withProviders(() => [provide(FancyService, {useValue: new FancyService()})]) .inject([FancyService], (service) => { expect(service.value).toEqual('real value'); })); it('should return value from inject', () => { - let retval = withProviders(() => [bind(FancyService).toValue(new FancyService())]) + let retval = withProviders(() => [provide(FancyService, {useValue: new FancyService()})]) .inject([FancyService], (service) => { expect(service.value).toEqual('real value'); return 10; @@ -233,7 +231,7 @@ export function main() { }; var restoreJasmineBeforeEach = - () => { jasmine.getEnv().beforeEach = originalJasmineBeforeEach; } + () => { jasmine.getEnv().beforeEach = originalJasmineBeforeEach; }; it('should fail when an asynchronous error is thrown', (done) => { var itPromise = patchJasmineIt(); @@ -267,7 +265,7 @@ export function main() { }); describe('using beforeEachProviders', () => { - beforeEachProviders(() => [bind(FancyService).toValue(new FancyService())]); + beforeEachProviders(() => [provide(FancyService, {useValue: new FancyService()})]); beforeEach( inject([FancyService], (service) => { expect(service.value).toEqual('real value'); })); @@ -277,7 +275,7 @@ export function main() { it('should fail when the injector has already been used', () => { patchJasmineBeforeEach(); expect(() => { - beforeEachProviders(() => [bind(FancyService).toValue(new FancyService())]); + beforeEachProviders(() => [provide(FancyService, {useValue: new FancyService()})]); }) .toThrowError('beforeEachProviders was called after the injector had been used ' + 'in a beforeEach or it block. This invalidates the test injector'); @@ -366,7 +364,7 @@ export function main() { it('should override a provider', async(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => { - tcb.overrideProviders(TestProvidersComp, [bind(FancyService).toClass(MockFancyService)]) + tcb.overrideProviders(TestProvidersComp, [provide(FancyService, {useClass: MockFancyService})]) .createAsync(TestProvidersComp) .then((componentFixture) => { componentFixture.detectChanges(); @@ -380,7 +378,7 @@ export function main() { async(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => { tcb.overrideViewProviders(TestViewProvidersComp, - [bind(FancyService).toClass(MockFancyService)]) + [provide(FancyService, {useClass: MockFancyService})]) .createAsync(TestViewProvidersComp) .then((componentFixture) => { componentFixture.detectChanges(); diff --git a/modules/@angular/platform-browser/test/web_workers/worker/renderer_integration_spec.ts b/modules/@angular/platform-browser/test/web_workers/worker/renderer_integration_spec.ts index 802962f947..63e29188ee 100644 --- a/modules/@angular/platform-browser/test/web_workers/worker/renderer_integration_spec.ts +++ b/modules/@angular/platform-browser/test/web_workers/worker/renderer_integration_spec.ts @@ -13,23 +13,18 @@ import {TestInjector} from '@angular/core/testing'; import {TestComponentBuilder} from '@angular/compiler/testing'; import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter'; import { - bind, provide, - Provider, Injector, ViewMetadata, Component, Injectable, - ElementRef, ComponentRef } from '@angular/core'; import {NgIf} from '@angular/common'; import {WebWorkerRootRenderer} from '@angular/platform-browser/src/web_workers/worker/renderer'; import { ClientMessageBrokerFactory, - ClientMessageBrokerFactory_, - UiArguments, - FnArg + ClientMessageBrokerFactory_ } from '@angular/platform-browser/src/web_workers/shared/client_message_broker'; import {Serializer} from '@angular/platform-browser/src/web_workers/shared/serializer'; import {RootRenderer} from '@angular/core/src/render/api'; @@ -39,14 +34,13 @@ import {RenderStore} from '@angular/platform-browser/src/web_workers/shared/rend import {MessageBasedRenderer} from '@angular/platform-browser/src/web_workers/ui/renderer'; import {createPairedMessageBuses, PairedMessageBuses} from '../shared/web_worker_test_util'; import { - ServiceMessageBrokerFactory, ServiceMessageBrokerFactory_ } from '@angular/platform-browser/src/web_workers/shared/service_message_broker'; import {CompilerConfig} from '@angular/compiler'; import {dispatchEvent} from '../../../../platform-browser/testing/browser_util'; import { - TEST_BROWSER_STATIC_PLATFORM_PROVIDERS, - TEST_BROWSER_STATIC_APPLICATION_PROVIDERS + TEST_BROWSER_PLATFORM_PROVIDERS, + TEST_BROWSER_APPLICATION_PROVIDERS } from '@angular/platform-browser/testing'; export function main() { @@ -88,8 +82,8 @@ export function main() { beforeEachProviders(() => { uiRenderStore = new RenderStore(); var testUiInjector = new TestInjector(); - testUiInjector.platformProviders = TEST_BROWSER_STATIC_PLATFORM_PROVIDERS; - testUiInjector.applicationProviders = TEST_BROWSER_STATIC_APPLICATION_PROVIDERS; + testUiInjector.platformProviders = TEST_BROWSER_PLATFORM_PROVIDERS; + testUiInjector.applicationProviders = TEST_BROWSER_APPLICATION_PROVIDERS; testUiInjector.addProviders([ Serializer, provide(RenderStore, {useValue: uiRenderStore}), diff --git a/modules/@angular/platform-browser/test/xhr/xhr_impl_spec.ts b/modules/@angular/platform-browser/test/xhr/xhr_impl_spec.ts index 70a87c01c0..0a2d815142 100644 --- a/modules/@angular/platform-browser/test/xhr/xhr_impl_spec.ts +++ b/modules/@angular/platform-browser/test/xhr/xhr_impl_spec.ts @@ -11,7 +11,6 @@ import { } from '@angular/core/testing/testing_internal'; import {XHRImpl} from '../../src/xhr/xhr_impl'; import {PromiseWrapper} from '../../src/facade/async'; -import {IS_DART} from '../../src/facade/lang'; export function main() { describe('XHRImpl', () => { @@ -23,8 +22,7 @@ export function main() { // will be relative to here, so url200 should look like // static_assets/200.html. // We currently have no way of detecting this. - var urlBase = IS_DART ? '' : '/base/modules/@angular/'; - var url200 = urlBase + 'platform-browser/test/browser/static_assets/200.html'; + var url200 = '/base/modules/@angular/platform-browser/test/browser/static_assets/200.html'; var url404 = '/bad/path/404.html'; beforeEach(() => { xhr = new XHRImpl(); }); diff --git a/modules/@angular/platform-browser/testing/benchmark_util.ts b/modules/@angular/platform-browser/testing/benchmark_util.ts index 9a37b17e34..a23b5c5dca 100644 --- a/modules/@angular/platform-browser/testing/benchmark_util.ts +++ b/modules/@angular/platform-browser/testing/benchmark_util.ts @@ -1,7 +1,7 @@ import {BrowserDomAdapter} from '../src/browser/browser_adapter'; import {document, window} from '../src/facade/browser'; import {NumberWrapper, isBlank} from '../src/facade/lang'; -import {BaseException, WrappedException} from '../src/facade/exceptions'; +import {BaseException} from '../src/facade/exceptions'; var DOM = new BrowserDomAdapter(); diff --git a/modules/@angular/platform-browser/testing/browser.ts b/modules/@angular/platform-browser/testing/browser.ts index 9b307b995a..8733eea60f 100644 --- a/modules/@angular/platform-browser/testing/browser.ts +++ b/modules/@angular/platform-browser/testing/browser.ts @@ -1,37 +1,35 @@ -import { - TEST_BROWSER_STATIC_PLATFORM_PROVIDERS, - ADDITIONAL_TEST_BROWSER_STATIC_PROVIDERS -} from './browser_static'; -import {BROWSER_APP_PROVIDERS} from '../index'; -import {DirectiveResolver, ViewResolver} from '@angular/compiler'; +import {TEST_BROWSER_STATIC_PLATFORM_PROVIDERS, ADDITIONAL_TEST_BROWSER_STATIC_PROVIDERS} from "./browser_static"; +import {BROWSER_APP_PROVIDERS, BROWSER_APP_COMPILER_PROVIDERS} from "../index"; +import {DirectiveResolver, ViewResolver} from "@angular/compiler"; import { MockDirectiveResolver, MockViewResolver, TestComponentRenderer, TestComponentBuilder -} from '@angular/compiler/testing'; -import {DOMTestComponentRenderer} from './dom_test_component_renderer'; +} from "@angular/compiler/testing"; +import {DOMTestComponentRenderer} from "./dom_test_component_renderer"; /** * Default platform providers for testing. */ export const TEST_BROWSER_PLATFORM_PROVIDERS: Array = - /*@ts2dart_const*/[TEST_BROWSER_STATIC_PLATFORM_PROVIDERS]; + [TEST_BROWSER_STATIC_PLATFORM_PROVIDERS]; export const ADDITIONAL_TEST_BROWSER_PROVIDERS = [ - /*@ts2dart_Provider*/ {provide: DirectiveResolver, useClass: MockDirectiveResolver}, - /*@ts2dart_Provider*/ {provide: ViewResolver, useClass: MockViewResolver}, + {provide: DirectiveResolver, useClass: MockDirectiveResolver}, + {provide: ViewResolver, useClass: MockViewResolver}, TestComponentBuilder, - /*@ts2dart_Provider*/ {provide: TestComponentRenderer, useClass: DOMTestComponentRenderer}, + {provide: TestComponentRenderer, useClass: DOMTestComponentRenderer}, ]; /** * Default application providers for testing. */ export const TEST_BROWSER_APPLICATION_PROVIDERS: Array = - /*@ts2dart_const*/[ + [ BROWSER_APP_PROVIDERS, + BROWSER_APP_COMPILER_PROVIDERS, ADDITIONAL_TEST_BROWSER_STATIC_PROVIDERS, ADDITIONAL_TEST_BROWSER_PROVIDERS ]; diff --git a/modules/@angular/platform-browser/testing/browser_static.ts b/modules/@angular/platform-browser/testing/browser_static.ts index 03d51642fc..5149ce7bc7 100644 --- a/modules/@angular/platform-browser/testing/browser_static.ts +++ b/modules/@angular/platform-browser/testing/browser_static.ts @@ -1,15 +1,38 @@ import {APP_ID, NgZone, PLATFORM_COMMON_PROVIDERS, PLATFORM_INITIALIZER} from '@angular/core'; -import {BROWSER_APP_COMMON_PROVIDERS} from '../src/platform/common/browser'; +import {BROWSER_APP_PROVIDERS} from '../src/browser'; import {BrowserDomAdapter} from '../src/browser/browser_adapter'; import {AnimationBuilder} from '../src/animate/animation_builder'; import {MockAnimationBuilder} from './animation_builder_mock'; import {MockLocationStrategy} from '@angular/common/testing'; import {LocationStrategy} from '@angular/common'; -import {MockNgZone} from '@angular/core/testing'; import {BrowserDetection} from './browser_util'; import {Log} from '@angular/core/testing'; import {ELEMENT_PROBE_PROVIDERS} from '../src/dom/debug/ng_probe'; -import {IS_DART} from '../src/facade/lang'; + +/** + * Default platform providers for testing without a compiler. + */ +export const TEST_BROWSER_STATIC_PLATFORM_PROVIDERS: Array = + [ + PLATFORM_COMMON_PROVIDERS, + {provide: PLATFORM_INITIALIZER, useValue: initBrowserTests, multi: true} + ]; + +export const ADDITIONAL_TEST_BROWSER_STATIC_PROVIDERS: Array = + [ + {provide: APP_ID, useValue: 'a'}, + ELEMENT_PROBE_PROVIDERS, + Log, + {provide: NgZone, useFactory: createNgZone}, + {provide: LocationStrategy, useClass: MockLocationStrategy}, + {provide: AnimationBuilder, useClass: MockAnimationBuilder} + ]; + +/** + * Default application providers for testing without a compiler. + */ +export const TEST_BROWSER_STATIC_APPLICATION_PROVIDERS: Array = + [BROWSER_APP_PROVIDERS, ADDITIONAL_TEST_BROWSER_STATIC_PROVIDERS]; function initBrowserTests() { BrowserDomAdapter.makeCurrent(); @@ -17,30 +40,5 @@ function initBrowserTests() { } function createNgZone(): NgZone { - return IS_DART ? new MockNgZone() : new NgZone({enableLongStackTrace: true}); + return new NgZone({enableLongStackTrace: true}); } - -/** - * Default platform providers for testing without a compiler. - */ -export const TEST_BROWSER_STATIC_PLATFORM_PROVIDERS: Array = - /*@ts2dart_const*/[ - PLATFORM_COMMON_PROVIDERS, - /*@ts2dart_Provider*/{provide: PLATFORM_INITIALIZER, useValue: initBrowserTests, multi: true} - ]; - -export const ADDITIONAL_TEST_BROWSER_STATIC_PROVIDERS: Array = - /*@ts2dart_const*/[ - /*@ts2dart_Provider*/ {provide: APP_ID, useValue: 'a'}, - ELEMENT_PROBE_PROVIDERS, - Log, - /*@ts2dart_Provider*/ {provide: NgZone, useFactory: createNgZone}, - /*@ts2dart_Provider*/ {provide: LocationStrategy, useClass: MockLocationStrategy}, - /*@ts2dart_Provider*/ {provide: AnimationBuilder, useClass: MockAnimationBuilder} - ]; - -/** - * Default application providers for testing without a compiler. - */ -export const TEST_BROWSER_STATIC_APPLICATION_PROVIDERS: Array = - /*@ts2dart_const*/[BROWSER_APP_COMMON_PROVIDERS, ADDITIONAL_TEST_BROWSER_STATIC_PROVIDERS]; diff --git a/modules/@angular/upgrade/src/upgrade_adapter.ts b/modules/@angular/upgrade/src/upgrade_adapter.ts index 226d1424bb..eef14e296d 100644 --- a/modules/@angular/upgrade/src/upgrade_adapter.ts +++ b/modules/@angular/upgrade/src/upgrade_adapter.ts @@ -10,11 +10,10 @@ import { Provider, Type, Testability -} from '@angular/core'; -import {browserPlatform} from '@angular/platform-browser'; -import {BROWSER_APP_PROVIDERS} from '@angular/platform-browser'; -import {getComponentInfo, ComponentInfo} from './metadata'; -import {onError, controllerKey} from './util'; +} from "@angular/core"; +import {browserPlatform, BROWSER_APP_PROVIDERS, BROWSER_APP_COMPILER_PROVIDERS} from "@angular/platform-browser"; +import {getComponentInfo, ComponentInfo} from "./metadata"; +import {onError, controllerKey} from "./util"; import { NG1_COMPILE, NG1_INJECTOR, @@ -26,10 +25,10 @@ import { NG2_COMPONENT_FACTORY_REF_MAP, NG2_ZONE, REQUIRE_INJECTOR -} from './constants'; -import {DowngradeNg2ComponentAdapter} from './downgrade_ng2_adapter'; -import {UpgradeNg1ComponentAdapterBuilder} from './upgrade_ng1_adapter'; -import * as angular from './angular_js'; +} from "./constants"; +import {DowngradeNg2ComponentAdapter} from "./downgrade_ng2_adapter"; +import {UpgradeNg1ComponentAdapterBuilder} from "./upgrade_ng1_adapter"; +import * as angular from "./angular_js"; var upgradeCount: number = 0; @@ -295,6 +294,7 @@ export class UpgradeAdapter { ReflectiveInjector.resolveAndCreate( [ BROWSER_APP_PROVIDERS, + BROWSER_APP_COMPILER_PROVIDERS, provide(NG1_INJECTOR, {useFactory: () => ng1Injector}), provide(NG1_COMPILE, {useFactory: () => ng1Injector.get(NG1_COMPILE)}), diff --git a/modules/@angular/upgrade/test/upgrade_spec.ts b/modules/@angular/upgrade/test/upgrade_spec.ts index 0d89b86955..ab7cc8cb35 100644 --- a/modules/@angular/upgrade/test/upgrade_spec.ts +++ b/modules/@angular/upgrade/test/upgrade_spec.ts @@ -1,26 +1,7 @@ -import { - beforeEach, - ddescribe, - describe, - expect, - iit, - inject, - it, - xdescribe, - xit, -} from '@angular/core/testing/testing_internal'; -import {AsyncTestCompleter} from '@angular/core/testing/testing_internal'; -import { - Component, - Class, - Inject, - EventEmitter, - ApplicationRef, - provide, - Testability, -} from '@angular/core'; -import {UpgradeAdapter} from '@angular/upgrade'; -import * as angular from '@angular/upgrade/src/angular_js'; +import {describe, expect, inject, it, AsyncTestCompleter} from "@angular/core/testing/testing_internal"; +import {Component, Class, EventEmitter, provide, Testability} from "@angular/core"; +import {UpgradeAdapter} from "@angular/upgrade"; +import * as angular from "@angular/upgrade/src/angular_js"; export function main() { describe('adapter: ng1 to ng2', () => { diff --git a/modules/playground/e2e_test/web_workers/input/input_spec.ts b/modules/playground/e2e_test/web_workers/input/input_spec.ts index 3324db22e5..91b322dba1 100644 --- a/modules/playground/e2e_test/web_workers/input/input_spec.ts +++ b/modules/playground/e2e_test/web_workers/input/input_spec.ts @@ -12,7 +12,6 @@ describe('WebWorkers Input', function() { it('should bootstrap', () => { // This test can't wait for Angular 2 as Testability is not available when using WebWorker browser.ignoreSynchronization = true; - browser.get('/'); browser.get(URL); waitForBootstrap(); @@ -23,7 +22,6 @@ describe('WebWorkers Input', function() { it('should bind to input value', () => { // This test can't wait for Angular 2 as Testability is not available when using WebWorker browser.ignoreSynchronization = true; - browser.get('/'); browser.get(URL); waitForBootstrap(); @@ -38,7 +36,6 @@ describe('WebWorkers Input', function() { it('should bind to textarea value', () => { // This test can't wait for Angular 2 as Testability is not available when using WebWorker browser.ignoreSynchronization = true; - browser.get('/'); browser.get(URL); waitForBootstrap();