rxsubsink
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

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();
  }
}

Package Sidebar

Install

npm i rxsubsink

Weekly Downloads

0

Version

1.0.0

License

MIT

Unpacked Size

8.79 kB

Total Files

11

Last publish

Collaborators

  • js-media