wardbell / subsink

RxJS subscription sink for unsubscribing gracefully in a component

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Just a question: what is benefit against bare Subscription?

stasberkov opened this issue · comments

Without SubSink you can do

subscription = new Subscription();
...
this.subscription.add(subs1$.subscribe(...));
this.subscription.add(subs2$.subscribe(...));
...
this.subscription.unsubscribe();

Can SubSink do it better?

@stasberkov Good question hahaha!!

this.subscription.sink is a lot more stylish you have to admit that!

We use a base class for all our components.
The base class have a protected ngUnsubscribe$ subject that is getting unsubscribed onDestroy.

When we have this we can use the RXJS pipe takaUntil(this.ngUnscubscribe$)

This was discussed at length in #1. I agree with the response from @wardbell

Use it if you like it. Ignore it if you don't. Cheers to all.