Fix angular-busy promise-compare issues and added UT
Related also to issue https://github.com/cgross/angular-busy/issues/68
In case I change cg-busy unresolved promise with a new unresolved promise - the tracker.reset is not begin called. This is due the use of angular.equals, which doesn't look on "$" fields - so the two above promises looks the same. Because reset is not being called, when the first promise is resolved - the cg-busy overlay is removed, which causes unwanted behaviour (the user still waits for an action, but no overlay).
Therefore, we add to the promise object a random ID, so comparison works correctly. Added also UT that catch this bug, and works after our fix.
Thanks to @barnash for the help in debugging and finding a solution for it.
Looking at the angular-busy code again, actually - I'm not sure what is the need for angular.compare on the promises at all. Meaning - removing my fix and the compare check together, will have the same result (and fix the issue I originally tried to fix).
All the logic is triggered under $watchCollection on the options parameter. Two scenarios I see here:
- The options is a promise, or array of promises. In this case - if the $watchCollection was triggered, the angular.equal will always return true because there is an actual change of the promises.
- The options is an object, with promise or array of promises supplied. In this case - if the $watchCollection was triggered it is either the promise was changed or other key in the object (like the min-duration or templateUrl key). If it was a promise change - we need to call reset anyway. If not - calling reset again seems not to have any effect. It may create more callbacks for delay/min-duration which is a waste, but it doesn't seem to have any effect.
To be on the safe side - I'll keep my fix because if fixes the author original intention - trigger reset only on promise changes..
I've forked this to https://github.com/faceleg/angular-busy-plus. Recommend using that as the development focus until / unless the owner becomes active or brings help on board.