1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-12-26 17:08:33 +01:00

move broadcaster to jslib

This commit is contained in:
Kyle Spearrin 2018-04-06 15:33:38 -04:00
parent 0b9c2f518d
commit 5d66ede2ea

View File

@ -0,0 +1,33 @@
import { Injectable } from '@angular/core';
@Injectable()
export class BroadcasterService {
subscribers: Map<string, (message: any) => any> = new Map<string, (message: any) => any>();
send(message: any, id?: string) {
if (id != null) {
if (this.subscribers.has(id)) {
this.subscribers.get(id)(message);
}
return;
}
this.subscribers.forEach((value) => {
value(message);
});
}
subscribe(id: string, messageCallback: (message: any) => any) {
if (this.subscribers.has(id)) {
return;
}
this.subscribers.set(id, messageCallback);
}
unsubscribe(id: string) {
if (this.subscribers.has(id)) {
this.subscribers.delete(id);
}
}
}