Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix #1282 - "all" callback list is retrieved for each event.

  • Loading branch information...
commit c4297e5e2eec66e5b2bbefe3dfa4b9a112199871 1 parent c7a7584
@braddunbar braddunbar authored
Showing with 12 additions and 1 deletion.
  1. +1 −1  backbone.js
  2. +11 −0 test/events.js
View
2  backbone.js
@@ -150,13 +150,13 @@
trigger: function(events) {
var event, node, calls, tail, args, all, rest;
if (!(calls = this._callbacks)) return this;
- all = calls.all;
events = events.split(eventSplitter);
rest = slice.call(arguments, 1);
// For each event, walk through the linked list of callbacks twice,
// first to trigger the event, then to trigger any `"all"` callbacks.
while (event = events.shift()) {
+ all = calls.all;
if (node = calls[event]) {
tail = node.tail;
while ((node = node.next) !== tail) {
View
11 test/events.js
@@ -145,6 +145,17 @@ $(document).ready(function() {
equal(counter, 2, 'unbind does not alter callback list');
});
+ test("#1282 - 'all' callback list is retrieved after each event.", function() {
+ var counter = 0;
+ var obj = _.extend({}, Backbone.Events);
+ var incr = function(){ counter++; };
+ obj.on('x', function() {
+ obj.on('y', incr).on('all', incr);
+ })
+ .trigger('x y');
+ strictEqual(counter, 2);
+ });
+
test("if no callback is provided, `on` is a noop", 0, function() {
_.extend({}, Backbone.Events).bind('test').trigger('test');
});
Please sign in to comment.
Something went wrong with that request. Please try again.