2016-06-23 12:47:54 -04:00
|
|
|
/**
|
|
|
|
* @license
|
|
|
|
* Copyright Google Inc. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
|
|
* found in the LICENSE file at https://angular.io/license
|
|
|
|
*/
|
|
|
|
|
2016-08-11 23:40:46 -04:00
|
|
|
import {CommonModule} from '@angular/common';
|
2017-02-17 01:36:21 -05:00
|
|
|
import {APP_INITIALIZER, ApplicationModule, ErrorHandler, NgModule, NgZone, PlatformRef, Provider, RendererFactoryV2, RootRenderer, createPlatformFactory, platformCore} from '@angular/core';
|
2017-02-17 15:55:55 -05:00
|
|
|
import {DOCUMENT, ɵBROWSER_SANITIZATION_PROVIDERS as BROWSER_SANITIZATION_PROVIDERS} from '@angular/platform-browser';
|
2016-06-08 19:38:52 -04:00
|
|
|
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';
|
|
|
|
import {PostMessageBus, PostMessageBusSink, PostMessageBusSource} from './web_workers/shared/post_message_bus';
|
|
|
|
import {RenderStore} from './web_workers/shared/render_store';
|
|
|
|
import {Serializer} from './web_workers/shared/serializer';
|
|
|
|
import {ServiceMessageBrokerFactory, ServiceMessageBrokerFactory_} from './web_workers/shared/service_message_broker';
|
2017-02-17 01:36:21 -05:00
|
|
|
import {WebWorkerRendererFactoryV2, WebWorkerRootRenderer} from './web_workers/worker/renderer';
|
2016-06-08 19:38:52 -04:00
|
|
|
import {WorkerDomAdapter} from './web_workers/worker/worker_adapter';
|
2016-05-20 19:11:49 -04:00
|
|
|
|
2016-08-24 16:39:44 -04:00
|
|
|
|
2016-08-30 21:07:40 -04:00
|
|
|
|
2016-06-15 11:41:41 -04:00
|
|
|
/**
|
|
|
|
* @experimental
|
|
|
|
*/
|
2016-07-26 08:21:19 -04:00
|
|
|
export const platformWorkerApp = createPlatformFactory(platformCore, 'workerApp');
|
|
|
|
|
2016-08-25 03:50:16 -04:00
|
|
|
export function errorHandler(): ErrorHandler {
|
|
|
|
return new ErrorHandler();
|
2016-05-20 19:11:49 -04:00
|
|
|
}
|
|
|
|
|
2016-08-30 14:15:25 -04:00
|
|
|
|
2016-05-20 19:11:49 -04:00
|
|
|
// TODO(jteplitz602) remove this and compile with lib.webworker.d.ts (#3492)
|
2016-11-12 08:08:58 -05:00
|
|
|
const _postMessage = {
|
2016-06-08 19:38:52 -04:00
|
|
|
postMessage: (message: any, transferrables?: [ArrayBuffer]) => {
|
2016-05-20 19:11:49 -04:00
|
|
|
(<any>postMessage)(message, transferrables);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-08-22 20:37:48 -04:00
|
|
|
export function createMessageBus(zone: NgZone): MessageBus {
|
2016-11-12 08:08:58 -05:00
|
|
|
const sink = new PostMessageBusSink(_postMessage);
|
|
|
|
const source = new PostMessageBusSource();
|
|
|
|
const bus = new PostMessageBus(sink, source);
|
2016-05-20 19:11:49 -04:00
|
|
|
bus.attachToZone(zone);
|
|
|
|
return bus;
|
|
|
|
}
|
|
|
|
|
2016-08-22 20:37:48 -04:00
|
|
|
export function setupWebWorker(): void {
|
2016-05-20 19:11:49 -04:00
|
|
|
WorkerDomAdapter.makeCurrent();
|
2016-06-10 13:21:53 -04:00
|
|
|
}
|
refactor(core): clean up platform bootstrap and initTestEnvironment
- Introduces `CompilerFactory` which can be part of a `PlatformRef`.
- Introduces `WorkerAppModule`, `WorkerUiModule`, `ServerModule`
- Introduces `serverDynamicPlatform` for applications using runtime compilation
on the server.
- Changes browser bootstrap for runtime and offline compilation (see below for an example).
* introduces `bootstrapModule` and `bootstrapModuleFactory` in `@angular/core`
* introduces new `browserDynamicPlatform` in `@angular/platform-browser-dynamic
- Changes `initTestEnvironment` (which used to be `setBaseTestProviders`) to not take a compiler factory any more (see below for an example).
BREAKING CHANGE:
## Migration from `setBaseTestProviders` to `initTestEnvironment`:
- For the browser platform:
BEFORE:
```
import {setBaseTestProviders} from ‘@angular/core/testing’;
import {TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS} from ‘@angular/platform-browser-dynamic/testing’;
setBaseTestProviders(TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS);
```
AFTER:
```
import {initTestEnvironment} from ‘@angular/core/testing’;
import {browserDynamicTestPlatform,
BrowserDynamicTestModule} from ‘@angular/platform-browser-dynamic/testing’;
initTestEnvironment(
BrowserDynamicTestModule,
browserDynamicTestPlatform());
```
- For the server platform:
BEFORE:
```
import {setBaseTestProviders} from ‘@angular/core/testing’;
import {TEST_SERVER_PLATFORM_PROVIDERS,
TEST_SERVER_APPLICATION_PROVIDERS} from ‘@angular/platform-server/testing/server’;
setBaseTestProviders(TEST_SERVER_PLATFORM_PROVIDERS,
TEST_SERVER_APPLICATION_PROVIDERS);
```
AFTER:
```
import {initTestEnvironment} from ‘@angular/core/testing’;
import {serverTestPlatform,
ServerTestModule} from ‘@angular/platform-browser-dynamic/testing’;
initTestEnvironment(
ServerTestModule,
serverTestPlatform());
```
## Bootstrap changes
```
@AppModule({
modules: [BrowserModule],
precompile: [MainComponent],
providers: […], // additional providers
directives: […], // additional platform directives
pipes: […] // additional platform pipes
})
class MyModule {
constructor(appRef: ApplicationRef) {
appRef.bootstrap(MainComponent);
}
}
// offline compile
import {browserPlatform} from ‘@angular/platform-browser’;
import {bootstrapModuleFactory} from ‘@angular/core’;
bootstrapModuleFactory(MyModuleNgFactory, browserPlatform());
// runtime compile long form
import {browserDynamicPlatform} from ‘@angular/platform-browser-dynamic’;
import {bootstrapModule} from ‘@angular/core’;
bootstrapModule(MyModule, browserDynamicPlatform());
```
Closes #9922
Part of #9726
2016-07-08 13:47:17 -04:00
|
|
|
|
|
|
|
/**
|
2016-07-18 06:50:31 -04:00
|
|
|
* The ng module for the worker app side.
|
refactor(core): clean up platform bootstrap and initTestEnvironment
- Introduces `CompilerFactory` which can be part of a `PlatformRef`.
- Introduces `WorkerAppModule`, `WorkerUiModule`, `ServerModule`
- Introduces `serverDynamicPlatform` for applications using runtime compilation
on the server.
- Changes browser bootstrap for runtime and offline compilation (see below for an example).
* introduces `bootstrapModule` and `bootstrapModuleFactory` in `@angular/core`
* introduces new `browserDynamicPlatform` in `@angular/platform-browser-dynamic
- Changes `initTestEnvironment` (which used to be `setBaseTestProviders`) to not take a compiler factory any more (see below for an example).
BREAKING CHANGE:
## Migration from `setBaseTestProviders` to `initTestEnvironment`:
- For the browser platform:
BEFORE:
```
import {setBaseTestProviders} from ‘@angular/core/testing’;
import {TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS} from ‘@angular/platform-browser-dynamic/testing’;
setBaseTestProviders(TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS);
```
AFTER:
```
import {initTestEnvironment} from ‘@angular/core/testing’;
import {browserDynamicTestPlatform,
BrowserDynamicTestModule} from ‘@angular/platform-browser-dynamic/testing’;
initTestEnvironment(
BrowserDynamicTestModule,
browserDynamicTestPlatform());
```
- For the server platform:
BEFORE:
```
import {setBaseTestProviders} from ‘@angular/core/testing’;
import {TEST_SERVER_PLATFORM_PROVIDERS,
TEST_SERVER_APPLICATION_PROVIDERS} from ‘@angular/platform-server/testing/server’;
setBaseTestProviders(TEST_SERVER_PLATFORM_PROVIDERS,
TEST_SERVER_APPLICATION_PROVIDERS);
```
AFTER:
```
import {initTestEnvironment} from ‘@angular/core/testing’;
import {serverTestPlatform,
ServerTestModule} from ‘@angular/platform-browser-dynamic/testing’;
initTestEnvironment(
ServerTestModule,
serverTestPlatform());
```
## Bootstrap changes
```
@AppModule({
modules: [BrowserModule],
precompile: [MainComponent],
providers: […], // additional providers
directives: […], // additional platform directives
pipes: […] // additional platform pipes
})
class MyModule {
constructor(appRef: ApplicationRef) {
appRef.bootstrap(MainComponent);
}
}
// offline compile
import {browserPlatform} from ‘@angular/platform-browser’;
import {bootstrapModuleFactory} from ‘@angular/core’;
bootstrapModuleFactory(MyModuleNgFactory, browserPlatform());
// runtime compile long form
import {browserDynamicPlatform} from ‘@angular/platform-browser-dynamic’;
import {bootstrapModule} from ‘@angular/core’;
bootstrapModule(MyModule, browserDynamicPlatform());
```
Closes #9922
Part of #9726
2016-07-08 13:47:17 -04:00
|
|
|
*
|
|
|
|
* @experimental
|
|
|
|
*/
|
2016-07-18 06:50:31 -04:00
|
|
|
@NgModule({
|
|
|
|
providers: [
|
2017-02-16 17:09:06 -05:00
|
|
|
BROWSER_SANITIZATION_PROVIDERS,
|
|
|
|
Serializer,
|
|
|
|
{provide: DOCUMENT, useValue: null},
|
2016-07-18 06:50:31 -04:00
|
|
|
{provide: ClientMessageBrokerFactory, useClass: ClientMessageBrokerFactory_},
|
|
|
|
{provide: ServiceMessageBrokerFactory, useClass: ServiceMessageBrokerFactory_},
|
2017-02-16 17:09:06 -05:00
|
|
|
WebWorkerRootRenderer,
|
|
|
|
{provide: RootRenderer, useExisting: WebWorkerRootRenderer},
|
2017-02-17 01:36:21 -05:00
|
|
|
WebWorkerRendererFactoryV2,
|
|
|
|
{provide: RendererFactoryV2, useExisting: WebWorkerRendererFactoryV2},
|
2017-02-16 17:09:06 -05:00
|
|
|
{provide: ON_WEB_WORKER, useValue: true},
|
|
|
|
RenderStore,
|
2016-08-25 03:50:16 -04:00
|
|
|
{provide: ErrorHandler, useFactory: errorHandler, deps: []},
|
2016-07-18 06:50:31 -04:00
|
|
|
{provide: MessageBus, useFactory: createMessageBus, deps: [NgZone]},
|
2017-02-16 17:09:06 -05:00
|
|
|
{provide: APP_INITIALIZER, useValue: setupWebWorker, multi: true},
|
2016-07-18 06:50:31 -04:00
|
|
|
],
|
2017-02-16 17:09:06 -05:00
|
|
|
exports: [
|
|
|
|
CommonModule,
|
|
|
|
ApplicationModule,
|
|
|
|
]
|
refactor(core): clean up platform bootstrap and initTestEnvironment
- Introduces `CompilerFactory` which can be part of a `PlatformRef`.
- Introduces `WorkerAppModule`, `WorkerUiModule`, `ServerModule`
- Introduces `serverDynamicPlatform` for applications using runtime compilation
on the server.
- Changes browser bootstrap for runtime and offline compilation (see below for an example).
* introduces `bootstrapModule` and `bootstrapModuleFactory` in `@angular/core`
* introduces new `browserDynamicPlatform` in `@angular/platform-browser-dynamic
- Changes `initTestEnvironment` (which used to be `setBaseTestProviders`) to not take a compiler factory any more (see below for an example).
BREAKING CHANGE:
## Migration from `setBaseTestProviders` to `initTestEnvironment`:
- For the browser platform:
BEFORE:
```
import {setBaseTestProviders} from ‘@angular/core/testing’;
import {TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS} from ‘@angular/platform-browser-dynamic/testing’;
setBaseTestProviders(TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS);
```
AFTER:
```
import {initTestEnvironment} from ‘@angular/core/testing’;
import {browserDynamicTestPlatform,
BrowserDynamicTestModule} from ‘@angular/platform-browser-dynamic/testing’;
initTestEnvironment(
BrowserDynamicTestModule,
browserDynamicTestPlatform());
```
- For the server platform:
BEFORE:
```
import {setBaseTestProviders} from ‘@angular/core/testing’;
import {TEST_SERVER_PLATFORM_PROVIDERS,
TEST_SERVER_APPLICATION_PROVIDERS} from ‘@angular/platform-server/testing/server’;
setBaseTestProviders(TEST_SERVER_PLATFORM_PROVIDERS,
TEST_SERVER_APPLICATION_PROVIDERS);
```
AFTER:
```
import {initTestEnvironment} from ‘@angular/core/testing’;
import {serverTestPlatform,
ServerTestModule} from ‘@angular/platform-browser-dynamic/testing’;
initTestEnvironment(
ServerTestModule,
serverTestPlatform());
```
## Bootstrap changes
```
@AppModule({
modules: [BrowserModule],
precompile: [MainComponent],
providers: […], // additional providers
directives: […], // additional platform directives
pipes: […] // additional platform pipes
})
class MyModule {
constructor(appRef: ApplicationRef) {
appRef.bootstrap(MainComponent);
}
}
// offline compile
import {browserPlatform} from ‘@angular/platform-browser’;
import {bootstrapModuleFactory} from ‘@angular/core’;
bootstrapModuleFactory(MyModuleNgFactory, browserPlatform());
// runtime compile long form
import {browserDynamicPlatform} from ‘@angular/platform-browser-dynamic’;
import {bootstrapModule} from ‘@angular/core’;
bootstrapModule(MyModule, browserDynamicPlatform());
```
Closes #9922
Part of #9726
2016-07-08 13:47:17 -04:00
|
|
|
})
|
|
|
|
export class WorkerAppModule {
|
2016-07-18 06:50:31 -04:00
|
|
|
}
|