From 0d9b81308ff782dae8dfcd098f0ba21ace0b43a8 Mon Sep 17 00:00:00 2001 From: Andrew Cobby Date: Thu, 2 Jan 2014 22:02:35 +1000 Subject: [PATCH] Trigger Region close event with view that's being closed --- spec/javascripts/region.spec.js | 9 +++++++-- src/marionette.region.js | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/spec/javascripts/region.spec.js b/spec/javascripts/region.spec.js index f32ec7f70f..5fdc295aa2 100644 --- a/spec/javascripts/region.spec.js +++ b/spec/javascripts/region.spec.js @@ -245,7 +245,7 @@ describe("region", function(){ } }); - var myRegion, view, closed, closedContext; + var myRegion, view, closed, closedContext, closedView; beforeEach(function(){ setFixtures("
"); @@ -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; }); @@ -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); }); diff --git a/src/marionette.region.js b/src/marionette.region.js index 4cea54bee4..fcf21f8119 100644 --- a/src/marionette.region.js +++ b/src/marionette.region.js @@ -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; },