Skip to content

Instantly share code, notes, and snippets.

@donpark
Created September 9, 2016 16:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save donpark/733c1f9660c8155307a5ee5fe17ef22f to your computer and use it in GitHub Desktop.
Save donpark/733c1f9660c8155307a5ee5fe17ef22f to your computer and use it in GitHub Desktop.
export function listenOnce(target, type, listener, options) {
let once = (e) => {
target.removeEventListener(type, once, options)
listener(e)
}
target.addEventListener(type, once, options)
}
export function listenAnyOnce(target, types, listener, options) {
let once = (e) => {
for (let i = 0, n = types.length; i < n; i++) {
target.removeEventListener(types[i], once, options)
}
listener(e)
}
for (let i = 0, n = types.length; i < n; i++) {
target.addEventListener(types[i], once, options)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment