RxJS Scan Operator - How to Manage the State

  Рет қаралды 13,007

Decoded Frontend

Decoded Frontend

Күн бұрын

Пікірлер: 87
@DecodedFrontend
@DecodedFrontend 8 ай бұрын
Follow me on other Social Media where I share short tips about Angular: Twitter - twitter.com/DecodedFrontend Instagram - instagram.com/decodedfrontend LinkedIn - www.linkedin.com/in/dmezhenskyi
@TheDomork
@TheDomork 8 ай бұрын
I love the way you explain. You use the pure angular code and show a simple example for the non-trivial topic. Keep it on and have a nice and sunny day ;)
@DecodedFrontend
@DecodedFrontend 8 ай бұрын
Thank you for this feedback :) I glad to know that it was clear.
@EmilioDegiovanni
@EmilioDegiovanni 8 ай бұрын
Invaluable content, dude!! We never finish learning new things about RxJS
@DecodedFrontend
@DecodedFrontend 8 ай бұрын
oh yeah... RxJS is the thing you can learn forever :D Thank you for your feedback :)
8 ай бұрын
This is a really smart and elegant solution! thanks for that mate!
@rembautimes8808
@rembautimes8808 8 ай бұрын
Thanks Dmytro, I really like the way how the handler function is defined outside the stream logic making it easy to build very complex time based flows.
@DecodedFrontend
@DecodedFrontend 8 ай бұрын
Thank you for the comment :) Yep, I also like this pattern 😊
@emilsirbu236
@emilsirbu236 8 ай бұрын
How always a super valuable content! Man, you are in your mission, and we become better developers! Thanks Dmitro!
@DecodedFrontend
@DecodedFrontend 8 ай бұрын
I am happy to hear that! Thank you for your feedback 🙌🏻
@message59
@message59 6 ай бұрын
thank you so much for all the great content :) you have a great way of explaining things 👏🏼
@vt9988
@vt9988 6 ай бұрын
Great Video thanks a lot. I would love to see how you explain the ngrx state management
@cryptoptiker
@cryptoptiker 4 ай бұрын
Perfect content as allways. thank you dimi
@TheOdin96
@TheOdin96 8 ай бұрын
Dmytro, you are the man! 2 days ago I bought your course about hacking angular interview to revise some material before technical phase of interview. Today guy told me on a call that in his eyes he would guess that I have about 10 years of exp. Love you, keep it up
@DecodedFrontend
@DecodedFrontend 8 ай бұрын
Thank you for your feedback and I am very proud and happy of you :) Good luck with your new job!
@dmytrotokarev
@dmytrotokarev 8 ай бұрын
As always very clearly and useful. Thanks!
@DecodedFrontend
@DecodedFrontend 8 ай бұрын
My pleasure! glad it was helpful ;)
@KamelJabber1
@KamelJabber1 8 ай бұрын
Excellent topic and presentation!
@DecodedFrontend
@DecodedFrontend 8 ай бұрын
Thank you!
@NoName-1337
@NoName-1337 8 ай бұрын
I use this pattern for myself with some more stuff for some time. It’s great for async reactivity. As always, a great video. Thank you.
@DecodedFrontend
@DecodedFrontend 8 ай бұрын
Thank you so much for the comment. For me, this pattern worked also quite well 👍 If you experienced any issues with it, I would be happy to hear the use cases.
@NoName-1337
@NoName-1337 8 ай бұрын
@DecodedFrontend The only issue is that it can become a bit bloated, so some functions (such as the handler functions you've implemented) are necessary. The most common use cases involve HTTP calls to the REST API. This pattern can initialize the scan state with the first subscription (toSignal). Data manipulation (CRUD operations) can be handled with subjects and switchMap, by merging them as you have done. ShareReplay can be handy too. If you need an example, just let me know.
@DecodedFrontend
@DecodedFrontend 8 ай бұрын
@@NoName-1337 Hi! Thank you so much for the detailed answer. I think I've got the general idea, but if you already have an example that can be quickly crafted without any significant effort, it would be perfect :)
@NoName-1337
@NoName-1337 8 ай бұрын
@@DecodedFrontend I have sent you an email.
@ugochukwuumerie6378
@ugochukwuumerie6378 8 ай бұрын
Thank you, super useful, learnt a ton from this.
@DecodedFrontend
@DecodedFrontend 8 ай бұрын
❤️
@gagiksimonyan3782
@gagiksimonyan3782 8 ай бұрын
Another useful video from Dmytro) always glad to see notifications from your channel)
@DecodedFrontend
@DecodedFrontend 8 ай бұрын
Thanks, Gagik!
@AmarSingh-uw1db
@AmarSingh-uw1db 8 ай бұрын
Gratitude for such valuable knowledge ❤❤❤
@DecodedFrontend
@DecodedFrontend 8 ай бұрын
Thank you :)
@bancamilleri1546
@bancamilleri1546 7 ай бұрын
Got to love some good old currying. I'd love to see more videos on more advanced usage of RxJS and how to tie together Signals nicely :)
@vladimirv.443
@vladimirv.443 8 ай бұрын
Useful video, thanks! but the first case is more clearly and understandable + you have direct access to state
@DecodedFrontend
@DecodedFrontend 8 ай бұрын
Hey! Thanks for the comment. Yep, as I mentioned in the video, it seems a simpler solution at the beginning. However, it might become harder to manage especially if you have multiple sources over time update the state and resolution of the potential concurrency easier to resolve in rxjs using switchMap's, etc
@loko1944
@loko1944 8 ай бұрын
Not the solution I would use very often but I m a big fun of learning new things by examples like this. Perfect to know what is possible when it will be needed. Keep it going. Maybe some kind of cheat sheet with tricks like this would be helpful for people
@dasvas9383
@dasvas9383 2 ай бұрын
Спасибо, Дима, как всегда круто)
@timurbirgalin4704
@timurbirgalin4704 8 ай бұрын
Thank you for the video! That was really interesting and useful! When I started to work with Angular at my first job, it took me about four months to fully understand how to manage state and async events well:) Besides it was hard due to lack of good information about Angular. And I was so happy when I found your channel!
@maximermoshin393
@maximermoshin393 8 ай бұрын
Thanks for sharing knowledge. You are always the best)
@DecodedFrontend
@DecodedFrontend 8 ай бұрын
Thanks you :)
@matiasbpg
@matiasbpg 8 ай бұрын
I loved the map to function pattern
@DecodedFrontend
@DecodedFrontend 8 ай бұрын
Me too :) Thank you for the comment!
@popastefan6542
@popastefan6542 8 ай бұрын
Could we see the comparison of this state management solution using rxjs operators to the one using signals? I bet the signals one is way more straightforward
@pedrofernandes2005
@pedrofernandes2005 8 ай бұрын
Thanks for another great video! This is actually very clever and useful.
@genyklemberg
@genyklemberg 8 ай бұрын
Really nice approach. Should one add this video as reference to the code added to the project?)
@aleksandrm3466
@aleksandrm3466 8 ай бұрын
Дякую, чудовий приклад.
@DecodedFrontend
@DecodedFrontend 8 ай бұрын
Радий це чути! Дякую за коментар 🙌🏻
@andreykositskiy649
@andreykositskiy649 8 ай бұрын
Привіт. Дякую за твою роботу. Твій канал краще що я бачив по Ангуляру. Можеш порадити книжки які тобі допомогли в розвитку.
@haroldpepete
@haroldpepete 8 ай бұрын
great video, thanks, i would like to see a video about angular query, the counterpart of react-query and maybe something about rx-angular/state
@DecodedFrontend
@DecodedFrontend 8 ай бұрын
Thank you :) your request is clear and taken into consideration👍
@enverusta7811
@enverusta7811 7 ай бұрын
It was really helpful!
@denisgandzii1551
@denisgandzii1551 8 ай бұрын
Dmytro, I think will be nice to receive from you something like short news about front end and in particular everything regarding angular. I would really appreciate. And big thank for what you are doing.
@hansschenker
@hansschenker 8 ай бұрын
the accumulatorHandler is a reducer function, rename it to something like '...reducer' would help. This is Redux style programming in Rxjs, state is reduced by reducers inside scan operator.
@DecodedFrontend
@DecodedFrontend 8 ай бұрын
Yes, you're right. Actually, in the initial draft I had a direct reference to the reducer but eventually decided to go with more familiar 'handler' which would be familiar also for those who isn't familiar with reducer concept :)
@hansschenker
@hansschenker 8 ай бұрын
@@DecodedFrontend ...handler creates the association to an EventHandler, but here you do not handle an Event, you run a state change function which is basically a reducer function. In my opinion it is important as a trainer or teacher to use the most appropriate terms to help the interested user for future understandings. The slogan on the Rxjs official website:'Think of RxJS as Lodash for events' is merley a marketing slogan and does confuse users more than it helps!
@emanuelzhupa
@emanuelzhupa 8 ай бұрын
Great stuff, much needed 🎉🎉
@DecodedFrontend
@DecodedFrontend 8 ай бұрын
Thanks for your feedback, Emanuel!
@sergiim5601
@sergiim5601 7 ай бұрын
Great content, as always
@jeffnikelson5824
@jeffnikelson5824 8 ай бұрын
Expected you to show a signals approach at the end
@DecodedFrontend
@DecodedFrontend 8 ай бұрын
Hey 👋🏻, thanks for the comment. In my opinion, The only part where Signals would be justified in this case is using toSignal() instead of using async pipe, but I think it is too trivial to spend viewers' time on this :)
@dat.nguyenquoc
@dat.nguyenquoc 7 ай бұрын
Thank you very much!!!!
@alphamarouanadiallo8238
@alphamarouanadiallo8238 8 ай бұрын
Thanks you again, always top👌👍
@DecodedFrontend
@DecodedFrontend 8 ай бұрын
Thank you too!
@johncerpa3782
@johncerpa3782 8 ай бұрын
Great video
@oriel-elkabets
@oriel-elkabets 8 ай бұрын
Hi Dmytro, thanks for the video! I noticed that you used the spread operator to update the state of the array. I know that people often use it when updating reference values in signals, and I've seen other programmers do it this way. The question is: wouldn't it be better to simply use push to add the value to the existing array and return the same array? I understand that in signals, we must return a new array so that the signal emits the new value, and computed and effects react to it. However, in the case of using RxJS, I think it would work even without creating a new array. So why use it? I'm aware of the methodology of immutable values, but is it worth copying the whole array for this? Is it optimized in some way, such that there is no difference between this and push? I would love to hear your thoughts on this.
@codeSurvivor
@codeSurvivor 8 ай бұрын
Nice video, thanks a lot Dmytro! I completely agree with you regarding the usage of RxJS. From my point of view, I don't see currently that signals using effects if as good or powerful to manage async events. For reactive data management, signals is for me incredibly easier to use and powerful compared to RxJS, though. I think that a combination of both will be the way to go, at least for now. Also I have a question, I've seen in your videos that you navigate to Angular source code just form vscode. I guess you did some kind of inclusion of the Angular source in tsconfig.json or similar, but I cannot find out how to do it. Could you give me some hints? I find it very good for learning to read Angular source, and I'd like to be able to do it as easily as possible
@DecodedFrontend
@DecodedFrontend 8 ай бұрын
Hey 👋🏻 thanks for your feedback and your questions. Yes, the combination might work quite well (in my opinion) because none of those two can completely replace each other completely:) Regarding the source code navigation. I don’t have any tools for that and do it manually by switching to another VS CODE instance with the source code opened. This is just a result of post production processing where I cut the part where I am switching :)
@codeSurvivor
@codeSurvivor 8 ай бұрын
@@DecodedFrontend All right! Thanks! Good video editing! :-D
@anhquande
@anhquande 7 ай бұрын
"scan" operator can be considered as a reactive version of "reduce()" function
@enverusta7811
@enverusta7811 7 ай бұрын
Since we might need to use those handlers in other lists too, I implemented them in a more generic way like this: ```function removeHandlerFn(indexToRemove: number) { return (state: T[]): T[] => state.filter((_element, index) => index !== indexToRemove); } function resetHandlerFn(event: void) { return (state: T[]): T[] => []; } function accumulatorHandlerFn(value: T) { return (state: T[]): T[] => [...state, value]; } function scanHandlerFn(state: T[], stateHandlerFn: (state: T[]) => T[]) { return stateHandlerFn(state); }``` Also used them like this: ```ages$: Observable = merge( this.reset$.pipe(map(resetHandlerFn)), this.remove$.pipe(map(removeHandlerFn)), this.debouncedAge$.pipe(map(accumulatorHandlerFn)) ).pipe(scan(scanHandlerFn, []));```
@Melfice575
@Melfice575 8 ай бұрын
beautiful
@raji8527
@raji8527 8 ай бұрын
YOu aer the best!!!!
@TheSysmat
@TheSysmat 8 ай бұрын
Nice
@beodan9219
@beodan9219 8 ай бұрын
magic :)
@anandu06
@anandu06 8 ай бұрын
Could you please put the course in Udemy , it will be helpful ❤
@deadlyecho
@deadlyecho 8 ай бұрын
Where were you man, missed your spicy vids 😂
@radvilardian740
@radvilardian740 8 ай бұрын
rxjs is not going anywhere
@DecodedFrontend
@DecodedFrontend 8 ай бұрын
Yep! 👍🏻
@arnauddusseldorp928
@arnauddusseldorp928 8 ай бұрын
Great video, but what happens when you subscribe with a second async to the stream. Eg to show a list of dots in a table. Then there are two states.
@radvilardian740
@radvilardian740 8 ай бұрын
@@arnauddusseldorp928 if 2 streams, then u need to handle them separately, or use some operators like takeWhile and takeUntil explicitly.
@DecodedFrontend
@DecodedFrontend 8 ай бұрын
@@arnauddusseldorp928 thanks for your question :) In this case, the second subscriber will have its own state, which might differ from the 1st one. If you need to share the state, you have to use the operator shareReply(1) after the scan(), which will share the state among subscribers.
@ExploringCodeCrafter
@ExploringCodeCrafter 8 ай бұрын
Nices Video
@DecodedFrontend
@DecodedFrontend 8 ай бұрын
Thanks :)
@anastasiia6513
@anastasiia6513 8 ай бұрын
👍👍👍👍👍👍👍👍👍
@artstar991
@artstar991 8 ай бұрын
Monster
TOP 6 Mistakes in RxJS code
18:35
Decoded Frontend
Рет қаралды 25 М.
How To Make Angular Code More Reusable
19:14
Decoded Frontend
Рет қаралды 32 М.
Жездуха 42-серия
29:26
Million Show
Рет қаралды 2,6 МЛН
Their Boat Engine Fell Off
0:13
Newsflare
Рет қаралды 15 МЛН
I Sent a Subscriber to Disneyland
0:27
MrBeast
Рет қаралды 104 МЛН
Глеб Михеев - Как RxJS разделил мой мир на до и после
49:43
HolyJS — конференция для JavaScript‑разработчиков
Рет қаралды 26 М.
I only ever use *these* RxJS operators to code reactively
25:25
Joshua Morony
Рет қаралды 138 М.
Angular Resource API - Everything You Have To Know (so far)
27:58
Decoded Frontend
Рет қаралды 21 М.
First look at Signals in Angular
18:43
Decoded Frontend
Рет қаралды 47 М.
Input Signals in Angular 17.1 - How To Use & Test
14:34
Decoded Frontend
Рет қаралды 32 М.
TOP 5 Angular Interview Questions and Answers (for experienced, 2020)
21:50
RxJS Crash Course
58:14
Laith Academy
Рет қаралды 97 М.
How to Do 90% of What Plugins Do (With Just Vim)
1:14:03
thoughtbot
Рет қаралды 916 М.
LinkedSignal in Angular 19: The Gem We Were Missing
14:05
Decoded Frontend
Рет қаралды 1,6 М.
Жездуха 42-серия
29:26
Million Show
Рет қаралды 2,6 МЛН