Skip to content

Instantly share code, notes, and snippets.

@samverneck
Created January 31, 2017 14:05
Show Gist options
  • Save samverneck/f8e2491dfcd8ea8f5cc7a0432b36321b to your computer and use it in GitHub Desktop.
Save samverneck/f8e2491dfcd8ea8f5cc7a0432b36321b to your computer and use it in GitHub Desktop.
class EventListener<T> {
private callbacks:{(user : T) : void}[] = [];
addEventListener(callback:{(user : T) : void}):void {
this.callbacks.push(callback);
}
removeEventListener(callback:{(user: T) : void}):void {
this.callbacks.splice(this.callbacks.lastIndexOf(callback));
}
fireEventListener(user:T) {
this.callbacks.forEach(_ => _(user));
}
}
var event = new EventListener<number>();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment