Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
S

subsink

> 编程语言
Open source

RxJS subscription sink for unsubscribing gracefully in a component

395 stars0 likes2 views
WebsiteGitHub

About

RxJS subscription sink for unsubscribing gracefully in a component

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

bash
npm install subsink --save

Angular examples

There are 2 main ways to use the SubSink: the "easy" way and the "add/array" way.

RxJS supports adding subscriptions to an array of subscriptions. You can then unsubscribe directly from that array. If this appeals to you, then feel free to use it. If you prefer the technique with SubSink using the setter (aka easy) syntax below, then use that. Either way, no judgments are made. This is entirely up to you to decide.

Easy Syntax

Example using the sink property to collect the subscriptions using a setter.

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

  ...
  this.subs.sink = observable$.subscribe(...);
  this.subs.sink = observable$.subscribe(...);
  this.subs.sink = observable$.subscribe(...);
  ...

  // Unsubscribe when the component dies
  ngOnDestroy() {
    this.subs.unsubscribe();
  }
}

The Array/Add Technique

Example using the .add technique. This is similar to what RxJS supports out of the box.

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

  ...

  this.subs.add(observable$.subscribe(...)); 

  this.subs.add(observable$.subscribe(...)); 

  // Add multiple subscriptions at the same time
  this.subs.add( 
    observable$.subscribe(...),
    anotherObservable$.subscribe(...)
  ); 

  ...

  // Unsubscribe when the component dies
  ngOnDestroy() {
    this.subs.unsubscribe();
  }
}

Issues· 16 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

TypeScript

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言