I am currently working on a web application which uses angular 6 as its frontend framework. I am also going to use some api endpoints to get data from server. And here i got stuck, according to angular docs it recommends to use rxjs but i am little bit confused while using rxjs operators.
Answer
Probably if you consider only http calls to APIs, the advantages brought by RxJS vs Promises are not that many. The retry
operator makes it easier to retry when errors occur, maybe managing race conditions is easier using switchMap
, but overall not that much.
The reason is that http calls are a "one shot" thing. You fire 1 call and that 1 call returns just 1 result or errors. Just like Promeses are "one shot" things.
Where RxJS really shines is when you have to deal with streams of events that may have more than 1 emission over time. The Cloud and the DOM are 2 examples of sources of such streams. These are the situations where you can see how RxJS is Promises on steroids.
Here a couple of examples:
No comments:
Post a Comment