TOP 6 Mistakes in RxJS code

15,411
0
Publicado 2024-06-19
To try everything Brilliant has to offer—free—for a full 30 days, visit brilliant.org/DecodedFrontend.
You’ll also get 20% off an annual premium subscription.

From this video, you will learn the TOP 6 mistakes developers make when writing RxJS code. Watch this video until the end, and you will see how to make your RxJS code more reliable, clear, and performant. If you find this video useful, please share it with your colleagues and friends. Enjoy!

👉 See All Angular Courses - bit.ly/discounted-course-bundle

🕒 Time Codes:
00:00 - Intro
00:00:54 - Project Overview;
00:02:56 - Nested Subscriptions;
00:05:38 - Wrong usage of takeUntil for unsub;
00:07:20 - Manual Subscriptions;
00:09:34 - Observable re-execution;
00:12:20 - Improper usage of distinctUntilChanged();
00:14:46 - Brilliant Sponsorship;
00:15:54 - Side Effects in the wrong place;
00:17:40 - Outro;

🔗 Solution Source Code:
github.com/DMezhenskyi/angular-top-rxjs-mistakes/t…

💡 Short Frontend Snacks (Tips) every week here:
Twitter - twitter.com/DecodedFrontend
Instagram - www.instagram.com/decodedfrontend
LinkedIn - www.linkedin.com/in/dmezhenskyi

This video was sponsored by Brilli

Todos los comentarios (21)
  • @haroldpepete
    i think even angular's creator can learn something from your videos, you're the best
  • One mistake I learned about recently: not using `defer` for `valueChanges/statusChanges` observables of reactive forms. In particular, reactively declared variables outside of any hook or constructor. For example, if you have `value$ = this.form.valueChanges.pipe(startWith(this.form.value), map(.....))` and then in `ngOnInit` do something like `this.form.setValue('initial value here')`, then `value$` will not actually start with `'initial value here'` since that happens at a different time. This can be fixed by wrapping the stream* using RXJS `defer`. That allows `value$` to initialize at a later time when the observable is being subscribed to, and that is after `ngOnInit` runs and sets the value. edit: good video as always, thank you. And nice talk yesterday.
  • @adiscivgin
    Perfect explanation of something that is really needed for angular developers around the globe. Saw those mistakes everywhere. You rock, really.
  • @kaxoonyoe7346
    I think you are sitting in the deepest level of angular , very impressive!
  • @eXpertise7
    You're really good. This is gold. Coming from Angular Dev with 6 year experience.
  • Thank you. Of all those who talk about angular, your videos are the most useful and detailed. I like that you are not afraid to explain some things using source code, it gives a moore deep understanding of the principles of the framework. I have a request: could you consider the microfrontend and the role of angular in it? I think this is a very relevant and interesting topic. For example, it confuses me that in the case of Angular you have to use a custom webpack configuration because it doesn’t seem like the authors themselves approve of this, otherwise they would have added such a feature to Angular themselves.
  • @Dimonina
    Mistake 4. Won't shareReplay(1) keep the subscription active even after component is destroyed? Afair it will. In this case we can use refCount or takeUntilDestroyed BEFORE shareReplay(1).
  • @TibinThomas1993
    Thanks for the content Adding few of my leaning below 1. The use of `debounceTime()`, `delay()`, or any other time-related operators can hinder performance, especially when there are many subscribers. 2. Late subscription to Subjects can be a challenging issue for beginners to identify and debug. 3. `TakeWhile` will unsubscribe from the stream when the specified condition is met.
  • @pierajzan
    I would love to see more angular "mistakes" videos. Through your experience you have seen many bad practices and can explain why they are bad. I hope for such videos :)
  • @orz5516
    common mistakes: 1. Subscriptions inside functions that triggers multiple times (through DOM events like click, hover etc...). 2. Creating multiple subscriptions inside angular life cycle hooks when the observable results are dependent on one another and thus creating race conditions.
  • A very interesting and usefule video! Some of these mistakes I'd made before and my coworkers explained me them. But now I have more systematic and deep understanding of all these bad patterns, so thank you so much:)
  • @amaizingcode
    Great video! I hope you can share more tips like these. I think they can benefit the community a lot. Thanks!
  • @tz2014
    Awesome, it's a always brilliant to learn from you
  • @blueghost512
    Thank you bro. Although I stoped coding in Angular two years ago, such content still useful. specially for a NestJS dev
  • @alexeyn2281
    Great video! Could you give advice how to prorerly split vendor file to chunks?