Add a method to remove event listeners from event dispatchers
This commit is contained in:
parent
05139cfff8
commit
82eb7453a8
1 changed files with 13 additions and 1 deletions
|
@ -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) => {
|
||||
|
|
Loading…
Reference in a new issue