Adding "expected" requests
Wes,
First off, thanks so much for this great Angular work. I'm using the component in a large-scale angular project and it has been outstanding. Thank you!
I wanted to get your opinion on a common occurrence in more data loading situations. Say you need to fetch 2 things, and then fetch 2 more based on the outcome of the first two fetches (not unlikely in a REST environment). The loading bar will jump back and forth—looking like it completes only to jump back to the beginning when the second set of requests are made. This makes sense technically since angular (and therefore the loading bar) don't know anything about the second 2 requests until they're actually made. But the developer knows about them, and therefore there might be a better way to handle these situations.
I started looking at a way to address this situation and wanted to get your feedback. In my forked repo, I added the ability to pass in a loadingBarShouldExpect parameter on the $http configuration object. This would tell the loading bar to "expect" additional requests in the future. So a loadingBarShouldExpect: 4 parameter would tell the loading bar "this is the first of 4 requests." This allows the same situation described above to appear as a single load event instead of two sets of events back-to-back.
You can see a diff of my fork and your repo. Most of the changes were used to piece together a demo which loads 100 sets of weather data synchronously as one load event (not a great example, but it shows the added functionality). The few changes to the actual source are shown in the last file.
Let me know what you think and whether there's a better way to go about this.
Thanks again, -Nate
+1
I would like to use this feature in my projects - this solution is simple and covers many common cases.
I also added a pull request.
It would be cool to pass the loading bar a promise which would kick off start() and then call complete() when the promise resolves. This would be a lot easier way for complex interactions, like this, to have one overarching loading bar.
@joshperry, that solution would be great for situations where you have 3 requests and then 2 of those requests fire 2 more. But we have situations where one request starts, then completes and kicks off another request, which completes, and then kicks of another request. Since at those points "all" requests are "done" I think you'd still have a bouncing loading bar.