The ability to reply to discussions is limited to PRO members. Want to join in the discussion? Click here to subscribe now.

Send new requests from refresh clicks in RxJS

Send new requests from refresh clicks in RxJS

5:07
In this lesson we learn how to fetch new data whenever the refresh button is clicked. This lessons starts to give us a feeling of how is it to develop reactive applications in RxJS.
Watch this lesson now
Avatar
egghead.io

In this lesson we learn how to fetch new data whenever the refresh button is clicked. This lessons starts to give us a feeling of how is it do develop reactive applications in RxJS.

Avatar
Joshua

Why do you need flatMap in the responseStream?

Avatar
Andre

Hi Joshua, if we try to simply map a request URL to a response, we will get a stream of streams, because each response is a stream (since a response always comes asynchronously in the future). With a stream of streams, we can "flatten" it by using mergeAll. So map + mergeAll is what we would need to do. Actually, flatMap is precisely map + mergeAll. That's why we use flatMap.

In reply to Joshua
Avatar
Martin

I think the code is a little bit redundant here or at least it's not clear tom me why the random function is used twice. First in the requestOnRefreshStream and second in the suggestionStreams also. So to easy the code we could go with standard url in the requestORefreshStream and we still have "random" suggestions.

In reply to egghead.io
HEY, QUICK QUESTION!
Joel's Head
Why are we asking?