1
0
mirror of https://github.com/xuthus83/pigallery2.git synced 2025-01-14 14:43:17 +08:00
pigallery2/src/common/event/Event2Args.ts
2021-04-18 15:48:35 +02:00

22 lines
535 B
TypeScript

export class Event2Args<T, M> {
private handlers: ((data?: T, data2?: M) => void)[] = [];
public on(handler: (data?: T, data2?: M) => void): void {
this.handlers.push(handler);
}
public off(handler: (data?: T, data2?: M) => void): void {
this.handlers = this.handlers.filter((h): boolean => h !== handler);
}
public allOff(): void {
this.handlers = [];
}
public trigger(data?: T, data2?: M): void {
if (this.handlers) {
this.handlers.slice(0).forEach((h): void => h(data, data2));
}
}
}