Permalink
Browse files

Fix #2044 - `once` events are properly removed after triggering

  • Loading branch information...
caseywebdev committed Dec 28, 2012
1 parent 1cff00a commit c45e3109f76be52195251f0d685770549dd9fdcb
Showing with 10 additions and 1 deletion.
  1. +1 −1 backbone.js
  2. +9 −0 test/events.js
View
@@ -160,7 +160,7 @@
if (callback || context) {
for (j = 0, k = list.length; j < k; j++) {
ev = list[j];
- if ((callback && callback !== (ev.callback._callback || ev.callback)) ||
+ if ((callback && callback !== ev.callback._callback && callback !== ev.callback) ||
(context && context !== ev.context)) {
events.push(ev);
}
View
@@ -364,4 +364,13 @@ $(document).ready(function() {
_.extend({}, Backbone.Events).once('event').trigger('event');
});
+ test("once removes event after running", 1, function() {
+ var obj = {};
+ _.extend(obj, Backbone.Events);
+ obj.once('event', function() {});
+ obj.trigger('event');
+ console.log(obj._events);
+ equal(obj._events['event'].length, 0, 'once should have removed bound event.');
+ });

This comment has been minimized.

Show comment Hide comment
@braddunbar

braddunbar Dec 28, 2012

Collaborator

I agree that the fix above should be added, but I don't think that testing the internals of the implementation is a good strategy. The implementation should be able to change without breaking the tests. Essentially, this fix is an optimization for removing once callbacks, not a change in behavior.

@braddunbar

braddunbar Dec 28, 2012

Collaborator

I agree that the fix above should be added, but I don't think that testing the internals of the implementation is a good strategy. The implementation should be able to change without breaking the tests. Essentially, this fix is an optimization for removing once callbacks, not a change in behavior.

This comment has been minimized.

Show comment Hide comment
@caseywebdev

caseywebdev Dec 28, 2012

Collaborator

Good call.

@caseywebdev

caseywebdev Dec 28, 2012

Collaborator

Good call.

+
});

0 comments on commit c45e310

Please sign in to comment.