Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
File size: 806 Bytes
63858e7 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
/**
* Created by hen on 5/15/17.
* Modified by hoo on 4/16/19.
*/
export class SimpleEventHandler {
element: Element;
eventListeners: object[];
constructor(element: Element) {
this.element = element;
this.eventListeners = []
}
bind(eventNames: string, eventFunction: Function) {
for (const eventName of eventNames.split(' ')) {
this.eventListeners.push({eventName, eventFunction});
const eventFunctionWrap = e => eventFunction(e.detail, e);
this.element.addEventListener(eventName, eventFunctionWrap, false);
}
}
getListeners() {
return this.eventListeners;
}
trigger(eventName: string, detail: object) {
this.element.dispatchEvent(new CustomEvent(eventName, {detail}));
}
} |