Check whether RxJs subscriptions in Angular component are complete or unsubscribed
See original GitHub issueIs there a way to validate that all RxJs subscriptions are either complete or unsubscribed by the end of the life cycle of Angular component (when ngOnDestroy is called)?
My understanding is that rxjs-tslint-rules
doesn’t support it at the moment. However, I’d like to see your take on
- whether it is possible? and
- is
rxjs-tslint-rules
the right tool for that?
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
How to debug on whether observable is unsubscribe
You can have a subscription and check closed parameter. let subscription = observable.subscribe(() => {}) if (!subscription.closed) ...
Read more >Best Practices for Managing RxJS Subscriptions - This Dot Labs
Essentially, subscription management revolves around knowing when to complete or unsubscribe from an Observable, to prevent incorrect code from ...
Read more >Unsubscribing in Angular, the right way | by Ashwin Sathian
Absolutely. Granted, your observables and subscriptions will work just fine even if you don't with the whole unsubscribing business. To the untrained eye, ......
Read more >6 Ways to Unsubscribe from Observables in Angular
In this post, I'll review the different ways you can unsubscribe from Observables in Angular apps. The Downside to Observable Subscription.
Read more >When should I unsubscribe my Subscriptions in Angular?
A fundamental aspect of observables is that when they complete, any subscriptions are automatically unsubscribed. As such, if you know an ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I don’t use Angular much, these days, but I talk often with developers who do.
rxjs-prefer-async-pipe
is not a rule that I’ve ever used. There are rules in the package that enforce different opinions.I think it’s more than just subscriptions, though. What would you be doing in
this.http.get(url).subscribe(...)
? I often see people doing this sort of thing, putting a slab of imperative code in the function passed tosubscribe
and then assigning something tothis
- to be picked up by change detection.IMO, that’s all rather horrid. And it would be better implemented as a composed observable - using
map
, etc. to transform the reponse - and that observable could be used with anasync
pipe. When I did use Angular, I only ever usedOnPush
change detection and that plays nicely with theasync
pipe.So I think it’s more than just subscriptions. It’s about implementing components in a manner that as declarative a possible. And with
OnPush
change detection rather than the ‘magic’ stuff that, IMO, should never have been brought over from AngularJS.BTW, I’ve made a note of your question, as I think it would be a great feature to add to the DevTools and - hopefully - it will be fairly straightforward.