Possible improvement to AngularJS orderBy.js #14881
Description
As best I understand, the orderBy.js file was improved in Angular version 1.5.7 to deal with "tiebreakers" using the getComparisonObject function:
"NOTE: We are adding an extra tieBreaker
value based on the element's index."
But I also noticed that the doComparison function which "compares" the values, uses the "compare" function defined under the orderByFilter function. Since the orderByFilter function can use a developer supplied comparison function (which would probably not be aware of the comparison tiebreaker code), would it not be better to have the doComparison function written as this:
function doComparison(v1, v2) {
for (var i = 0, ii = predicates.length; i < ii; i++) {
var result = compare(v1.predicateValues[i], v2.predicateValues[i]);
if (result) {
return result * predicates[i].descending * descending;
}
}
return defaultCompare(v1.tieBreaker, v2.tieBreaker) * descending;
}
...so that the tiebreaker feature is always available regardless of whether or not the developer knew about it.
Current behavior:
Would ingnore the tieBreaker code from getComparisonObject function if the developer supplies his/her own comparison function.
Expected behavior:
Although the use case where this makes a difference may be small, adding the above change would always force the "tieBreaker" code to work where applicable. The downside might be upexpected results from developers not aware of the new "tieBreaker" comparison feature when upgrading to this version of AngularJS.
Angular version 1.5.7 is the first version I noticed the code for "tieBreaker" and should be browser independent, ref. file:
https://github.com/angular/angular.js/blob/master/src/ng/filter/orderBy.js