-
-
Save brigand/29d6eb8e6b04d7d90da763ddc8e9df00 to your computer and use it in GitHub Desktop.
domOn, domOnce
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function domOn(subject, eventName, handler, options = false) { | |
// This function is useless except in the case domOn(x, 'e', f); domOn(x, 'e', f); is run | |
// where cleanup can remove the distinct 'inner' function from each call, instead of both 'f' listeners. | |
function inner(event) { | |
return handler.call(this, event); | |
} | |
subject.addEventListener(eventName, inner, options); | |
const cleanup = () => subject.removeEventListener(eventName, inner, options); | |
return cleanup; | |
} | |
function domOnce(subject, eventName, handler, options = false) { | |
const cleanup = domOn(subject, eventName, function (event) { | |
cleanup(); | |
return handler(event); | |
}, options); | |
return cleanup; | |
} | |
domOnce(session, 'end', () => { | |
// TODO: implement | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment