mirror of
https://github.com/novnc/noVNC.git
synced 2026-06-06 04:19:41 +00:00
Always use the shorthand notation if the function is a method of an object or class `{ foo() { ... } }` or `class bar { foo() { ... } }`
unless it's a callback in which case you a fat arrow function should be used `{ cb: () => { ... } }`
41 lines
1016 B
JavaScript
41 lines
1016 B
JavaScript
/*
|
|
* noVNC: HTML5 VNC client
|
|
* Copyright 2017 Pierre Ossman for Cendio AB
|
|
* Licensed under MPL 2.0 (see LICENSE.txt)
|
|
*
|
|
* See README.md for usage and integration instructions.
|
|
*/
|
|
|
|
export default class EventTargetMixin {
|
|
constructor() {
|
|
this._listeners = null;
|
|
}
|
|
|
|
addEventListener(type, callback) {
|
|
if (!this._listeners) {
|
|
this._listeners = new Map();
|
|
}
|
|
if (!this._listeners.has(type)) {
|
|
this._listeners.set(type, new Set());
|
|
}
|
|
this._listeners.get(type).add(callback);
|
|
}
|
|
|
|
removeEventListener(type, callback) {
|
|
if (!this._listeners || !this._listeners.has(type)) {
|
|
return;
|
|
}
|
|
this._listeners.get(type).delete(callback);
|
|
}
|
|
|
|
dispatchEvent(event) {
|
|
if (!this._listeners || !this._listeners.has(event.type)) {
|
|
return true;
|
|
}
|
|
this._listeners.get(event.type).forEach(function (callback) {
|
|
callback.call(this, event);
|
|
}, this);
|
|
return !event.defaultPrevented;
|
|
}
|
|
}
|