1
0
mirror of https://github.com/bpatrik/pigallery2.git synced 2024-12-12 11:15:22 +02:00
pigallery2/common/event/Event2Args.ts

24 lines
583 B
TypeScript
Raw Normal View History

2016-03-14 12:07:08 +02:00
///<reference path="../../typings/main.d.ts"/>
2016-03-13 12:28:29 +02:00
export class Event2Args<T,M> {
private handlers: { (data?: T,data2?: M): void; }[] = [];
public on(handler: { (data?: T,data2?: M): void }) {
this.handlers.push(handler);
}
public off(handler: { (data?: T,data2?: M): void }) {
this.handlers = this.handlers.filter(h => h !== handler);
}
public allOff() {
this.handlers = [];
}
public trigger(data?: T,data2?: M) {
if (this.handlers) {
this.handlers.slice(0).forEach(h => h(data,data2));
}
}
}