2015-08-20 14:28:25 -07:00
|
|
|
import {EventEmitter} from 'angular2/src/core/facade/async';
|
2015-09-10 15:25:36 -07:00
|
|
|
import {BaseException, WrappedException} from 'angular2/src/core/facade/exceptions';
|
2015-09-08 10:52:06 -07:00
|
|
|
import {NgZone} from 'angular2/src/core/zone/ng_zone';
|
2015-08-27 10:39:39 -07:00
|
|
|
export {EventEmitter, Observable} from 'angular2/src/core/facade/async';
|
2015-08-17 10:28:47 -07:00
|
|
|
|
|
|
|
|
function _abstract() {
|
|
|
|
|
throw new BaseException("This method is abstract");
|
|
|
|
|
}
|
|
|
|
|
|
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-08-21 12:21:29 -07:00
|
|
|
export /* abstract (with TS 1.6) */ 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
|
|
|
*/
|
|
|
|
|
initChannel(channel: string, runInZone: boolean = true): void { throw _abstract(); }
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
|
|
|
|
attachToZone(zone: NgZone): void { throw _abstract(); }
|
|
|
|
|
|
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-08-21 12:21:29 -07:00
|
|
|
from(channel: string): EventEmitter { throw _abstract(); }
|
|
|
|
|
|
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-08-21 12:21:29 -07:00
|
|
|
to(channel: string): EventEmitter { throw _abstract(); }
|
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-08-17 10:28:47 -07:00
|
|
|
* Returns an {@link EventEmitter} that emits every time a messsage
|
|
|
|
|
* is received on the given channel.
|
2015-07-10 16:09:18 -07:00
|
|
|
*/
|
2015-08-17 10:28:47 -07:00
|
|
|
from(channel: string): EventEmitter;
|
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
|
|
|
|
|
*/
|
|
|
|
|
to(channel: string): EventEmitter;
|
|
|
|
|
}
|