question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Check whether RxJs subscriptions in Angular component are complete or unsubscribed

See original GitHub issue

Is 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:closed
  • Created 4 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
cartantcommented, Apr 26, 2019

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 to subscribe and then assigning something to this - 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 an async pipe. When I did use Angular, I only ever used OnPush change detection and that plays nicely with the async 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.

1reaction
cartantcommented, Apr 23, 2019

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found