mirror of
https://github.com/xuthus83/pigallery2.git
synced 2024-11-03 21:04:03 +08:00
24 lines
582 B
TypeScript
24 lines
582 B
TypeScript
|
///<reference path="../../typings/tsd.d.ts"/>
|
||
|
|
||
|
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));
|
||
|
}
|
||
|
}
|
||
|
}
|