Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Possible improvement to AngularJS orderBy.js #14881

Closed
angular-indonesia/angular.js
#30
@OpenSiteMobile

Description

@OpenSiteMobile

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions