"Refresh" observables | Angular Tips and Tricks

  Рет қаралды 39,933

Code With Gio

Code With Gio

Күн бұрын

Пікірлер: 50
@g3cyka
@g3cyka 2 жыл бұрын
Great video! You helped me a lot! Thank you.
@yasinakarsu6088
@yasinakarsu6088 2 жыл бұрын
great explanation, as a beginner it is helped me a lot
@davidr5000
@davidr5000 2 жыл бұрын
Nice video and example. But for production i would probably put the refresh logic inside the api.service because now i need to know the implemantation of the service inside my component which goes against the seperation of concerns principle. Only my two cents as a junior dev 😅
@CodeWithGio
@CodeWithGio 2 жыл бұрын
Hmm thought provoking, I guess you can do that, on the other hand separating refresh from the API service is also 'separation of concerns', i.e api call and refresh logic. Now thinking about it having the third class that manages refresh might be the best option
@laughandtune
@laughandtune 7 ай бұрын
If there are two different components and we are using the same methodology, both the components flicker, after hitting a button in the parent component. Can you please try to implement same methodology, with parent/child components?
@levanloladze4382
@levanloladze4382 Жыл бұрын
love from Georgia ❤❤❤🇬🇪 🇬🇪 🇬🇪 🇬🇪 🇬🇪 🇬🇪
@famigliapaganelli5055
@famigliapaganelli5055 4 жыл бұрын
Great! I spent all day to find a way to refresh observable and finally I found your video! Thank you very much!!! You're great!
@yaminyassin3602
@yaminyassin3602 3 жыл бұрын
You explained this really well 😌 thank you!
@joshuasmith2814
@joshuasmith2814 3 жыл бұрын
Push variable to trigger function... why not just call the function? Having trouble to see how is this not overcomplication and Promise call would be simpler.
@CodeWithGio
@CodeWithGio 3 жыл бұрын
This video is about refreshing the observable, not whether or not promise is better. Also calling function again would only update the template, not other code only subscriptions. Check my separate RxJs series, it would make more sense
@dinesh.m7341
@dinesh.m7341 Жыл бұрын
Thank you 👍
@colinstringer561
@colinstringer561 2 жыл бұрын
I think there's a cleaner approach. I would change the observable in the service into a subject or behaviorsubject. Then inside the addUser() function in the service you can call .next() to add a user to your user list. This way the component will automatically detect changes that are made in the service (which is the whole point of using observables in the first place). With this approach there won't be a need for a refresh observable, and there won't be a need for any manual subscriptions.
@CodeWithGio
@CodeWithGio 2 жыл бұрын
The example is arbitrary. The video is about "refreshing" the observables when you need it, If that need is the result of bad design that's completely different matter
@colinstringer561
@colinstringer561 2 жыл бұрын
​@@CodeWithGio Yeah I guess that's true. I'm relatively new to observables and Angular, so I'm learning the fundamentals still. I don't yet have the insight in what is or isn't possible for each situation. But by watching your video, it makes me wonder, is it possible to have such amazingly clean rxjs design in a project that 'hacky' approaches (no offense) like a refresh-subject aren't necessary?
@CodeWithGio
@CodeWithGio 2 жыл бұрын
Yeah, absolutely, ideally you should have a design where refresh happens implicitly on the pages that need fresh data, how to do that? Well that's a topic of its own
@fundans3982
@fundans3982 3 жыл бұрын
Nice explanation, can you please make the video on rx js operators like switchMap, mergeMap etc.. I like the way you are exploring the concept. Thanks in advance.
@CodeWithGio
@CodeWithGio 3 жыл бұрын
Yeah, absolutely, I'll create several videos about common rxjs operators
@teeratphoowaborwornphimkul3501
@teeratphoowaborwornphimkul3501 3 жыл бұрын
Beautiful Guy .... A lot of benefit for the people
@TheSantivideo
@TheSantivideo 3 жыл бұрын
Amazing video! Just what I needed!
@codingwithelhacen990
@codingwithelhacen990 3 жыл бұрын
I was looking for this! Thanks!!
@pedrogiovanni3408
@pedrogiovanni3408 2 жыл бұрын
Very nice video! I was looking for something like this 👍🏻 for educational purpose I would know if there are other ways to achieve the same result inside the component (no use of service). Thanks in advance
@CodeWithGio
@CodeWithGio 2 жыл бұрын
Technically yes, I haven't thought much about it though. Basic idea is that you have to trigger the observable chain, how you achieve this, is up to you
@kiranvinay7552
@kiranvinay7552 4 жыл бұрын
brother is it a good practise to maintain beahavoirSubject in service an next value whenever data in service(which is obtained from api) changes and we gonna subscribe it in a component where the data is need to be refreshed??? and bw u didnot subscribe that subject why???
@CodeWithGio
@CodeWithGio 4 жыл бұрын
Yes that is another good way to do it, encapsulate all the change logic into a single service and use subjects as public API for your components, once change happens, subject will be updated and components as well. What I've shown in this video is a different approach to achieve the same thing. You can use either one, depending on situation at hand
@kiranvinay7552
@kiranvinay7552 4 жыл бұрын
@@CodeWithGio thnks man u r late but i tried and achieved it !! thnku u brother
@g-l8492
@g-l8492 3 жыл бұрын
Nice :) btw, unsubscribing was missing, didnt fit to this Video maybe but should be done here, no?
@CodeWithGio
@CodeWithGio 3 жыл бұрын
So when using async pipe in the template for some observable, it's not necessary to manually unsubscribe (technically you can't even do that, because async pipe stores the subscription internally and we don't have access to that). If you have explicit subscription i.e obs.subscribe then yes, you need to unsubscribe
@g-l8492
@g-l8492 3 жыл бұрын
@@CodeWithGio oh I didn't know that, good to know 👍
@piotrjarzabek-up9jc
@piotrjarzabek-up9jc Жыл бұрын
very thanks i was looking for solution like this i was not sure :D
@unikgamingyt299
@unikgamingyt299 2 жыл бұрын
Thank you very much for this. I was wondering how to refresh the page and your video popped out. It was very helpful for me. Hopefully will help others too. 😊
@hgatl
@hgatl 2 жыл бұрын
İ loved your approach , Excellent
@SrckyBoi
@SrckyBoi 2 жыл бұрын
Couldn't you just have used ChangeDetectorRef instead?
@CodeWithGio
@CodeWithGio 2 жыл бұрын
ChangeDetectorRef works with Angular change detection i.e dom updates, it has nothing to do with observables
@TravisSomaroo
@TravisSomaroo Жыл бұрын
Hi Gio great video, do you perhaps have GIT repo with this tutorial?
@CodeWithGio
@CodeWithGio Жыл бұрын
Not yet
@baljeetsangrur
@baljeetsangrur 2 жыл бұрын
Thats why people hate angular, Have to write tons of lines to do a simple task. It can be done easily with real API and AJAX.
@CodeWithGio
@CodeWithGio 2 жыл бұрын
You are missing the point, observables and fp scale really well
@skaffen
@skaffen Жыл бұрын
You just don't know how to do it properly.
@pmsanthosh
@pmsanthosh 3 жыл бұрын
Can we do this for a subscription instead of observable
@CodeWithGio
@CodeWithGio 3 жыл бұрын
Do you have any specific example in mind ? I'm not sure what refreshing the subscription means, you subscribe to observable and get subscription. Then you refresh the observable and get new value in subscription
@giorgimerabishvili8194
@giorgimerabishvili8194 4 жыл бұрын
Great video Gio. Keep it up!
@ovuncuzun
@ovuncuzun 3 жыл бұрын
Thank you very much. You mentioned there are many ways to do it, what else are they?
@CodeWithGio
@CodeWithGio 3 жыл бұрын
In reality there is no such thing as "Refreshing" the observable, think of observable like a function, you can't "refresh" the function, but what you can do, is to call that function again, let's say the function returns games list from HTTP call, if you call that function again later, it would "refresh". It's exactly the same with observables. What you do to "refresh" the function ? just call it again, what you do to "refresh" the observable ? just re-subscribe to it, that's essentially what I do in the video. Now there are many ways to re-subscribe it, you can create your own operator and pass down some trigger, you can implement special trigger class with necessary methods, if you use observables in the template, you can have functions that return them and basically call it and assign it to necessary variables. The point is there are as many ways to "refresh" the observable, as there are for calling a function. Hope it helps
@thearyaman123
@thearyaman123 3 жыл бұрын
@@CodeWithGio thank you this was very helpful
@khanhmai4472
@khanhmai4472 3 жыл бұрын
Thank you so much for this tip!
@CodeWithGio
@CodeWithGio 3 жыл бұрын
Glad it helped you, more tips and tricks coming soon
@sumanthdarisi
@sumanthdarisi 4 жыл бұрын
Thanks for the clear video. In my case, I am getting data from an open-source API. How can I refresh my page when new data added to the API son ??? Note: I am not the owner of the API, they don't have post method to accept the data from users like me. Thanks in advance for your response.
@CodeWithGio
@CodeWithGio 4 жыл бұрын
Well in this case you have to get the a notification of some sort that data on API side was changed. Usually APIs support some sort of websocket interface, that gives you such notifications. Once you receive the notification then you can refresh your data. If your API doesn't support such thing, then I think it's not possible to refresh your data, whenever change happens in backend. Another trick you can use, is to query the data with intervals, but this probably will cause some rate limit issues and API might block your requests completely.
@sumanthdarisi
@sumanthdarisi 4 жыл бұрын
@@CodeWithGio Appreciate your response. Unfortunately, this is an open-source API, I don't know if this API has such web socket notification functionality. Regarding, interval query option, it doesn't work my site. Thanks for the response again.
Make your components reactive | Angular Tips and Tricks
11:28
Code With Gio
Рет қаралды 3 М.
Electric Flying Bird with Hanging Wire Automatic for Ceiling Parrot
00:15
Nastya and balloon challenge
00:23
Nastya
Рет қаралды 68 МЛН
mergeMap vs concatMap vs exhaustMap vs switchMap | RxJS Tutorials
28:02
These ARE the Angular tips you are looking for | John Papa
25:05
Complex features made easy with RxJS
36:13
Hasgeek TV
Рет қаралды 59 М.
Top 5 Angular Mistakes - You Must Know Them
10:32
Monsterlessons Academy
Рет қаралды 59 М.
Hot vs Cold Observable in RxJs (2021)
15:06
Decoded Frontend
Рет қаралды 27 М.
I only ever use *these* RxJS operators to code reactively
25:25
Joshua Morony
Рет қаралды 130 М.
Clean way to manage Subscriptions | Angular Tips and Tricks
10:21
Code With Gio
Рет қаралды 18 М.
Top 10 RxJs Operators in Angular [Angular Series]
25:06
David Acosta
Рет қаралды 119 М.