Created
April 19, 2015 16:27
-
-
Save jhusain/4b14f5069f3a254cfa0a to your computer and use it in GitHub Desktop.
Converting event to Observable
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
function fromEvent(dom, eventName) { | |
return { | |
forEach: function(observer) { | |
var handler = (e) => { | |
observer.onNext(e); | |
}; | |
dom.addEventListener(eventName, handler); | |
// Subscription | |
return { | |
dispose: function() { | |
dom.removeEventListener(eventName, handler); | |
} | |
} | |
} | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment