Skip to content
RxJS subscription sink for unsubscribing gracefully in a component
TypeScript
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
__tests__ Initial commit Oct 11, 2018
example Initial commit Oct 11, 2018
src Initial commit Oct 11, 2018
.gitignore Initial commit Oct 11, 2018
.npmignore Initial commit Oct 11, 2018
LICENSE Initial commit Oct 11, 2018
README.md Initial commit Oct 11, 2018
package.json release: v.1.0.0. No changes May 1, 2019
tsconfig.json Initial commit Oct 11, 2018

README.md

npm Build Status Build Status npm Awesome

SubSink

RxJS subscription sink for unsubscribing gracefully in a component.

SubSink is a dead simple class to absorb RxJS subscriptions in an array.

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

Installation

npm install subsink --save

Angular example

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

  ...

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

  this.subs.add(observable$.subscribe(...)); // if you insist

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

  ...

  // Unsubscribe when the component dies
  ngOnDestroy() {
    this.subs.unsubscribe();
  }
}
You can’t perform that action at this time.