It’s a good idea to destroy observables using a helper class but not recommend to do this way as it causes each class or component to inherit the helper class to just destroy a subscription. If you expect a observer and want to kill it just Do pipe(take(1)) and if you expect a promise like user profile api request use.toPromise() instead of .subscribe(). I say this from experience using to helper method just cause extra code that’s not need. But great Article
A passionate full-stack developer is adept at building robust web applications with expertise in front-end (HTML, CSS, JavaScript, Angular, React) and back-end (Node.js) technologies.
Great article! 👌
I have written a similar article that describes 5 ways to unsubscribe observables and I think you just proposed the 6th! 🚀
[4+1 ways] How to Unsubscribe from Observables in Angular like a 😎
Nikos Anifantis ・ May 26 ・ 7 min read
Good one Nikos !!
Many many thanks Madhu!
Thanks Nikos!
It’s a good idea to destroy observables using a helper class but not recommend to do this way as it causes each class or component to inherit the helper class to just destroy a subscription. If you expect a observer and want to kill it just Do pipe(take(1)) and if you expect a promise like user profile api request use.toPromise() instead of .subscribe(). I say this from experience using to helper method just cause extra code that’s not need. But great Article
I quite like npmjs.com/package/@ngneat/until-de... . I think it's worth a look. I agree though that ComponentStore is fantastic :)
Nice one !!
Sorry I skimmed and missed the subtleties of your approach, that's really nice :)
Thank you :)
Cool! How about the async pipe approach also?
Yes,
asyncis always a great choice for displaying Observable results on a template :)Wow, this is clever. This pattern will reduce a lot of boilerplate from my code, thanks!
Thanks Ankita! I will :)
Hey, Great one! thanks. very useful.
Can you explain why you use ReplaySubject?