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.
Why do you need flatMap in the responseStream?
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.
OMG please update to RXJS 6, took so long for me to find how to use merge :'( for those who are like me (I use node-fetch):
var responseStream = merge(startupRequestStream, requestOnRefreshStream). pipe( flatMap(requestUrl => from(fetch(requestUrl).then(res => res.json())) ) );