Skip to content

Commit

Permalink
Fix unbinding once events
Browse files Browse the repository at this point in the history
  • Loading branch information
nolimits4web committed Feb 11, 2019
1 parent 91f0a21 commit e34a698
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,9 @@ function off(...args) {
if (listener && handler.listener === listener) {
el.removeEventListener(event, handler.proxyListener, capture);
handlers.splice(k, 1);
} else if (listener && handler.listener && handler.listener.dom7proxy && handler.listener.dom7proxy === listener) {
el.removeEventListener(event, handler.proxyListener, capture);
handlers.splice(k, 1);
} else if (!listener) {
el.removeEventListener(event, handler.proxyListener, capture);
handlers.splice(k, 1);
Expand All @@ -305,11 +308,15 @@ function once(...args) {
[eventName, listener, capture] = args;
targetSelector = undefined;
}
function proxy(...eventArgs) {
function onceHandler(...eventArgs) {
listener.apply(this, eventArgs);
dom.off(eventName, targetSelector, proxy, capture);
dom.off(eventName, targetSelector, onceHandler, capture);
if (onceHandler.dom7proxy) {
delete onceHandler.dom7proxy;
}
}
return dom.on(eventName, targetSelector, proxy, capture);
onceHandler.dom7proxy = listener;
return dom.on(eventName, targetSelector, onceHandler, capture);
}
function trigger(...args) {
const events = args[0].split(' ');
Expand Down

0 comments on commit e34a698

Please sign in to comment.