33 lines
765 B
TypeScript
33 lines
765 B
TypeScript
import Factory from "./factoryService";
|
|
import Vue from "vue";
|
|
// --------------------------------------------------
|
|
// Message Service Definition
|
|
// --------------------------------------------------
|
|
|
|
export class MessageService {
|
|
|
|
private _events: Vue = new Vue({});
|
|
|
|
subscribeToChannel(name: string, callback: Function, once: boolean = false) {
|
|
if (once)
|
|
this._events.$once(name, callback);
|
|
else
|
|
this._events.$on(name, callback);
|
|
}
|
|
|
|
deleteChannel(name: string) {
|
|
this._events.$off(name);
|
|
}
|
|
|
|
unsubscribeFromChannel(name: string, callback: Function) {
|
|
this._events.$off(name, callback);
|
|
}
|
|
|
|
publishToChannel<T>(name: string, ...args: any[]) {
|
|
this._events.$emit(name, args);
|
|
}
|
|
}
|
|
|
|
Factory.Register(MessageService);
|
|
|