summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-05-23 13:19:31 -0400
committerGitHub <noreply@github.com>2020-05-23 13:19:31 -0400
commit9a657214ad84f031c4c642cfa64ffa6b7d71ad77 (patch)
tree13d0a897210fbc7863787a79384c412b1e1d2916
parentd0dcff765f740bf6f0f6523b09cb8b21eb85cd93 (diff)
Add support for additional types of event listeners (#522)
* Add support for additional types of event listeners * Fixes
-rw-r--r--ext/mixed/js/core.js32
1 files changed, 27 insertions, 5 deletions
diff --git a/ext/mixed/js/core.js b/ext/mixed/js/core.js
index 589425f2..fa66033d 100644
--- a/ext/mixed/js/core.js
+++ b/ext/mixed/js/core.js
@@ -255,15 +255,37 @@ class EventListenerCollection {
return this._eventListeners.length;
}
- addEventListener(node, type, listener, options) {
- node.addEventListener(type, listener, options);
- this._eventListeners.push([node, type, listener, options]);
+ addEventListener(object, ...args) {
+ object.addEventListener(...args);
+ this._eventListeners.push(['removeEventListener', object, ...args]);
+ }
+
+ addListener(object, ...args) {
+ object.addListener(args);
+ this._eventListeners.push(['removeListener', object, ...args]);
+ }
+
+ on(object, ...args) {
+ object.on(args);
+ this._eventListeners.push(['off', object, ...args]);
}
removeAllEventListeners() {
if (this._eventListeners.length === 0) { return; }
- for (const [node, type, listener, options] of this._eventListeners) {
- node.removeEventListener(type, listener, options);
+ for (const [removeFunctionName, object, ...args] of this._eventListeners) {
+ switch (removeFunctionName) {
+ case 'removeEventListener':
+ object.removeEventListener(...args);
+ break;
+ case 'removeListener':
+ object.removeListener(...args);
+ break;
+ case 'off':
+ object.off(...args);
+ break;
+ default:
+ throw new Error(`Unknown remove function: ${removeFunctionName}`);
+ }
}
this._eventListeners = [];
}