Skip to content

Commit

Permalink
Merge pull request #834 from cobbweb/trigger-region-close-event-with-…
Browse files Browse the repository at this point in the history
…view

Trigger Region close event with view that's being closed
  • Loading branch information
samccone committed Jan 8, 2014
2 parents 02fa4b1 + 0d9b813 commit 04021d2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 7 additions & 2 deletions spec/javascripts/region.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ describe("region", function(){
}
});

var myRegion, view, closed, closedContext;
var myRegion, view, closed, closedContext, closedView;

beforeEach(function(){
setFixtures("<div id='region'></div>");
Expand All @@ -256,7 +256,8 @@ describe("region", function(){
spyOn(view, "remove");

myRegion = new MyRegion();
myRegion.on("close", function(){
myRegion.on("close", function(view){
closedView = view;
closed = true;
closedContext = this;
});
Expand All @@ -269,6 +270,10 @@ describe("region", function(){
expect(closed).toBeTruthy();
});

it("should trigger a close event with the view that's being closed", function(){
expect(closedView).toBe(view);
});

it("should set 'this' to the manager, from the close event", function(){
expect(closedContext).toBe(myRegion);
});
Expand Down
2 changes: 1 addition & 1 deletion src/marionette.region.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ _.extend(Marionette.Region.prototype, Backbone.Events, {
if (view.close) { view.close(); }
else if (view.remove) { view.remove(); }

Marionette.triggerMethod.call(this, "close");
Marionette.triggerMethod.call(this, "close", view);

delete this.currentView;
},
Expand Down

0 comments on commit 04021d2

Please sign in to comment.