4 ms·
Regarding observables, specifically the ones from HttpClient, i always just do a .toPromise(), and use async/await. My rule of thumb is that if i expect a strea
by spyke112 6y ago
Regarding observables, specifically the ones from HttpClient, i always just do a .toPromise(), and use async/await. My rule of thumb is that if i expect a stream of events use observables, but if it's a one of call, like a http request really is, then i use promises. If i need to memoize the data from the request, i do it in a service, and call through that.
- modernlearner 6y agoJust ran into this when building a component to display and filter data. It was starting to turn into a monster when trying to use Rx.js and in the end, the code was simpler to understand with multiple for loops and forEach and map/filter calls. I ended up with a service that doesn't rely on observables.
- nobleach 6y agoNot to mention, easier to test. I had a branch of my code where I had finally figured out how to reliably test the stream/observable variant, but it was just an ugly mess.