Basically, in case the request response is not received yet, do not issue a new (network) request. Wait for the one which is still pending.
Here's a test for this (kind of extreme) use-case:
it('Should wait if there is a Promise pending and should NOT fire another one',done=>{letnetworkRequestsCount=0;constrepo=newSuperRepo({storage: 'LOCAL_VARIABLE',name: 'test',outOfDateAfter: 1000,// 1 secondrequest: ()=>{networkRequestsCount++;returnnewPromise(resolve=>{clock.tick(10*1000);resolve('whatever');});}});repo.initSyncer().then(()=>{expect(networkRequestsCount).to.equal(1);clock.tick(15*1000);expect(networkRequestsCount).to.equal(2);}).then(done,done);});
While working on a side project powered by SuperRepo, I had to check when my repository data was lastFetched.
I figure out that I can't do that easily with the methods provided by SuperRepo. Therefore, the enhancement I plan is to return lastFetched and isInvalid params in the getDataUpToDateStatus() method.
While working on a side project powered by SuperRepo, I had to refresh a chart each time my data is synced successfully.
Therefore, I plan to enhance the initSyncer() method with an option to pass an (optional) callback which will be executed every time when the data is synced successfully.