nope/lib/communication/eventLayer.ts

20 lines
571 B
TypeScript
Raw Normal View History

2020-08-21 16:38:21 +00:00
import { EventEmitter } from "events";
2020-08-23 07:21:03 +00:00
import { CommunicationEvents, ICommunicationInterface } from "../dispatcher/nopeDispatcher";
2020-08-21 16:38:21 +00:00
2020-08-23 07:21:03 +00:00
/**
2020-09-11 07:59:23 +00:00
* A Communication Layer for the Dispatchers.
* Here, only a Events are used.
*
* @export
* @class EventLayer
* @implements {ICommunicationInterface}
2020-08-23 07:21:03 +00:00
*/
2020-08-21 16:38:21 +00:00
export class EventLayer implements ICommunicationInterface {
protected _emitter = new EventEmitter();
on(event: CommunicationEvents, cb: (...args: any[]) => void) {
this._emitter.on(event, cb);
}
send(data: any): void {
this._emitter.emit('event', data)
}
}