2017-06-10 22:32:56 +02:00
|
|
|
export class Event2Args<T, M> {
|
2018-05-12 18:19:51 +02:00
|
|
|
private handlers: ((data?: T, data2?: M) => void)[] = [];
|
2016-03-13 12:28:29 +02:00
|
|
|
|
2018-05-12 18:19:51 +02:00
|
|
|
public on(handler: (data?: T, data2?: M) => void) {
|
2017-06-10 22:32:56 +02:00
|
|
|
this.handlers.push(handler);
|
|
|
|
}
|
2016-03-13 12:28:29 +02:00
|
|
|
|
2018-05-12 18:19:51 +02:00
|
|
|
public off(handler: (data?: T, data2?: M) => void) {
|
2017-06-10 22:32:56 +02:00
|
|
|
this.handlers = this.handlers.filter(h => h !== handler);
|
|
|
|
}
|
2016-03-13 12:28:29 +02:00
|
|
|
|
2017-06-10 22:32:56 +02:00
|
|
|
public allOff() {
|
|
|
|
this.handlers = [];
|
|
|
|
}
|
2016-03-13 12:28:29 +02:00
|
|
|
|
2017-06-10 22:32:56 +02:00
|
|
|
public trigger(data?: T, data2?: M) {
|
|
|
|
if (this.handlers) {
|
|
|
|
this.handlers.slice(0).forEach(h => h(data, data2));
|
2016-03-13 12:28:29 +02:00
|
|
|
}
|
2017-06-10 22:32:56 +02:00
|
|
|
}
|
2016-03-13 12:28:29 +02:00
|
|
|
}
|