Last active
June 22, 2021 02:02
-
-
Save krishnathota/1477bb8d4cb72da31ee509d14dba5f56 to your computer and use it in GitHub Desktop.
Revisions
-
krishnathota renamed this gist
Jun 22, 2021 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
krishnathota renamed this gist
Jun 22, 2021 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
krishnathota created this gist
Jun 22, 2021 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,23 @@ import { Injectable, OnDestroy } from '@angular/core'; import { SubscriptionLike } from 'rxjs'; import { SubSink } from 'subsink'; /** * @description Keeps hold of your subscriptions and unsubscribes them when component is destroyed. * This uses 'SubSink' library to achieve this. * @usage Extend your component from this 'MyComponent extends Unsubscribe'. Call super() in your component's constructor. * @important Please keep a note that if you happen to implement OnDestroy in your component, * you have to explicitly call super.ngOnDestroy() to invoke un-subscription for the component. * @param sub; Subscription list. Assign your subscriptions in your component to 'sub' */ @Injectable() export abstract class Unsubscribe implements OnDestroy { _subSink = new SubSink(); set sub(subscription: SubscriptionLike) { this._subSink.sink = subscription; } ngOnDestroy(): void { this._subSink.unsubscribe(); } }