Skip to content

Commit

Permalink
included descending option in private _sort
Browse files Browse the repository at this point in the history
  • Loading branch information
rishabhm committed Jul 17, 2013
1 parent 4e7bef5 commit 26d8652
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
12 changes: 10 additions & 2 deletions src/app/js/model-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,7 @@ Y.ModelList = Y.extend(ModelList, Y.Base, {
`reset` event.
@param {Boolean} [options.silent=false] If `true`, no `reset` event will
be fired.
@param {Boolean} [options.descending=false] If `true`, sorts in descending order
@chainable
**/
sort: function (options) {
Expand Down Expand Up @@ -1123,11 +1124,18 @@ Y.ModelList = Y.extend(ModelList, Y.Base, {
@param {Model} a First model to compare.
@param {Model} b Second model to compare.
@param {Object} [options] Options passed from `sort()` function.
@return {Number} `-1` if _a_ is less than _b_, `0` if equal, `1` if greater.
@param {Boolean} [options.descending=false] If `true`, sorts in descending order
@return {Number} `-1` if _a_ is less than _b_, `0` if equal, `1` if greater (for ascending).
@protected
**/
_sort: function (a, b, options) {
return this._compare(this.comparator(a), this.comparator(b));
var result = this._compare(this.comparator(a), this.comparator(b));

if (!result) {
return result;
}

return options && options.descending ? -result : result;
},

// -- Event Handlers -------------------------------------------------------
Expand Down
10 changes: 0 additions & 10 deletions src/app/tests/unit/assets/model-list-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -867,16 +867,6 @@ modelListSuite.add(new Y.Test.Case({
return model.get('foo');
};

list._sort = function (a, b, options) {
var result = this._compare(this.comparator(a), this.comparator(b));

if (!result) {
return result;
}

return options && options.descending ? -result : result;
};

Assert.areSame(list, list.sort({descending:true}), 'sort() should be chainable');
ArrayAssert.itemsAreSame(['z', 'y', 'x', 'a'], list.get('foo'));

Expand Down

0 comments on commit 26d8652

Please sign in to comment.