Skip to content

Instantly share code, notes, and snippets.

@alxhub
Created March 16, 2018 15:42
Show Gist options
  • Select an option

  • Save alxhub/82c85f46cb3ac495708acba5c0d1ed69 to your computer and use it in GitHub Desktop.

Select an option

Save alxhub/82c85f46cb3ac495708acba5c0d1ed69 to your computer and use it in GitHub Desktop.
onUnsubscribe Rx operator
function onUnsubscribe<T>(fn: () => void): (obs: Observable<T>) => Observable<T> {
return (obs: Observable<T>): Observable<T> => {
return new Observable<T>(subscriber => {
const sub = obs.subscribe(subscriber);
return () => {
sub.unsubscribe();
fn();
};
});
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment