Add a method to remove event listeners from event dispatchers

This commit is contained in:
Adomas Venčkauskas 2021-10-04 17:10:28 +03:00
parent 05139cfff8
commit 82eb7453a8

View file

@ -2151,7 +2151,10 @@ Zotero.Utilities.Internal = {
return {
addListener: (listener, once) => {
this._addListener(event, listener, alwaysOnce || once, immediateAfterTrigger);
}
},
removeListener: (listener) => {
this._removeListener(event, listener);
},
}
};
@ -2169,6 +2172,15 @@ Zotero.Utilities.Internal = {
}
this._events[event].listeners.set(listener, once);
};
cls.prototype._removeListener = function(event, listener) {
let ev = this._events[event];
if (!ev || !ev.listeners) {
Zotero.debug(`EventListener.removeListener(): attempting to remove an invalid event ${event} listener`);
return;
}
ev.listeners.delete(listener);
};
cls.prototype._waitForEvent = async function (event) {
return new Zotero.Promise((resolve, reject) => {