Skip to content

Commit

Permalink
Merge pull request #860 from bitovi/851-reverse
Browse files Browse the repository at this point in the history
Emit events for can.List.prototype.reverse
  • Loading branch information
daffl committed Apr 7, 2014
2 parents dd166e2 + 913db14 commit e7640b5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
5 changes: 4 additions & 1 deletion list/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -871,7 +871,10 @@ steal("can/util", "can/map", function (can, Map) {
* list === reversedList; // true
* @codeend
*/
reverse: [].reverse,
reverse: function() {
var list = can.makeArray([].reverse.call(this));
this.replace(list);
},

/**
* @function can.List.prototype.slice slice
Expand Down
13 changes: 13 additions & 0 deletions list/list_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,17 @@ steal("can/util", "can/list", "can/test", function () {
l.splice(0, 1);
ok(!l.attr(0), 'all props are removed');
});

test('reverse triggers add/remove events (#851)', function() {
expect(6);
var l = new can.List([1,2,3]);

l.bind('change', function() { ok(true, 'change should be called'); });
l.bind('set', function() { ok(false, 'set should not be called'); });
l.bind('add', function() { ok(true, 'add called'); });
l.bind('remove', function() { ok(true, 'remove called'); });
l.bind('length', function() { ok(true, 'length should be called'); });

l.reverse();
});
});

0 comments on commit e7640b5

Please sign in to comment.