Created
March 16, 2018 15:42
-
-
Save alxhub/82c85f46cb3ac495708acba5c0d1ed69 to your computer and use it in GitHub Desktop.
onUnsubscribe Rx operator
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 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