Administration/src/app/core/notification/notification.service.ts
Snoweuph a4f27ed881
All checks were successful
Quality Check / Linting (push) Successful in 24s
Build Application / build (push) Successful in 55s
Build Application / build-docker (push) Successful in 8s
Build Application / release (push) Successful in 4s
CHORE: setup
2025-02-02 19:59:34 +01:00

37 lines
1,021 B
TypeScript

import { Injectable } from '@angular/core';
import { Subject, Subscription } from 'rxjs';
export interface Notification {
msg: string;
type: NotificationType;
}
export enum NotificationType {
Information = 'info',
Error = 'error',
}
export type NotificationCallback = (notification: Notification) => void;
@Injectable({ providedIn: 'root' })
export class NotificationService {
private readonly bus: Subject<Notification> = new Subject();
private readonly subscribers: Map<string, Subscription> = new Map<string, Subscription>();
subscribe(subscriberId: string, callback: NotificationCallback): void {
this.subscribers.set(
subscriberId,
this.bus.subscribe({
next: callback
})
);
}
publish(msg: string, type: NotificationType = NotificationType.Information) {
this.bus.next({ msg, type });
}
unsubscribe(subscriberId: string) {
this.subscribers.get(subscriberId)?.unsubscribe();
}
}