Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic typescript of event handler. #2130

Merged
merged 1 commit into from Feb 14, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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