Skip to content

Commit

Permalink
Unbind collection and model events for behaviors
Browse files Browse the repository at this point in the history
  • Loading branch information
samccone committed Apr 18, 2014
1 parent 2d9ad15 commit c68c1ab
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
19 changes: 19 additions & 0 deletions spec/javascripts/behaviors.spec.js
Expand Up @@ -413,6 +413,25 @@ describe("Behaviors", function(){
expect(collectionSpy).toHaveBeenCalledOn(testBehavior);
});

it("should unbind model events on view undelegate", function() {
v = new V({
model: m
});

v.undelegateEvents();
m.set("foo", "doge");
expect(fooChangedSpy).not.toHaveBeenCalled();
});

it("should unbind collection events on view undelegate", function() {
v = new CV({
collection: c
});

v.undelegateEvents();
c.reset();
expect(collectionSpy).not.toHaveBeenCalled();
});
});

describe("behavior trigger calls", function() {
Expand Down
4 changes: 2 additions & 2 deletions src/marionette.behaviors.js
Expand Up @@ -96,8 +96,8 @@ Marionette.Behaviors = (function(Marionette, _) {
undelegateEvents.apply(this, args);

_.each(behaviors, function(b) {
Marionette.unbindEntityEvents(this, this.model, Marionette.getOption(b, "modelEvents"));
Marionette.unbindEntityEvents(this, this.collection, Marionette.getOption(b, "collectionEvents"));
Marionette.unbindEntityEvents(b, this.model, Marionette.getOption(b, "modelEvents"));
Marionette.unbindEntityEvents(b, this.collection, Marionette.getOption(b, "collectionEvents"));
}, this);
},

Expand Down

0 comments on commit c68c1ab

Please sign in to comment.