Currently we show three users in the list, it actually does three time network request, we can verfiy this by console out EA CH Network Request:
var responsestream = startuprequeststream.merge (requestonrefreshstream) = = { Console.log (' Do network request '); return Rx.Observable.fromPromise (Jquery.getjson (requesturl) );
We actually can use the same network request by Sharereplay (1):
var responsestream = startuprequeststream.merge (requestonrefreshstream) = = { Console.log (' Do network request '); return Rx.Observable.fromPromise (Jquery.getjson (Requesturl)); }) . Sharereplay ( 1);
Why replay one? Well, that's because if there happens to be a really late subscriber...let ' s say someone does a setTimeout and doesn ' t sub scribe to the responsestream after a long while. Let ' s say, three seconds or even seconds. Then, the this subscribe would get a replayed response JSON. It won't do-a new network request, but it'll simply replay that same JSON that happened before.
[RxJS] reactive programming-sharing network requests with Sharereplay ()