Skip to content

Commit

Permalink
Return undefined from delegate
Browse files Browse the repository at this point in the history
  • Loading branch information
wyuenho committed Mar 14, 2014
1 parent 4e8caf4 commit ad39972
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
5 changes: 0 additions & 5 deletions backbone.js
Original file line number Diff line number Diff line change
Expand Up @@ -1130,11 +1130,6 @@
// `blur`, and not `change`, `submit`, and `reset` in Internet Explorer.
delegate: function(eventName, selector, listener) {
this.$el.on(eventName + '.delegateEvents' + this.cid, selector, listener);

// Return the listener for easy undelegation with `undelegate`. When
// `delegate` is called with two arguments, `selector` is actually the
// `listener`.
return _.isFunction(selector) ? selector : listener;
},

// Clears all callbacks previously bound to the view by `delegateEvents`.
Expand Down
11 changes: 5 additions & 6 deletions test/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,21 +77,19 @@
equal(counter2, 3);
});

test("delegate", 4, function() {
test("delegate", 2, function() {
var counter1 = 0, counter2 = 0;

var view = new Backbone.View({el: '#testElement'});
view.increment = function(){ counter1++; };
view.$el.on('click', function(){ counter2++; });

var listener1 = view.delegate('click', 'h1', view.increment);
var listener2 = view.delegate('click', view.increment);
view.delegate('click', 'h1', view.increment);
view.delegate('click', view.increment);

view.$('h1').trigger('click');
equal(counter1, 2);
equal(counter2, 1);
strictEqual(listener1, view.increment);
strictEqual(listener2, view.increment);
});

test("delegateEvents allows functions for callbacks", 3, function() {
Expand Down Expand Up @@ -161,7 +159,8 @@

test("undelegate with passed handler", 1, function() {
view = new Backbone.View({el: '#testElement'});
var listener = view.delegate('click', function() { ok(false); });
var listener = function() { ok(false); };
view.delegate('click', listener);
view.delegate('click', function() { ok(true); });
view.undelegate('click', listener);
view.$el.trigger('click');
Expand Down

0 comments on commit ad39972

Please sign in to comment.