refactor(WebWorker): Use the new generic bootstrap.
BREAKING CHANGE:
You can no longer bootstrap a WebWorker or Isolate using `bootstrap` or `bootstrapWebWorker`. Instead you have to do the following:
In TypeScript:
```TypeScript
// index.js
import {WORKER_RENDER_PLATFORM, WORKER_RENDER_APPLICATION, WORKER_SCRIPT} from "angular2/platforms/worker_render";
import {platform} from "angular2/platform";
platform([WORKER_RENDER_PLATFORM])
.application([WORKER_RENDER_APPLICATION, new Provider(WORKER_SCRIPT, {useValue: "loader.js"});
```
```JavaScript
// loader.js
importScripts("https://cdnjs.cloudflare.com/ajax/libs/es6-shim/0.33.3/es6-shim.js", "https://jspm.io/system@0.16.js", "angular2/web_worker/worker.js");
System.import("app");
```
```TypeScript
// app.ts
import {Component, View} from "angular2/core";
import {WORKER_APP_PLATFORM, setupWebWorker} from "angular2/platforms/worker_app";
import {platform} from "angular2/platform";
@Component({
selector: "hello-world"
})
@View({
template: "<h1>Hello {{name}}</h1>
})
export class HelloWorld {
name: string = "Jane";
}
platform([WORKER_APP_PLATFORM])
.asyncApplication(setupWebWorker, optionalProviders?)
.then((ref) => ref.bootstrap(RootComponent));
```
In Dart:
```Dart
// index.dart
import "angular2/platform.dart";
import "angular2/platforms/worker_render.dart";
main() {
platform([WORKER_RENDER_PLATFORM])
.asyncApplication(initIsolate("my_worker.dart"));
}
```
```Dart
// background_index.dart
import "angular2/platform.dart";
import "angular2/platforms/worker_app.dart";
import "package:angular2/src/core/reflection/reflection.dart";
import "package:angular2/src/core/reflection/reflection_capabilities.dart";
@Component(
selector: "hello-world"
)
@View(
template: "<h1>Hello {{name}}</h1>"
)
class HelloWorld {
String name = "Jane";
}
main(List<String> args, SendPort replyTo) {
reflector.reflectionCapabilities = new ReflectionCapabilities();
platform([WORKER_APP_PLATFORM])
.asyncApplication(setupIsolate(replyTo))
.then((ref) => ref.bootstrap(RootComponent));
}
```
You should no longer import from the `angular2/web_worker/worker` and `angular2/web_worker/ui` paths. Instead you can now import directly from core, directives, etc..
The WebWorkerApplication class has been removed. If you want to use ServiceMessageBroker or ClientMessageBroker on the render thread, you must inject their factories via DI.
If you need to use the MessageBus on the render thread you must also obtain it through DI.
closes #3277
closes #5473
Closes #5519
2015-12-02 20:25:24 -08:00
|
|
|
import {XHR} from 'angular2/src/compiler/xhr';
|
|
|
|
import {WebWorkerXHRImpl} from 'angular2/src/web_workers/worker/xhr_impl';
|
|
|
|
import {ListWrapper} from 'angular2/src/facade/collection';
|
|
|
|
import {WebWorkerRenderer} from 'angular2/src/web_workers/worker/renderer';
|
|
|
|
import {print, Type, CONST_EXPR, isPresent} from 'angular2/src/facade/lang';
|
|
|
|
import {MessageBus} from 'angular2/src/web_workers/shared/message_bus';
|
|
|
|
import {Renderer} from 'angular2/src/core/render/api';
|
|
|
|
import {
|
|
|
|
PLATFORM_DIRECTIVES,
|
|
|
|
PLATFORM_PIPES,
|
|
|
|
ExceptionHandler,
|
|
|
|
APPLICATION_COMMON_PROVIDERS,
|
|
|
|
PLATFORM_COMMON_PROVIDERS,
|
|
|
|
} from 'angular2/core';
|
|
|
|
import {COMMON_DIRECTIVES, COMMON_PIPES, FORM_PROVIDERS} from "angular2/common";
|
|
|
|
import {
|
|
|
|
ClientMessageBrokerFactory,
|
|
|
|
ClientMessageBrokerFactory_
|
|
|
|
} from 'angular2/src/web_workers/shared/client_message_broker';
|
|
|
|
import {
|
|
|
|
ServiceMessageBrokerFactory,
|
|
|
|
ServiceMessageBrokerFactory_
|
|
|
|
} from 'angular2/src/web_workers/shared/service_message_broker';
|
|
|
|
import {COMPILER_PROVIDERS} from 'angular2/src/compiler/compiler';
|
|
|
|
import {Serializer} from "angular2/src/web_workers/shared/serializer";
|
|
|
|
import {ON_WEB_WORKER} from "angular2/src/web_workers/shared/api";
|
|
|
|
import {Provider} from 'angular2/src/core/di';
|
|
|
|
import {RenderProtoViewRefStore} from 'angular2/src/web_workers/shared/render_proto_view_ref_store';
|
|
|
|
import {
|
|
|
|
RenderViewWithFragmentsStore
|
|
|
|
} from 'angular2/src/web_workers/shared/render_view_with_fragments_store';
|
|
|
|
import {WebWorkerEventDispatcher} from 'angular2/src/web_workers/worker/event_dispatcher';
|
|
|
|
import {NgZone} from 'angular2/src/core/zone/ng_zone';
|
2015-12-10 16:24:46 -08:00
|
|
|
import {Promise, PromiseWrapper} from 'angular2/src/facade/async';
|
refactor(WebWorker): Use the new generic bootstrap.
BREAKING CHANGE:
You can no longer bootstrap a WebWorker or Isolate using `bootstrap` or `bootstrapWebWorker`. Instead you have to do the following:
In TypeScript:
```TypeScript
// index.js
import {WORKER_RENDER_PLATFORM, WORKER_RENDER_APPLICATION, WORKER_SCRIPT} from "angular2/platforms/worker_render";
import {platform} from "angular2/platform";
platform([WORKER_RENDER_PLATFORM])
.application([WORKER_RENDER_APPLICATION, new Provider(WORKER_SCRIPT, {useValue: "loader.js"});
```
```JavaScript
// loader.js
importScripts("https://cdnjs.cloudflare.com/ajax/libs/es6-shim/0.33.3/es6-shim.js", "https://jspm.io/system@0.16.js", "angular2/web_worker/worker.js");
System.import("app");
```
```TypeScript
// app.ts
import {Component, View} from "angular2/core";
import {WORKER_APP_PLATFORM, setupWebWorker} from "angular2/platforms/worker_app";
import {platform} from "angular2/platform";
@Component({
selector: "hello-world"
})
@View({
template: "<h1>Hello {{name}}</h1>
})
export class HelloWorld {
name: string = "Jane";
}
platform([WORKER_APP_PLATFORM])
.asyncApplication(setupWebWorker, optionalProviders?)
.then((ref) => ref.bootstrap(RootComponent));
```
In Dart:
```Dart
// index.dart
import "angular2/platform.dart";
import "angular2/platforms/worker_render.dart";
main() {
platform([WORKER_RENDER_PLATFORM])
.asyncApplication(initIsolate("my_worker.dart"));
}
```
```Dart
// background_index.dart
import "angular2/platform.dart";
import "angular2/platforms/worker_app.dart";
import "package:angular2/src/core/reflection/reflection.dart";
import "package:angular2/src/core/reflection/reflection_capabilities.dart";
@Component(
selector: "hello-world"
)
@View(
template: "<h1>Hello {{name}}</h1>"
)
class HelloWorld {
String name = "Jane";
}
main(List<String> args, SendPort replyTo) {
reflector.reflectionCapabilities = new ReflectionCapabilities();
platform([WORKER_APP_PLATFORM])
.asyncApplication(setupIsolate(replyTo))
.then((ref) => ref.bootstrap(RootComponent));
}
```
You should no longer import from the `angular2/web_worker/worker` and `angular2/web_worker/ui` paths. Instead you can now import directly from core, directives, etc..
The WebWorkerApplication class has been removed. If you want to use ServiceMessageBroker or ClientMessageBroker on the render thread, you must inject their factories via DI.
If you need to use the MessageBus on the render thread you must also obtain it through DI.
closes #3277
closes #5473
Closes #5519
2015-12-02 20:25:24 -08:00
|
|
|
|
|
|
|
class PrintLogger {
|
|
|
|
log = print;
|
|
|
|
logError = print;
|
|
|
|
logGroup = print;
|
|
|
|
logGroupEnd() {}
|
|
|
|
}
|
|
|
|
|
|
|
|
export const WORKER_APP_PLATFORM: Array<any /*Type | Provider | any[]*/> =
|
|
|
|
CONST_EXPR([PLATFORM_COMMON_PROVIDERS]);
|
|
|
|
|
|
|
|
export const WORKER_APP_COMMON_PROVIDERS: Array<any /*Type | Provider | any[]*/> = CONST_EXPR([
|
|
|
|
APPLICATION_COMMON_PROVIDERS,
|
|
|
|
COMPILER_PROVIDERS,
|
|
|
|
FORM_PROVIDERS,
|
|
|
|
Serializer,
|
|
|
|
new Provider(PLATFORM_PIPES, {useValue: COMMON_PIPES, multi: true}),
|
|
|
|
new Provider(PLATFORM_DIRECTIVES, {useValue: COMMON_DIRECTIVES, multi: true}),
|
|
|
|
new Provider(ClientMessageBrokerFactory, {useClass: ClientMessageBrokerFactory_}),
|
|
|
|
new Provider(ServiceMessageBrokerFactory, {useClass: ServiceMessageBrokerFactory_}),
|
|
|
|
WebWorkerRenderer,
|
|
|
|
new Provider(Renderer, {useExisting: WebWorkerRenderer}),
|
|
|
|
new Provider(ON_WEB_WORKER, {useValue: true}),
|
|
|
|
RenderViewWithFragmentsStore,
|
|
|
|
RenderProtoViewRefStore,
|
|
|
|
new Provider(ExceptionHandler, {useFactory: _exceptionHandler, deps: []}),
|
|
|
|
WebWorkerXHRImpl,
|
|
|
|
new Provider(XHR, {useExisting: WebWorkerXHRImpl}),
|
|
|
|
WebWorkerEventDispatcher
|
|
|
|
]);
|
|
|
|
|
|
|
|
function _exceptionHandler(): ExceptionHandler {
|
|
|
|
return new ExceptionHandler(new PrintLogger());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Asynchronously returns a list of providers that can be used to initialize the
|
|
|
|
* Application injector.
|
|
|
|
* Also takes care of attaching the {@link MessageBus} to the given {@link NgZone}.
|
|
|
|
*/
|
|
|
|
export function genericWorkerAppProviders(bus: MessageBus,
|
|
|
|
zone: NgZone): Promise<Array<Type | Provider | any[]>> {
|
|
|
|
bus.attachToZone(zone);
|
2015-12-10 16:24:46 -08:00
|
|
|
var bindings = ListWrapper.concat(WORKER_APP_COMMON_PROVIDERS, [
|
|
|
|
new Provider(MessageBus, {useValue: bus}),
|
|
|
|
]);
|
|
|
|
return PromiseWrapper.resolve(bindings);
|
refactor(WebWorker): Use the new generic bootstrap.
BREAKING CHANGE:
You can no longer bootstrap a WebWorker or Isolate using `bootstrap` or `bootstrapWebWorker`. Instead you have to do the following:
In TypeScript:
```TypeScript
// index.js
import {WORKER_RENDER_PLATFORM, WORKER_RENDER_APPLICATION, WORKER_SCRIPT} from "angular2/platforms/worker_render";
import {platform} from "angular2/platform";
platform([WORKER_RENDER_PLATFORM])
.application([WORKER_RENDER_APPLICATION, new Provider(WORKER_SCRIPT, {useValue: "loader.js"});
```
```JavaScript
// loader.js
importScripts("https://cdnjs.cloudflare.com/ajax/libs/es6-shim/0.33.3/es6-shim.js", "https://jspm.io/system@0.16.js", "angular2/web_worker/worker.js");
System.import("app");
```
```TypeScript
// app.ts
import {Component, View} from "angular2/core";
import {WORKER_APP_PLATFORM, setupWebWorker} from "angular2/platforms/worker_app";
import {platform} from "angular2/platform";
@Component({
selector: "hello-world"
})
@View({
template: "<h1>Hello {{name}}</h1>
})
export class HelloWorld {
name: string = "Jane";
}
platform([WORKER_APP_PLATFORM])
.asyncApplication(setupWebWorker, optionalProviders?)
.then((ref) => ref.bootstrap(RootComponent));
```
In Dart:
```Dart
// index.dart
import "angular2/platform.dart";
import "angular2/platforms/worker_render.dart";
main() {
platform([WORKER_RENDER_PLATFORM])
.asyncApplication(initIsolate("my_worker.dart"));
}
```
```Dart
// background_index.dart
import "angular2/platform.dart";
import "angular2/platforms/worker_app.dart";
import "package:angular2/src/core/reflection/reflection.dart";
import "package:angular2/src/core/reflection/reflection_capabilities.dart";
@Component(
selector: "hello-world"
)
@View(
template: "<h1>Hello {{name}}</h1>"
)
class HelloWorld {
String name = "Jane";
}
main(List<String> args, SendPort replyTo) {
reflector.reflectionCapabilities = new ReflectionCapabilities();
platform([WORKER_APP_PLATFORM])
.asyncApplication(setupIsolate(replyTo))
.then((ref) => ref.bootstrap(RootComponent));
}
```
You should no longer import from the `angular2/web_worker/worker` and `angular2/web_worker/ui` paths. Instead you can now import directly from core, directives, etc..
The WebWorkerApplication class has been removed. If you want to use ServiceMessageBroker or ClientMessageBroker on the render thread, you must inject their factories via DI.
If you need to use the MessageBus on the render thread you must also obtain it through DI.
closes #3277
closes #5473
Closes #5519
2015-12-02 20:25:24 -08:00
|
|
|
}
|