Created
July 24, 2016 09:22
-
-
Save codemilli/ce0eac669773c3a9d293154ada929f13 to your computer and use it in GitHub Desktop.
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 listen(element, eventName) { | |
return new Observable(observer => { | |
// Create an event handler which sends data to the sink | |
let handler = event => observer.next(event); | |
// Attach the event handler | |
element.addEventListener(eventName, handler, true); | |
// Return a function which will cancel the event stream | |
return () => { | |
// Detach the event handler from the element | |
element.removeEventListener(eventName, handler, true); | |
}; | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment