W3cubDocs

/Angular 2 TypeScript

MessageBus

Experimental Class

Class Overview

class MessageBus implements MessageBusSource,  MessageBusSink {
  initChannel(channel: string, runInZone?: boolean) : void
  attachToZone(zone: NgZone) : void
  from(channel: string) : EventEmitter<any>
  to(channel: string) : EventEmitter<any>
}

Class Description

Message Bus is a low level API used to communicate between the UI and the background. Communication is based on a channel abstraction. Messages published in a given channel to one MessageBusSink are received on the same channel by the corresponding MessageBusSource.

Class Details

initChannel(channel: string, runInZone?: boolean) : void

Sets up a new channel on the MessageBus. MUST be called before calling from or to on the channel. If runInZone is true then the source will emit events inside the angular zone and the sink will buffer messages and send only once the zone exits. if runInZone is false then the source will emit events inside the global zone and the sink will send messages immediately.

attachToZone(zone: NgZone) : void

Assigns this bus to the given zone. Any callbacks attached to channels where runInZone was set to true on initialization will be executed in the given zone.

from(channel: string) : EventEmitter<any>

Returns an EventEmitter that emits every time a message is received on the given channel.

to(channel: string) : EventEmitter<any>

Returns an EventEmitter for the given channel To publish methods to that channel just call next on the returned emitter

exported from @angular/platform-webworker/index, defined in @angular/platform-webworker/src/web_workers/shared/message_bus.ts

© 2010–2017 Google, Inc.
Licensed under the Creative Commons Attribution License 4.0.
https://v2.angular.io/docs/ts/latest/api/platform-webworker/index/MessageBus-class.html