Skip to content

Instantly share code, notes, and snippets.

@BibbyChung
Last active June 25, 2019 06:45
Show Gist options
  • Save BibbyChung/2ec39f72e39933466cbafafd57a0715f to your computer and use it in GitHub Desktop.
Save BibbyChung/2ec39f72e39933466cbafafd57a0715f to your computer and use it in GitHub Desktop.
easy to unsubscribe...
import { Subscription } from 'rxjs';
declare module 'rxjs/internal/Subscription' {
interface Subscription {
toUnsubscription(
this: Subscription,
sub: Subscription
): void;
}
}
Subscription.prototype.toUnsubscription =
function (
this: Subscription,
sub: Subscription
): void {
sub.add(this);
};
@BibbyChung
Copy link
Author

BibbyChung commented Jun 24, 2019

how to use it

import './subscription.extensions';
const sub = new Subscription();

const ob = interval(1000);
ob.subscribe(x => {
  console.log('show => ', x);
}).toUnsubscription(sub);

sub.unsubscribe();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment