fix(WebWorker): Fix PostMessageBusSink and Source undefined error.

Closes #7156
This commit is contained in:
Jason Teplitz 2016-02-18 11:17:31 -08:00 committed by vsavkin
parent 9aedef208f
commit 01fe7f5fac
1 changed files with 25 additions and 25 deletions

View File

@ -9,28 +9,8 @@ import {StringMapWrapper} from 'angular2/src/facade/collection';
import {Injectable} from "angular2/src/core/di"; import {Injectable} from "angular2/src/core/di";
import {NgZone} from 'angular2/src/core/zone/ng_zone'; import {NgZone} from 'angular2/src/core/zone/ng_zone';
/** // TODO(jteplitz602) Replace this with the definition in lib.webworker.d.ts(#3492)
* A TypeScript implementation of {@link MessageBus} for communicating via JavaScript's export interface PostMessageTarget { postMessage: (message: any, transfer?:[ArrayBuffer]) => void; }
* postMessage API.
*/
@Injectable()
export class PostMessageBus implements MessageBus {
constructor(public sink: PostMessageBusSink, public source: PostMessageBusSource) {}
attachToZone(zone: NgZone): void {
this.source.attachToZone(zone);
this.sink.attachToZone(zone);
}
initChannel(channel: string, runInZone: boolean = true): void {
this.source.initChannel(channel, runInZone);
this.sink.initChannel(channel, runInZone);
}
from(channel: string): EventEmitter<any> { return this.source.from(channel); }
to(channel: string): EventEmitter<any> { return this.sink.to(channel); }
}
export class PostMessageBusSink implements MessageBusSink { export class PostMessageBusSink implements MessageBusSink {
private _zone: NgZone; private _zone: NgZone;
@ -135,6 +115,29 @@ export class PostMessageBusSource implements MessageBusSource {
} }
} }
/**
* A TypeScript implementation of {@link MessageBus} for communicating via JavaScript's
* postMessage API.
*/
@Injectable()
export class PostMessageBus implements MessageBus {
constructor(public sink: PostMessageBusSink, public source: PostMessageBusSource) {}
attachToZone(zone: NgZone): void {
this.source.attachToZone(zone);
this.sink.attachToZone(zone);
}
initChannel(channel: string, runInZone: boolean = true): void {
this.source.initChannel(channel, runInZone);
this.sink.initChannel(channel, runInZone);
}
from(channel: string): EventEmitter<any> { return this.source.from(channel); }
to(channel: string): EventEmitter<any> { return this.sink.to(channel); }
}
/** /**
* Helper class that wraps a channel's {@link EventEmitter} and * Helper class that wraps a channel's {@link EventEmitter} and
* keeps track of if it should run in the zone. * keeps track of if it should run in the zone.
@ -142,6 +145,3 @@ export class PostMessageBusSource implements MessageBusSource {
class _Channel { class _Channel {
constructor(public emitter: EventEmitter<any>, public runInZone: boolean) {} constructor(public emitter: EventEmitter<any>, public runInZone: boolean) {}
} }
// TODO(jteplitz602) Replace this with the definition in lib.webworker.d.ts(#3492)
export interface PostMessageTarget { postMessage: (message: any, transfer?:[ArrayBuffer]) => void; }