Last active
January 29, 2017 12:28
-
-
Save ahsquared/b2442ffcf94ab5c3a244669531c0fe63 to your computer and use it in GitHub Desktop.
RxJS Delegate
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 delegate(wrapper, selector, eventNames) { | |
return Rx.Observable.from(eventNames.split(",")).mergeMap(eventName => { | |
return Rx.Observable.fromEvent( | |
wrapper, | |
eventName.replace(/\s/g, ""), | |
function (e) { | |
return {event: e, delegate: e.target.closest(selector)}; | |
}); | |
}).filter(function (x) { | |
return x.delegate !== null; | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment