2015-08-17 10:28:47 -07:00
|
|
|
import {EventEmitter} from 'angular2/src/facade/async';
|
|
|
|
|
import {BaseException} from 'angular2/src/facade/lang';
|
|
|
|
|
|
|
|
|
|
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-08-17 10:28:47 -07:00
|
|
|
/**
|
|
|
|
|
* Returns an {@link EventEmitter} that emits every time a messsage
|
|
|
|
|
* 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-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 {
|
|
|
|
|
/**
|
|
|
|
|
* 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;
|
|
|
|
|
}
|