Skip to content
This repository has been archived by the owner on Jan 8, 2023. It is now read-only.

JelleBruisten/rxjs-subscription-sink

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rxjs-subscription-sink

RxJS subscription sink for unsubscribing gracefully in a component.

SubscriptionSink is a simple RxJS Subscription Container to track RxJS subscriptions.

Call unsubscribe() to unsubscribe all of them, as you would do in your component library's unmount/onDestroy lifecycle event.

Angular example

export class SomeComponent implements OnDestroy {
  private subs = new SubscriptionSink();

  ...

  // short and easy syntax
  this.subs.sink = observable$.subscribe(...);  

  // normal syntax
  this.subs.add(observable$.subscribe(...)); 

  // can add multiple subcriptions
  this.subs.add( 
    observable$.subscribe(...),
    anotherObservable$.subscribe(...)
  ); 

  ...

  // Unsubscribe when the component dies
  ngOnDestroy() {

    // normal way
    this.subs.unsubscribe();

    // using the allias
    this.subs.flush();
  }
}

About

A Rxjs Subscription container class

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published