Skip to content

Commit

Permalink
Merge pull request #2130 from itsjamie/event-handler-ts
Browse files Browse the repository at this point in the history
Basic typescript of event handler.
  • Loading branch information
itsjamie committed Feb 14, 2019
2 parents 2e9f2de + ff0aa54 commit 29ad34d
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/event-handler.js → src/event-handler.ts
Expand Up @@ -15,7 +15,11 @@ const FORBIDDEN_EVENT_NAMES = {
};

class EventHandler {
constructor (hls, ...events) {
hls: any;
handledEvents: any[];
useGenericHandler: boolean;

constructor (hls: any, ...events: any[]) {
this.hls = hls;
this.onEvent = this.onEvent.bind(this);
this.handledEvents = events;
Expand Down Expand Up @@ -60,12 +64,12 @@ class EventHandler {
/**
* arguments: event (string), data (any)
*/
onEvent (event, data) {
onEvent (event: string, data: any) {
this.onEventGeneric(event, data);
}

onEventGeneric (event, data) {
let eventToFunction = function (event, data) {
onEventGeneric (event: string, data: any) {
let eventToFunction = function (event: string, data: any) {
let funcName = 'on' + event.replace('hls', '');
if (typeof this[funcName] !== 'function') {
throw new Error(`Event ${event} has no generic handler in this ${this.constructor.name} class (tried ${funcName})`);
Expand Down

0 comments on commit 29ad34d

Please sign in to comment.