Skip to content

Instantly share code, notes, and snippets.

@ahsquared
Last active January 29, 2017 12:28
Show Gist options
  • Save ahsquared/b2442ffcf94ab5c3a244669531c0fe63 to your computer and use it in GitHub Desktop.
Save ahsquared/b2442ffcf94ab5c3a244669531c0fe63 to your computer and use it in GitHub Desktop.
RxJS Delegate
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