2016-06-23 12:47:54 -04:00
|
|
|
/**
|
|
|
|
* @license
|
2020-05-19 15:08:49 -04:00
|
|
|
* Copyright Google LLC All Rights Reserved.
|
2016-06-23 12:47:54 -04:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2019-03-11 20:20:40 -04:00
|
|
|
import {DOCUMENT, ɵPLATFORM_WORKER_UI_ID as PLATFORM_WORKER_UI_ID} from '@angular/common';
|
2020-04-13 19:40:21 -04:00
|
|
|
import {createPlatformFactory, ErrorHandler, Injectable, InjectionToken, Injector, isDevMode, NgZone, PLATFORM_ID, PLATFORM_INITIALIZER, platformCore, RendererFactory2, StaticProvider, Testability, ɵAPP_ID_RANDOM_PROVIDER as APP_ID_RANDOM_PROVIDER, ɵsetDocument} from '@angular/core';
|
2019-03-11 20:20:40 -04:00
|
|
|
import {EVENT_MANAGER_PLUGINS, EventManager, HAMMER_GESTURE_CONFIG, HammerGestureConfig, ɵBROWSER_SANITIZATION_PROVIDERS as BROWSER_SANITIZATION_PROVIDERS, ɵBrowserDomAdapter as BrowserDomAdapter, ɵBrowserGetTestability as BrowserGetTestability, ɵDomEventsPlugin as DomEventsPlugin, ɵDomRendererFactory2 as DomRendererFactory2, ɵDomSharedStylesHost as DomSharedStylesHost, ɵHammerGesturesPlugin as HammerGesturesPlugin, ɵKeyEventsPlugin as KeyEventsPlugin, ɵSharedStylesHost as SharedStylesHost} from '@angular/platform-browser';
|
2017-02-19 00:28:27 -05:00
|
|
|
|
2016-06-08 19:38:52 -04:00
|
|
|
import {ON_WEB_WORKER} from './web_workers/shared/api';
|
2017-09-12 14:45:02 -04:00
|
|
|
import {ClientMessageBrokerFactory} from './web_workers/shared/client_message_broker';
|
2016-06-08 19:38:52 -04:00
|
|
|
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';
|
2017-09-12 14:45:02 -04:00
|
|
|
import {ServiceMessageBrokerFactory} from './web_workers/shared/service_message_broker';
|
2017-03-07 19:36:12 -05:00
|
|
|
import {MessageBasedRenderer2} from './web_workers/ui/renderer';
|
2016-05-20 19:11:49 -04:00
|
|
|
|
2017-02-19 00:28:27 -05:00
|
|
|
|
perf: switch angular to use StaticInjector instead of ReflectiveInjector
This change allows ReflectiveInjector to be tree shaken resulting
in not needed Reflect polyfil and smaller bundles.
Code savings for HelloWorld using Closure:
Reflective: bundle.js: 105,864(34,190 gzip)
Static: bundle.js: 154,889(33,555 gzip)
645( 2%)
BREAKING CHANGE:
`platformXXXX()` no longer accepts providers which depend on reflection.
Specifically the method signature when from `Provider[]` to
`StaticProvider[]`.
Example:
Before:
```
[
MyClass,
{provide: ClassA, useClass: SubClassA}
]
```
After:
```
[
{provide: MyClass, deps: [Dep1,...]},
{provide: ClassA, useClass: SubClassA, deps: [Dep1,...]}
]
```
NOTE: This only applies to platform creation and providers for the JIT
compiler. It does not apply to `@Compotent` or `@NgModule` provides
declarations.
Benchpress note: Previously Benchpress also supported reflective
provides, which now require static providers.
DEPRECATION:
- `ReflectiveInjector` is now deprecated as it will be remove. Use
`Injector.create` as a replacement.
closes #18496
2017-08-03 15:33:29 -04:00
|
|
|
|
2016-05-20 19:11:49 -04:00
|
|
|
/**
|
|
|
|
* Wrapper class that exposes the Worker
|
|
|
|
* and underlying {@link MessageBus} for lower level message passing.
|
2016-06-27 15:27:23 -04:00
|
|
|
*
|
2018-10-19 07:12:20 -04:00
|
|
|
* @publicApi
|
2020-05-11 17:41:13 -04:00
|
|
|
* @deprecated platform-webworker is deprecated in Angular and will be removed in a future version
|
|
|
|
* of Angular
|
2016-05-20 19:11:49 -04:00
|
|
|
*/
|
|
|
|
@Injectable()
|
|
|
|
export class WebWorkerInstance {
|
2018-06-18 19:38:33 -04:00
|
|
|
// TODO(issue/24571): remove '!'.
|
2020-04-13 19:40:21 -04:00
|
|
|
public worker!: Worker;
|
2018-06-18 19:38:33 -04:00
|
|
|
// TODO(issue/24571): remove '!'.
|
2020-04-13 19:40:21 -04:00
|
|
|
public bus!: MessageBus;
|
2016-05-20 19:11:49 -04:00
|
|
|
|
|
|
|
/** @internal */
|
|
|
|
public init(worker: Worker, bus: MessageBus) {
|
|
|
|
this.worker = worker;
|
|
|
|
this.bus = bus;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-15 11:41:41 -04:00
|
|
|
/**
|
2018-10-19 07:12:20 -04:00
|
|
|
* @publicApi
|
2020-05-11 17:41:13 -04:00
|
|
|
* @deprecated platform-webworker is deprecated in Angular and will be removed in a future version
|
|
|
|
* of Angular
|
2016-06-15 11:41:41 -04:00
|
|
|
*/
|
2017-01-03 19:54:46 -05:00
|
|
|
export const WORKER_SCRIPT = new InjectionToken<string>('WebWorkerScript');
|
2016-05-20 19:11:49 -04:00
|
|
|
|
|
|
|
/**
|
2016-08-30 14:15:25 -04:00
|
|
|
* A multi-provider used to automatically call the `start()` method after the service is
|
2016-05-20 19:11:49 -04:00
|
|
|
* created.
|
|
|
|
*
|
2018-10-19 07:12:20 -04:00
|
|
|
* @publicApi
|
2020-05-11 17:41:13 -04:00
|
|
|
* @deprecated platform-webworker is deprecated in Angular and will be removed in a future version
|
|
|
|
* of Angular
|
2016-05-20 19:11:49 -04:00
|
|
|
*/
|
2016-06-15 11:25:31 -04:00
|
|
|
export const WORKER_UI_STARTABLE_MESSAGING_SERVICE =
|
2017-02-20 11:00:31 -05:00
|
|
|
new InjectionToken<({start: () => void})[]>('WorkerRenderStartableMsgService');
|
2016-05-20 19:11:49 -04:00
|
|
|
|
perf: switch angular to use StaticInjector instead of ReflectiveInjector
This change allows ReflectiveInjector to be tree shaken resulting
in not needed Reflect polyfil and smaller bundles.
Code savings for HelloWorld using Closure:
Reflective: bundle.js: 105,864(34,190 gzip)
Static: bundle.js: 154,889(33,555 gzip)
645( 2%)
BREAKING CHANGE:
`platformXXXX()` no longer accepts providers which depend on reflection.
Specifically the method signature when from `Provider[]` to
`StaticProvider[]`.
Example:
Before:
```
[
MyClass,
{provide: ClassA, useClass: SubClassA}
]
```
After:
```
[
{provide: MyClass, deps: [Dep1,...]},
{provide: ClassA, useClass: SubClassA, deps: [Dep1,...]}
]
```
NOTE: This only applies to platform creation and providers for the JIT
compiler. It does not apply to `@Compotent` or `@NgModule` provides
declarations.
Benchpress note: Previously Benchpress also supported reflective
provides, which now require static providers.
DEPRECATION:
- `ReflectiveInjector` is now deprecated as it will be remove. Use
`Injector.create` as a replacement.
closes #18496
2017-08-03 15:33:29 -04:00
|
|
|
export const _WORKER_UI_PLATFORM_PROVIDERS: StaticProvider[] = [
|
2016-07-18 06:50:31 -04:00
|
|
|
{provide: NgZone, useFactory: createNgZone, deps: []},
|
perf: switch angular to use StaticInjector instead of ReflectiveInjector
This change allows ReflectiveInjector to be tree shaken resulting
in not needed Reflect polyfil and smaller bundles.
Code savings for HelloWorld using Closure:
Reflective: bundle.js: 105,864(34,190 gzip)
Static: bundle.js: 154,889(33,555 gzip)
645( 2%)
BREAKING CHANGE:
`platformXXXX()` no longer accepts providers which depend on reflection.
Specifically the method signature when from `Provider[]` to
`StaticProvider[]`.
Example:
Before:
```
[
MyClass,
{provide: ClassA, useClass: SubClassA}
]
```
After:
```
[
{provide: MyClass, deps: [Dep1,...]},
{provide: ClassA, useClass: SubClassA, deps: [Dep1,...]}
]
```
NOTE: This only applies to platform creation and providers for the JIT
compiler. It does not apply to `@Compotent` or `@NgModule` provides
declarations.
Benchpress note: Previously Benchpress also supported reflective
provides, which now require static providers.
DEPRECATION:
- `ReflectiveInjector` is now deprecated as it will be remove. Use
`Injector.create` as a replacement.
closes #18496
2017-08-03 15:33:29 -04:00
|
|
|
{
|
|
|
|
provide: MessageBasedRenderer2,
|
|
|
|
deps: [ServiceMessageBrokerFactory, MessageBus, Serializer, RenderStore, RendererFactory2]
|
|
|
|
},
|
2017-03-07 19:36:12 -05:00
|
|
|
{provide: WORKER_UI_STARTABLE_MESSAGING_SERVICE, useExisting: MessageBasedRenderer2, multi: true},
|
2016-06-08 19:38:52 -04:00
|
|
|
BROWSER_SANITIZATION_PROVIDERS,
|
2016-08-25 03:50:16 -04:00
|
|
|
{provide: ErrorHandler, useFactory: _exceptionHandler, deps: []},
|
2016-06-08 19:38:52 -04:00
|
|
|
{provide: DOCUMENT, useFactory: _document, deps: []},
|
|
|
|
// TODO(jteplitz602): Investigate if we definitely need EVENT_MANAGER on the render thread
|
|
|
|
// #5298
|
perf: switch angular to use StaticInjector instead of ReflectiveInjector
This change allows ReflectiveInjector to be tree shaken resulting
in not needed Reflect polyfil and smaller bundles.
Code savings for HelloWorld using Closure:
Reflective: bundle.js: 105,864(34,190 gzip)
Static: bundle.js: 154,889(33,555 gzip)
645( 2%)
BREAKING CHANGE:
`platformXXXX()` no longer accepts providers which depend on reflection.
Specifically the method signature when from `Provider[]` to
`StaticProvider[]`.
Example:
Before:
```
[
MyClass,
{provide: ClassA, useClass: SubClassA}
]
```
After:
```
[
{provide: MyClass, deps: [Dep1,...]},
{provide: ClassA, useClass: SubClassA, deps: [Dep1,...]}
]
```
NOTE: This only applies to platform creation and providers for the JIT
compiler. It does not apply to `@Compotent` or `@NgModule` provides
declarations.
Benchpress note: Previously Benchpress also supported reflective
provides, which now require static providers.
DEPRECATION:
- `ReflectiveInjector` is now deprecated as it will be remove. Use
`Injector.create` as a replacement.
closes #18496
2017-08-03 15:33:29 -04:00
|
|
|
{
|
|
|
|
provide: EVENT_MANAGER_PLUGINS,
|
|
|
|
useClass: DomEventsPlugin,
|
|
|
|
deps: [DOCUMENT, NgZone],
|
|
|
|
multi: true
|
|
|
|
},
|
|
|
|
{provide: EVENT_MANAGER_PLUGINS, useClass: KeyEventsPlugin, deps: [DOCUMENT], multi: true},
|
|
|
|
{
|
|
|
|
provide: EVENT_MANAGER_PLUGINS,
|
|
|
|
useClass: HammerGesturesPlugin,
|
|
|
|
deps: [DOCUMENT, HAMMER_GESTURE_CONFIG],
|
|
|
|
multi: true
|
|
|
|
},
|
|
|
|
{provide: HAMMER_GESTURE_CONFIG, useClass: HammerGestureConfig, deps: []},
|
2016-11-02 14:38:10 -04:00
|
|
|
APP_ID_RANDOM_PROVIDER,
|
perf: switch angular to use StaticInjector instead of ReflectiveInjector
This change allows ReflectiveInjector to be tree shaken resulting
in not needed Reflect polyfil and smaller bundles.
Code savings for HelloWorld using Closure:
Reflective: bundle.js: 105,864(34,190 gzip)
Static: bundle.js: 154,889(33,555 gzip)
645( 2%)
BREAKING CHANGE:
`platformXXXX()` no longer accepts providers which depend on reflection.
Specifically the method signature when from `Provider[]` to
`StaticProvider[]`.
Example:
Before:
```
[
MyClass,
{provide: ClassA, useClass: SubClassA}
]
```
After:
```
[
{provide: MyClass, deps: [Dep1,...]},
{provide: ClassA, useClass: SubClassA, deps: [Dep1,...]}
]
```
NOTE: This only applies to platform creation and providers for the JIT
compiler. It does not apply to `@Compotent` or `@NgModule` provides
declarations.
Benchpress note: Previously Benchpress also supported reflective
provides, which now require static providers.
DEPRECATION:
- `ReflectiveInjector` is now deprecated as it will be remove. Use
`Injector.create` as a replacement.
closes #18496
2017-08-03 15:33:29 -04:00
|
|
|
{provide: DomRendererFactory2, deps: [EventManager, DomSharedStylesHost]},
|
2017-03-07 19:36:12 -05:00
|
|
|
{provide: RendererFactory2, useExisting: DomRendererFactory2},
|
2016-06-08 19:38:52 -04:00
|
|
|
{provide: SharedStylesHost, useExisting: DomSharedStylesHost},
|
perf: switch angular to use StaticInjector instead of ReflectiveInjector
This change allows ReflectiveInjector to be tree shaken resulting
in not needed Reflect polyfil and smaller bundles.
Code savings for HelloWorld using Closure:
Reflective: bundle.js: 105,864(34,190 gzip)
Static: bundle.js: 154,889(33,555 gzip)
645( 2%)
BREAKING CHANGE:
`platformXXXX()` no longer accepts providers which depend on reflection.
Specifically the method signature when from `Provider[]` to
`StaticProvider[]`.
Example:
Before:
```
[
MyClass,
{provide: ClassA, useClass: SubClassA}
]
```
After:
```
[
{provide: MyClass, deps: [Dep1,...]},
{provide: ClassA, useClass: SubClassA, deps: [Dep1,...]}
]
```
NOTE: This only applies to platform creation and providers for the JIT
compiler. It does not apply to `@Compotent` or `@NgModule` provides
declarations.
Benchpress note: Previously Benchpress also supported reflective
provides, which now require static providers.
DEPRECATION:
- `ReflectiveInjector` is now deprecated as it will be remove. Use
`Injector.create` as a replacement.
closes #18496
2017-08-03 15:33:29 -04:00
|
|
|
{
|
|
|
|
provide: ServiceMessageBrokerFactory,
|
2017-09-12 14:45:02 -04:00
|
|
|
useClass: ServiceMessageBrokerFactory,
|
perf: switch angular to use StaticInjector instead of ReflectiveInjector
This change allows ReflectiveInjector to be tree shaken resulting
in not needed Reflect polyfil and smaller bundles.
Code savings for HelloWorld using Closure:
Reflective: bundle.js: 105,864(34,190 gzip)
Static: bundle.js: 154,889(33,555 gzip)
645( 2%)
BREAKING CHANGE:
`platformXXXX()` no longer accepts providers which depend on reflection.
Specifically the method signature when from `Provider[]` to
`StaticProvider[]`.
Example:
Before:
```
[
MyClass,
{provide: ClassA, useClass: SubClassA}
]
```
After:
```
[
{provide: MyClass, deps: [Dep1,...]},
{provide: ClassA, useClass: SubClassA, deps: [Dep1,...]}
]
```
NOTE: This only applies to platform creation and providers for the JIT
compiler. It does not apply to `@Compotent` or `@NgModule` provides
declarations.
Benchpress note: Previously Benchpress also supported reflective
provides, which now require static providers.
DEPRECATION:
- `ReflectiveInjector` is now deprecated as it will be remove. Use
`Injector.create` as a replacement.
closes #18496
2017-08-03 15:33:29 -04:00
|
|
|
deps: [MessageBus, Serializer]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
provide: ClientMessageBrokerFactory,
|
2017-09-12 14:45:02 -04:00
|
|
|
useClass: ClientMessageBrokerFactory,
|
perf: switch angular to use StaticInjector instead of ReflectiveInjector
This change allows ReflectiveInjector to be tree shaken resulting
in not needed Reflect polyfil and smaller bundles.
Code savings for HelloWorld using Closure:
Reflective: bundle.js: 105,864(34,190 gzip)
Static: bundle.js: 154,889(33,555 gzip)
645( 2%)
BREAKING CHANGE:
`platformXXXX()` no longer accepts providers which depend on reflection.
Specifically the method signature when from `Provider[]` to
`StaticProvider[]`.
Example:
Before:
```
[
MyClass,
{provide: ClassA, useClass: SubClassA}
]
```
After:
```
[
{provide: MyClass, deps: [Dep1,...]},
{provide: ClassA, useClass: SubClassA, deps: [Dep1,...]}
]
```
NOTE: This only applies to platform creation and providers for the JIT
compiler. It does not apply to `@Compotent` or `@NgModule` provides
declarations.
Benchpress note: Previously Benchpress also supported reflective
provides, which now require static providers.
DEPRECATION:
- `ReflectiveInjector` is now deprecated as it will be remove. Use
`Injector.create` as a replacement.
closes #18496
2017-08-03 15:33:29 -04:00
|
|
|
deps: [MessageBus, Serializer]
|
|
|
|
},
|
|
|
|
{provide: Serializer, deps: [RenderStore]},
|
2016-06-08 19:38:52 -04:00
|
|
|
{provide: ON_WEB_WORKER, useValue: false},
|
perf: switch angular to use StaticInjector instead of ReflectiveInjector
This change allows ReflectiveInjector to be tree shaken resulting
in not needed Reflect polyfil and smaller bundles.
Code savings for HelloWorld using Closure:
Reflective: bundle.js: 105,864(34,190 gzip)
Static: bundle.js: 154,889(33,555 gzip)
645( 2%)
BREAKING CHANGE:
`platformXXXX()` no longer accepts providers which depend on reflection.
Specifically the method signature when from `Provider[]` to
`StaticProvider[]`.
Example:
Before:
```
[
MyClass,
{provide: ClassA, useClass: SubClassA}
]
```
After:
```
[
{provide: MyClass, deps: [Dep1,...]},
{provide: ClassA, useClass: SubClassA, deps: [Dep1,...]}
]
```
NOTE: This only applies to platform creation and providers for the JIT
compiler. It does not apply to `@Compotent` or `@NgModule` provides
declarations.
Benchpress note: Previously Benchpress also supported reflective
provides, which now require static providers.
DEPRECATION:
- `ReflectiveInjector` is now deprecated as it will be remove. Use
`Injector.create` as a replacement.
closes #18496
2017-08-03 15:33:29 -04:00
|
|
|
{provide: RenderStore, deps: []},
|
|
|
|
{provide: DomSharedStylesHost, deps: [DOCUMENT]},
|
|
|
|
{provide: Testability, deps: [NgZone]},
|
|
|
|
{provide: EventManager, deps: [EVENT_MANAGER_PLUGINS, NgZone]},
|
|
|
|
{provide: WebWorkerInstance, deps: []},
|
2016-07-18 06:50:31 -04:00
|
|
|
{
|
|
|
|
provide: PLATFORM_INITIALIZER,
|
|
|
|
useFactory: initWebWorkerRenderPlatform,
|
|
|
|
multi: true,
|
|
|
|
deps: [Injector]
|
|
|
|
},
|
2017-02-22 19:49:46 -05:00
|
|
|
{provide: PLATFORM_ID, useValue: PLATFORM_WORKER_UI_ID},
|
2017-02-16 17:09:06 -05:00
|
|
|
{provide: MessageBus, useFactory: messageBusFactory, deps: [WebWorkerInstance]},
|
2016-06-08 19:38:52 -04:00
|
|
|
];
|
2016-05-20 19:11:49 -04:00
|
|
|
|
2016-06-15 11:25:31 -04:00
|
|
|
function initializeGenericWorkerRenderer(injector: Injector) {
|
2016-11-12 08:08:58 -05:00
|
|
|
const bus = injector.get(MessageBus);
|
2017-11-15 11:43:35 -05:00
|
|
|
const zone = injector.get<NgZone>(NgZone);
|
2016-05-20 19:11:49 -04:00
|
|
|
bus.attachToZone(zone);
|
|
|
|
|
|
|
|
// initialize message services after the bus has been created
|
2016-11-12 08:08:58 -05:00
|
|
|
const services = injector.get(WORKER_UI_STARTABLE_MESSAGING_SERVICE);
|
2020-04-13 19:40:21 -04:00
|
|
|
zone.runGuarded(() => {
|
|
|
|
services.forEach((svc: any) => {
|
|
|
|
svc.start();
|
|
|
|
});
|
|
|
|
});
|
2016-05-20 19:11:49 -04:00
|
|
|
}
|
|
|
|
|
2016-06-02 20:30:40 -04:00
|
|
|
function messageBusFactory(instance: WebWorkerInstance): MessageBus {
|
|
|
|
return instance.bus;
|
|
|
|
}
|
|
|
|
|
2016-07-18 06:50:31 -04:00
|
|
|
function initWebWorkerRenderPlatform(injector: Injector): () => void {
|
2016-06-02 20:30:40 -04:00
|
|
|
return () => {
|
2016-07-18 06:50:31 -04:00
|
|
|
BrowserDomAdapter.makeCurrent();
|
|
|
|
BrowserGetTestability.init();
|
2016-11-12 08:08:58 -05:00
|
|
|
let scriptUri: string;
|
2016-06-02 20:30:40 -04:00
|
|
|
try {
|
|
|
|
scriptUri = injector.get(WORKER_SCRIPT);
|
2018-08-14 09:34:51 -04:00
|
|
|
} catch {
|
2016-08-25 03:50:16 -04:00
|
|
|
throw new Error(
|
2016-06-08 19:38:52 -04:00
|
|
|
'You must provide your WebWorker\'s initialization script with the WORKER_SCRIPT token');
|
2016-06-02 20:30:40 -04:00
|
|
|
}
|
|
|
|
|
2016-11-12 08:08:58 -05:00
|
|
|
const instance = injector.get(WebWorkerInstance);
|
2016-06-02 20:30:40 -04:00
|
|
|
spawnWebWorker(scriptUri, instance);
|
|
|
|
|
|
|
|
initializeGenericWorkerRenderer(injector);
|
|
|
|
};
|
2016-05-20 19:11:49 -04:00
|
|
|
}
|
|
|
|
|
2016-07-18 06:50:31 -04:00
|
|
|
/**
|
2018-10-19 07:12:20 -04:00
|
|
|
* @publicApi
|
2020-05-11 17:41:13 -04:00
|
|
|
* @deprecated platform-webworker is deprecated in Angular and will be removed in a future version
|
|
|
|
* of Angular
|
2016-07-18 06:50:31 -04:00
|
|
|
*/
|
2016-07-26 08:21:19 -04:00
|
|
|
export const platformWorkerUi =
|
|
|
|
createPlatformFactory(platformCore, 'workerUi', _WORKER_UI_PLATFORM_PROVIDERS);
|
|
|
|
|
2016-08-25 03:50:16 -04:00
|
|
|
function _exceptionHandler(): ErrorHandler {
|
|
|
|
return new ErrorHandler();
|
2016-07-18 06:50:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function _document(): any {
|
2019-11-09 14:00:53 -05:00
|
|
|
// Tell ivy about the global document
|
|
|
|
ɵsetDocument(document);
|
2017-02-14 19:14:40 -05:00
|
|
|
return document;
|
2016-07-18 06:50:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function createNgZone(): NgZone {
|
|
|
|
return new NgZone({enableLongStackTrace: isDevMode()});
|
|
|
|
}
|
|
|
|
|
2016-05-20 19:11:49 -04:00
|
|
|
/**
|
|
|
|
* Spawns a new class and initializes the WebWorkerInstance
|
|
|
|
*/
|
|
|
|
function spawnWebWorker(uri: string, instance: WebWorkerInstance): void {
|
2016-11-12 08:08:58 -05:00
|
|
|
const webWorker: Worker = new Worker(uri);
|
2019-07-17 20:49:16 -04:00
|
|
|
// webWorker is casted to any because the lib.d.ts signature changed in TS3.5 to require the
|
|
|
|
// transfer argument in postMessage method.
|
|
|
|
// this seems wrong but since all of this code is deprecated it shouldn't matter that much.
|
|
|
|
const sink = new PostMessageBusSink(webWorker as any);
|
2016-11-12 08:08:58 -05:00
|
|
|
const source = new PostMessageBusSource(webWorker);
|
|
|
|
const bus = new PostMessageBus(sink, source);
|
2016-05-20 19:11:49 -04:00
|
|
|
|
|
|
|
instance.init(webWorker, bus);
|
|
|
|
}
|