Created
October 31, 2014 09:27
-
-
Save orloffv/4aa04d7d5f9af8a4be67 to your computer and use it in GitHub Desktop.
This file contains 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
"use strict"; | |
var {unload} = require("unload+"); | |
/** | |
* Helper that adds event listeners and remembers to remove on unload | |
*/ | |
exports.listen = function listen(window, node, event, func, capture) { | |
// Default to use capture | |
if (capture == null) | |
capture = true; | |
node.addEventListener(event, func, capture); | |
function undoListen() { | |
node.removeEventListener(event, func, capture); | |
} | |
// Undo the listener on unload and provide a way to undo everything | |
let undoUnload = unload(undoListen, window); | |
return function() { | |
undoListen(); | |
undoUnload(); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment