mirror of
https://github.com/bitwarden/browser
synced 2024-12-27 02:14:24 +01:00
move broadcaster to jslib
This commit is contained in:
parent
0b9c2f518d
commit
5d66ede2ea
33
src/angular/services/broadcaster.service.ts
Normal file
33
src/angular/services/broadcaster.service.ts
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user