fix(WebWorker): Add zone support to MessageBus

Closes #4053
This commit is contained in:
Jason Teplitz
2015-09-08 10:52:06 -07:00
parent 3b9c08676a
commit f3da37c92f
35 changed files with 628 additions and 365 deletions

View File

@ -5,7 +5,8 @@ import 'dart:async';
import 'dart:core';
import 'package:angular2/src/web_workers/shared/message_bus.dart'
show MessageBus;
import 'package:angular2/src/web_workers/ui/impl.dart' show bootstrapUICommon, WebWorkerApplication;
import 'package:angular2/src/web_workers/ui/impl.dart'
show bootstrapUICommon, WebWorkerApplication;
import 'package:angular2/src/web_workers/shared/isolate_message_bus.dart';
/**
@ -37,7 +38,7 @@ Future<IsolateInstance> spawnWebWorker(Uri uri) async {
class UIMessageBusSource extends IsolateMessageBusSource {
UIMessageBusSource(ReceivePort port) : super(port);
Future<SendPort> get sink => rawDataStream.firstWhere((message) {
Future<SendPort> get sink => stream.firstWhere((message) {
return message is SendPort;
});
}

View File

@ -32,6 +32,7 @@ export function bootstrapUICommon(bus: MessageBus): WebWorkerApplication {
BrowserDomAdapter.makeCurrent();
var zone = createNgZone();
wtfInit();
bus.attachToZone(zone);
return zone.run(() => {
var injector = createInjector(zone, bus);
injector.get(MessageBasedRenderCompiler).start();
@ -47,11 +48,11 @@ export class WebWorkerApplication {
constructor(private _clientMessageBrokerFactory: ClientMessageBrokerFactory,
private _serviceMessageBrokerFactory: ServiceMessageBrokerFactory) {}
createClientMessageBroker(channel: string): ClientMessageBroker {
return this._clientMessageBrokerFactory.createMessageBroker(channel);
createClientMessageBroker(channel: string, runInZone: boolean = true): ClientMessageBroker {
return this._clientMessageBrokerFactory.createMessageBroker(channel, runInZone);
}
createServiceMessageBroker(channel: string): ServiceMessageBroker {
return this._serviceMessageBrokerFactory.createMessageBroker(channel);
createServiceMessageBroker(channel: string, runInZone: boolean = true): ServiceMessageBroker {
return this._serviceMessageBrokerFactory.createMessageBroker(channel, runInZone);
}
}

View File

@ -17,7 +17,7 @@ export class MessageBasedRenderCompiler {
private _renderCompiler: RenderCompiler) {}
start(): void {
var broker = this._brokerFactory.createMessageBroker(RENDER_COMPILER_CHANNEL);
var broker = this._brokerFactory.createMessageBroker(RENDER_COMPILER_CHANNEL, false);
broker.registerMethod("compileHost", [RenderDirectiveMetadata],
bind(this._renderCompiler.compileHost, this._renderCompiler),
ProtoViewDto);

View File

@ -26,6 +26,7 @@ export class MessageBasedRenderer {
start(): void {
var broker = this._brokerFactory.createMessageBroker(RENDERER_CHANNEL);
this._bus.initChannel(EVENT_CHANNEL);
broker.registerMethod("createRootHostView",
[RenderProtoViewRef, PRIMITIVE, PRIMITIVE, PRIMITIVE],
bind(this._createRootHostView, this));

View File

@ -14,6 +14,7 @@ export class WebWorkerSetup {
}
start(): void {
this._bus.initChannel(SETUP_CHANNEL, false);
var sink = this._bus.to(SETUP_CHANNEL);
var source = this._bus.from(SETUP_CHANNEL);