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
This commit is contained in:
@ -2,12 +2,14 @@ library playground.src.web_workers.images.background_index;
|
||||
|
||||
import "index_common.dart" show ImageDemo;
|
||||
import "dart:isolate";
|
||||
import "package:angular2/src/web_workers/worker/application.dart"
|
||||
show bootstrapWebWorker;
|
||||
import "package:angular2/platform/worker_app.dart";
|
||||
import "package:angular2/core.dart";
|
||||
import "package:angular2/src/core/reflection/reflection_capabilities.dart";
|
||||
import "package:angular2/src/core/reflection/reflection.dart";
|
||||
|
||||
main(List<String> args, SendPort replyTo) {
|
||||
reflector.reflectionCapabilities = new ReflectionCapabilities();
|
||||
bootstrapWebWorker(replyTo, ImageDemo).catchError((error) => throw error);
|
||||
}
|
||||
platform([WORKER_APP_PLATFORM])
|
||||
.asyncApplication(setupIsolate(replyTo))
|
||||
.then((ref) => ref.bootstrap(ImageDemo));
|
||||
}
|
@ -1,6 +1,9 @@
|
||||
import {bootstrapWebWorker} from "angular2/src/web_workers/worker/application";
|
||||
import {ImageDemo} from "./index_common";
|
||||
import {platform} from "angular2/core";
|
||||
import {WORKER_APP_PLATFORM, setupWebWorker} from "angular2/platform/worker_app";
|
||||
|
||||
export function main() {
|
||||
bootstrapWebWorker(ImageDemo);
|
||||
}
|
||||
platform([WORKER_APP_PLATFORM])
|
||||
.asyncApplication(setupWebWorker)
|
||||
.then((ref) => ref.bootstrap(ImageDemo));
|
||||
}
|
@ -1,10 +1,12 @@
|
||||
library angular2.examples.web_workers.images.index;
|
||||
|
||||
import "package:angular2/src/web_workers/ui/application.dart" show bootstrap;
|
||||
import "package:angular2/platform/worker_render.dart";
|
||||
import "package:angular2/core.dart";
|
||||
import "package:angular2/src/core/reflection/reflection_capabilities.dart";
|
||||
import "package:angular2/src/core/reflection/reflection.dart";
|
||||
|
||||
main() {
|
||||
reflector.reflectionCapabilities = new ReflectionCapabilities();
|
||||
bootstrap("background_index.dart");
|
||||
platform([WORKER_RENDER_PLATFORM])
|
||||
.asyncApplication(initIsolate("background_index.dart"));
|
||||
}
|
||||
|
@ -1,2 +1,9 @@
|
||||
import {bootstrap} from "angular2/src/web_workers/ui/application";
|
||||
bootstrap("loader.js");
|
||||
import {platform, Provider} from 'angular2/core';
|
||||
import {
|
||||
WORKER_RENDER_APP,
|
||||
WORKER_RENDER_PLATFORM,
|
||||
WORKER_SCRIPT
|
||||
} from 'angular2/platform/worker_render';
|
||||
|
||||
platform([WORKER_RENDER_PLATFORM])
|
||||
.application([WORKER_RENDER_APP, new Provider(WORKER_SCRIPT, {useValue: "loader.js"})]);
|
||||
|
@ -2,12 +2,14 @@ library playground.src.web_workers.kitchen_sink.background_index;
|
||||
|
||||
import "index_common.dart" show HelloCmp;
|
||||
import "dart:isolate";
|
||||
import "package:angular2/src/web_workers/worker/application.dart"
|
||||
show bootstrapWebWorker;
|
||||
import "package:angular2/platform/worker_app.dart";
|
||||
import "package:angular2/core.dart";
|
||||
import "package:angular2/src/core/reflection/reflection_capabilities.dart";
|
||||
import "package:angular2/src/core/reflection/reflection.dart";
|
||||
|
||||
main(List<String> args, SendPort replyTo) {
|
||||
reflector.reflectionCapabilities = new ReflectionCapabilities();
|
||||
bootstrapWebWorker(replyTo, HelloCmp).catchError((error) => throw error);
|
||||
platform([WORKER_APP_PLATFORM])
|
||||
.asyncApplication(setupIsolate(replyTo))
|
||||
.then((ref) => ref.bootstrap(HelloCmp));
|
||||
}
|
||||
|
@ -1,6 +1,9 @@
|
||||
import {HelloCmp} from "./index_common";
|
||||
import {bootstrapWebWorker} from "angular2/src/web_workers/worker/application";
|
||||
import {platform} from "angular2/core";
|
||||
import {WORKER_APP_PLATFORM, setupWebWorker} from "angular2/platform/worker_app";
|
||||
|
||||
export function main() {
|
||||
bootstrapWebWorker(HelloCmp);
|
||||
}
|
||||
platform([WORKER_APP_PLATFORM])
|
||||
.asyncApplication(setupWebWorker)
|
||||
.then((ref) => ref.bootstrap(HelloCmp));
|
||||
}
|
@ -1,10 +1,12 @@
|
||||
library angular2.examples.web_workers.kitchen_sink.index;
|
||||
|
||||
import "package:angular2/src/web_workers/ui/application.dart" show bootstrap;
|
||||
import "package:angular2/platform/worker_render.dart";
|
||||
import "package:angular2/core.dart";
|
||||
import "package:angular2/src/core/reflection/reflection_capabilities.dart";
|
||||
import "package:angular2/src/core/reflection/reflection.dart";
|
||||
|
||||
main() {
|
||||
reflector.reflectionCapabilities = new ReflectionCapabilities();
|
||||
bootstrap("background_index.dart");
|
||||
platform([WORKER_RENDER_PLATFORM])
|
||||
.asyncApplication(initIsolate("background_index.dart"));
|
||||
}
|
||||
|
@ -1,2 +1,9 @@
|
||||
import {bootstrap} from "angular2/src/web_workers/ui/application";
|
||||
bootstrap("loader.js");
|
||||
import {platform, Provider} from 'angular2/core';
|
||||
import {
|
||||
WORKER_RENDER_APP,
|
||||
WORKER_RENDER_PLATFORM,
|
||||
WORKER_SCRIPT
|
||||
} from 'angular2/platform/worker_render';
|
||||
|
||||
platform([WORKER_RENDER_PLATFORM])
|
||||
.application([WORKER_RENDER_APP, new Provider(WORKER_SCRIPT, {useValue: "loader.js"})]);
|
||||
|
@ -1,6 +1,7 @@
|
||||
library angular2.examples.message_broker.background_index;
|
||||
|
||||
import "package:angular2/web_worker/worker.dart";
|
||||
import "package:angular2/platform/worker_app.dart";
|
||||
import "package:angular2/core.dart";
|
||||
import "package:angular2/src/core/reflection/reflection_capabilities.dart";
|
||||
import "package:angular2/src/core/reflection/reflection.dart";
|
||||
import "index_common.dart" show App;
|
||||
@ -8,5 +9,7 @@ import "dart:isolate";
|
||||
|
||||
main(List<String> args, SendPort replyTo) {
|
||||
reflector.reflectionCapabilities = new ReflectionCapabilities();
|
||||
bootstrapWebWorker(replyTo, App).catchError((error) => throw error);
|
||||
platform([WORKER_APP_PLATFORM])
|
||||
.asyncApplication(setupIsolate(replyTo))
|
||||
.then((ref) => ref.bootstrap(App));
|
||||
}
|
||||
|
@ -1,6 +1,9 @@
|
||||
import {bootstrapWebWorker} from "angular2/web_worker/worker";
|
||||
import {platform} from "angular2/core";
|
||||
import {WORKER_APP_PLATFORM, setupWebWorker} from "angular2/platform/worker_app";
|
||||
import {App} from "./index_common";
|
||||
|
||||
export function main() {
|
||||
bootstrapWebWorker(App);
|
||||
platform([WORKER_APP_PLATFORM])
|
||||
.asyncApplication(setupWebWorker)
|
||||
.then((ref) => ref.bootstrap(App));
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
library angular2.examples.message_broker.index;
|
||||
|
||||
import "package:angular2/web_worker/ui.dart";
|
||||
import "package:angular2/platform/worker_render.dart";
|
||||
import "package:angular2/core.dart";
|
||||
import "package:angular2/src/core/reflection/reflection_capabilities.dart";
|
||||
import "package:angular2/src/core/reflection/reflection.dart";
|
||||
import "dart:html";
|
||||
@ -8,8 +9,11 @@ import "dart:html";
|
||||
main() {
|
||||
reflector.reflectionCapabilities = new ReflectionCapabilities();
|
||||
const ECHO_CHANNEL = "ECHO";
|
||||
bootstrap("background_index.dart").then((instance) {
|
||||
var broker = instance.app.createClientMessageBroker(ECHO_CHANNEL, false);
|
||||
platform([WORKER_RENDER_PLATFORM])
|
||||
.asyncApplication(initIsolate("background_index.dart"))
|
||||
.then((ref) {
|
||||
var brokerFactory = ref.injector.get(ClientMessageBrokerFactory);
|
||||
var broker = brokerFactory.createMessageBroker(ECHO_CHANNEL, false);
|
||||
querySelector("#send_echo").addEventListener("click", (e) {
|
||||
var val = (querySelector("#echo_input") as InputElement).value;
|
||||
var args = new UiArguments("echo", [new FnArg(val, PRIMITIVE)]);
|
||||
|
@ -1,9 +1,21 @@
|
||||
import {bootstrap, UiArguments, FnArg, PRIMITIVE} from "angular2/web_worker/ui";
|
||||
import {platform, Provider} from 'angular2/core';
|
||||
import {
|
||||
WORKER_RENDER_APP,
|
||||
WORKER_RENDER_PLATFORM,
|
||||
WORKER_SCRIPT,
|
||||
UiArguments,
|
||||
FnArg,
|
||||
PRIMITIVE,
|
||||
ClientMessageBrokerFactory
|
||||
} from 'angular2/platform/worker_render';
|
||||
|
||||
const ECHO_CHANNEL = "ECHO";
|
||||
|
||||
var instance = bootstrap("loader.js");
|
||||
var broker = instance.app.createClientMessageBroker(ECHO_CHANNEL, false);
|
||||
let ref =
|
||||
platform([WORKER_RENDER_PLATFORM])
|
||||
.application([WORKER_RENDER_APP, new Provider(WORKER_SCRIPT, {useValue: "loader.js"})]);
|
||||
let brokerFactory: ClientMessageBrokerFactory = ref.injector.get(ClientMessageBrokerFactory);
|
||||
var broker = brokerFactory.createMessageBroker(ECHO_CHANNEL, false);
|
||||
|
||||
document.getElementById("send_echo")
|
||||
.addEventListener("click", (e) => {
|
||||
|
@ -1,5 +1,6 @@
|
||||
import {PromiseWrapper} from "angular2/src/facade/async";
|
||||
import {Component, View, ServiceMessageBrokerFactory, PRIMITIVE} from "angular2/web_worker/worker";
|
||||
import {Component, View} from "angular2/core";
|
||||
import {ServiceMessageBrokerFactory, PRIMITIVE} from "angular2/platform/worker_app";
|
||||
|
||||
const ECHO_CHANNEL = "ECHO";
|
||||
|
||||
|
@ -8,7 +8,6 @@ System.config({
|
||||
System.import("playground/src/web_workers/message_broker/background_index")
|
||||
.then(
|
||||
function(m) {
|
||||
console.log("running main");
|
||||
try {
|
||||
m.main();
|
||||
} catch (e) {
|
||||
|
@ -2,12 +2,14 @@ library playground.src.web_workers.todo.background_index;
|
||||
|
||||
import "index_common.dart" show TodoApp;
|
||||
import "dart:isolate";
|
||||
import "package:angular2/src/web_workers/worker/application.dart"
|
||||
show bootstrapWebWorker;
|
||||
import "package:angular2/platform/worker_app.dart";
|
||||
import "package:angular2/core.dart";
|
||||
import "package:angular2/src/core/reflection/reflection_capabilities.dart";
|
||||
import "package:angular2/src/core/reflection/reflection.dart";
|
||||
|
||||
main(List<String> args, SendPort replyTo) {
|
||||
reflector.reflectionCapabilities = new ReflectionCapabilities();
|
||||
bootstrapWebWorker(replyTo, TodoApp).catchError((error) => throw error);
|
||||
platform([WORKER_APP_PLATFORM])
|
||||
.asyncApplication(setupIsolate(replyTo))
|
||||
.then((ref) => ref.bootstrap(TodoApp));
|
||||
}
|
||||
|
@ -1,6 +1,9 @@
|
||||
import {bootstrapWebWorker} from "angular2/src/web_workers/worker/application";
|
||||
import {TodoApp} from "./index_common";
|
||||
import {platform} from "angular2/core";
|
||||
import {WORKER_APP_PLATFORM, setupWebWorker} from "angular2/platform/worker_app";
|
||||
|
||||
export function main() {
|
||||
bootstrapWebWorker(TodoApp);
|
||||
platform([WORKER_APP_PLATFORM])
|
||||
.asyncApplication(setupWebWorker)
|
||||
.then((ref) => ref.bootstrap(TodoApp));
|
||||
}
|
||||
|
@ -1,10 +1,12 @@
|
||||
library angular2.examples.web_workers.todo.index;
|
||||
|
||||
import "package:angular2/src/web_workers/ui/application.dart" show bootstrap;
|
||||
import "package:angular2/platform/worker_render.dart";
|
||||
import "package:angular2/core.dart";
|
||||
import "package:angular2/src/core/reflection/reflection_capabilities.dart";
|
||||
import "package:angular2/src/core/reflection/reflection.dart";
|
||||
|
||||
main() {
|
||||
reflector.reflectionCapabilities = new ReflectionCapabilities();
|
||||
bootstrap("background_index.dart");
|
||||
platform([WORKER_RENDER_PLATFORM])
|
||||
.asyncApplication(initIsolate("background_index.dart"));
|
||||
}
|
||||
|
@ -1,2 +1,9 @@
|
||||
import {bootstrap} from "angular2/src/web_workers/ui/application";
|
||||
bootstrap("loader.js");
|
||||
import {platform, Provider} from 'angular2/core';
|
||||
import {
|
||||
WORKER_RENDER_APP,
|
||||
WORKER_RENDER_PLATFORM,
|
||||
WORKER_SCRIPT
|
||||
} from 'angular2/platform/worker_render';
|
||||
|
||||
platform([WORKER_RENDER_PLATFORM])
|
||||
.application([WORKER_RENDER_APP, new Provider(WORKER_SCRIPT, {useValue: "loader.js"})]);
|
@ -1,4 +1,5 @@
|
||||
import {NgFor, View, Component, FORM_DIRECTIVES} from 'angular2/web_worker/worker';
|
||||
import {View, Component} from 'angular2/core';
|
||||
import {NgFor, FORM_DIRECTIVES} from 'angular2/common';
|
||||
import {Store, Todo, TodoFactory} from './services/TodoStore';
|
||||
|
||||
@Component({selector: 'todo-app', viewProviders: [Store, TodoFactory]})
|
||||
|
@ -2,10 +2,10 @@ library angular2.examples.web_workers.todo.index_web_socket;
|
||||
|
||||
import "package:angular2/src/core/reflection/reflection_capabilities.dart";
|
||||
import "package:angular2/src/core/reflection/reflection.dart";
|
||||
import "package:angular2/src/web_workers/ui/impl.dart" show bootstrapUICommon;
|
||||
import "package:angular2/core.dart";
|
||||
import "package:angular2/platform/worker_render.dart";
|
||||
import "package:angular2/src/web_workers/debug_tools/web_socket_message_bus.dart";
|
||||
import 'dart:html'
|
||||
show WebSocket;
|
||||
import 'dart:html' show WebSocket;
|
||||
|
||||
main() {
|
||||
reflector.reflectionCapabilities = new ReflectionCapabilities();
|
||||
@ -13,6 +13,13 @@ main() {
|
||||
webSocket.onOpen.listen((e) {
|
||||
var bus = new WebSocketMessageBus.fromWebSocket(webSocket);
|
||||
|
||||
bootstrapUICommon(bus);
|
||||
platform([WORKER_RENDER_PLATFORM])
|
||||
.application([WORKER_RENDER_APP_COMMON, new Provider(MessageBus, useValue: bus),
|
||||
new Provider(APP_INITIALIZER,
|
||||
useFactory: (injector) => () => initializeGenericWorkerRenderer(injector),
|
||||
deps: [Injector],
|
||||
multi: true
|
||||
)
|
||||
]);
|
||||
});
|
||||
}
|
||||
|
@ -1,19 +1,28 @@
|
||||
library angular2.examples.web_workers.todo.server_index;
|
||||
|
||||
import "index_common.dart" show TodoApp;
|
||||
import "package:angular2/src/web_workers/debug_tools/multi_client_server_message_bus.dart";
|
||||
import "package:angular2/src/web_workers/worker/application_common.dart"
|
||||
show bootstrapWebWorkerCommon;
|
||||
import "package:angular2/platform/worker_app.dart";
|
||||
import "package:angular2/core.dart";
|
||||
import 'dart:io';
|
||||
import 'dart:async';
|
||||
import "package:angular2/src/core/reflection/reflection_capabilities.dart";
|
||||
import "package:angular2/src/core/reflection/reflection.dart";
|
||||
import "package:angular2/src/platform/server/html_adapter.dart";
|
||||
|
||||
void main() {
|
||||
reflector.reflectionCapabilities = new ReflectionCapabilities();
|
||||
platform([WORKER_APP_PLATFORM])
|
||||
.asyncApplication(initAppThread)
|
||||
.then((ref) => ref.bootstrap(TodoApp));
|
||||
}
|
||||
|
||||
Future<dynamic> initAppThread(NgZone zone) {
|
||||
Html5LibDomAdapter.makeCurrent();
|
||||
reflector.reflectionCapabilities = new ReflectionCapabilities();
|
||||
HttpServer.bind('127.0.0.1', 1337).then((HttpServer server) {
|
||||
return HttpServer.bind('127.0.0.1', 1337).then((HttpServer server) {
|
||||
print("Server Listening for requests on 127.0.0.1:1337");
|
||||
var bus = new MultiClientServerMessageBus.fromHttpServer(server);
|
||||
bootstrapWebWorkerCommon(TodoApp, bus).catchError((error) => throw error);
|
||||
print ("Server Listening for requests on 127.0.0.1:1337");
|
||||
return genericWorkerAppProviders(bus, zone);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import {Injectable} from 'angular2/web_worker/worker';
|
||||
import {Injectable} from 'angular2/core';
|
||||
import {ListWrapper, Predicate} from 'angular2/src/facade/collection';
|
||||
|
||||
// base model for RecordStore
|
||||
|
Reference in New Issue
Block a user