2015-11-06 17:34:07 -08:00
|
|
|
import {EventEmitter} from 'angular2/src/facade/async';
|
2015-09-08 10:52:06 -07:00
|
|
|
import {NgZone} from 'angular2/src/core/zone/ng_zone';
|
2015-11-06 17:34:07 -08:00
|
|
|
export {EventEmitter, Observable} from 'angular2/src/facade/async';
|
2015-08-17 10:28:47 -07:00
|
|
|
|
2015-07-10 16:09:18 -07:00
|
|
|
/**
|
2015-08-17 10:28:47 -07:00
|
|
|
* 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.
|
2015-07-10 16:09:18 -07:00
|
|
|
*/
|
2015-09-25 14:48:17 -07:00
|
|
|
export abstract class MessageBus implements MessageBusSource, MessageBusSink {
|
2015-09-08 10:52:06 -07:00
|
|
|
/**
|
|
|
|
|
* 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
|
2015-09-08 22:43:10 -07:00
|
|
|
* and the sink will send messages immediately.
|
2015-09-08 10:52:06 -07:00
|
|
|
*/
|
2015-09-25 14:48:17 -07:00
|
|
|
abstract initChannel(channel: string, runInZone?: boolean): void;
|
2015-09-08 10:52:06 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
2015-09-25 14:48:17 -07:00
|
|
|
abstract attachToZone(zone: NgZone): void;
|
2015-09-08 10:52:06 -07:00
|
|
|
|
2015-08-17 10:28:47 -07:00
|
|
|
/**
|
2015-09-09 00:12:40 -07:00
|
|
|
* Returns an {@link EventEmitter} that emits every time a message
|
2015-08-17 10:28:47 -07:00
|
|
|
* is received on the given channel.
|
|
|
|
|
*/
|
2015-10-24 18:48:43 -07:00
|
|
|
abstract from(channel: string): EventEmitter<any>;
|
2015-08-21 12:21:29 -07:00
|
|
|
|
2015-07-10 16:09:18 -07:00
|
|
|
|
2015-08-17 10:28:47 -07:00
|
|
|
/**
|
|
|
|
|
* Returns an {@link EventEmitter} for the given channel
|
|
|
|
|
* To publish methods to that channel just call next (or add in dart) on the returned emitter
|
|
|
|
|
*/
|
2015-10-24 18:48:43 -07:00
|
|
|
abstract to(channel: string): EventEmitter<any>;
|
2015-07-10 16:09:18 -07:00
|
|
|
}
|
|
|
|
|
|
2015-07-10 16:09:18 -07:00
|
|
|
export interface MessageBusSource {
|
2015-09-08 10:52:06 -07:00
|
|
|
/**
|
|
|
|
|
* Sets up a new channel on the MessageBusSource.
|
|
|
|
|
* MUST be called before calling from on the channel.
|
|
|
|
|
* If runInZone is true then the source will emit events inside the angular zone.
|
|
|
|
|
* if runInZone is false then the source will emit events inside the global zone.
|
|
|
|
|
*/
|
|
|
|
|
initChannel(channel: string, runInZone: boolean): void;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Assigns this source to the given zone.
|
|
|
|
|
* Any channels which are initialized with runInZone set to true will emit events that will be
|
|
|
|
|
* executed within the given zone.
|
|
|
|
|
*/
|
|
|
|
|
attachToZone(zone: NgZone): void;
|
|
|
|
|
|
2015-07-10 16:09:18 -07:00
|
|
|
/**
|
2015-09-13 11:15:03 -04:00
|
|
|
* Returns an {@link EventEmitter} that emits every time a message
|
2015-08-17 10:28:47 -07:00
|
|
|
* is received on the given channel.
|
2015-07-10 16:09:18 -07:00
|
|
|
*/
|
2015-10-24 18:48:43 -07:00
|
|
|
from(channel: string): EventEmitter<any>;
|
2015-07-10 16:09:18 -07:00
|
|
|
}
|
2015-07-10 16:09:18 -07:00
|
|
|
|
2015-08-17 10:28:47 -07:00
|
|
|
export interface MessageBusSink {
|
2015-09-08 10:52:06 -07:00
|
|
|
/**
|
|
|
|
|
* Sets up a new channel on the MessageBusSink.
|
|
|
|
|
* MUST be called before calling to on the channel.
|
|
|
|
|
* If runInZone is true the sink will buffer messages and send only once the zone exits.
|
|
|
|
|
* if runInZone is false the sink will send messages immediatly.
|
|
|
|
|
*/
|
|
|
|
|
initChannel(channel: string, runInZone: boolean): void;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Assigns this sink to the given zone.
|
2015-09-08 22:46:24 -07:00
|
|
|
* Any channels which are initialized with runInZone set to true will wait for the given zone
|
2015-09-08 10:52:06 -07:00
|
|
|
* to exit before sending messages.
|
|
|
|
|
*/
|
|
|
|
|
attachToZone(zone: NgZone): void;
|
|
|
|
|
|
2015-08-17 10:28:47 -07:00
|
|
|
/**
|
|
|
|
|
* Returns an {@link EventEmitter} for the given channel
|
|
|
|
|
* To publish methods to that channel just call next (or add in dart) on the returned emitter
|
|
|
|
|
*/
|
2015-10-24 18:48:43 -07:00
|
|
|
to(channel: string): EventEmitter<any>;
|
2015-08-17 10:28:47 -07:00
|
|
|
}
|