Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trigger Region close event with view that's being closed #834

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Trigger Region close event with view that's being closed
  • Loading branch information
Andrew Cobby committed Jan 2, 2014
commit 0d9b81308ff782dae8dfcd098f0ba21ace0b43a8
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