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

Region does not re-delegateEvent on previously closed view #654

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 20 additions & 5 deletions spec/javascripts/region.spec.js
Expand Up @@ -33,6 +33,7 @@ describe("region", function(){

view = new MyView();
spyOn(view, "render").andCallThrough();
spyOn(view, "delegateEvents").andCallThrough();

myRegion = new MyRegion();
spyOn(myRegion, "onShow");
Expand All @@ -50,15 +51,19 @@ describe("region", function(){
expect(view.render).toHaveBeenCalled();
});

it("should not call 'delegateEvents' for a view that has not been closed", function(){
expect(view.delegateEvents).not.toHaveBeenCalled();
});

it("should append the rendered HTML to the manager's 'el'", function(){
expect(myRegion.$el).toHaveHtml(view.el);
});

it("shoudl call 'onShow' for the view, after the rendered HTML has been added to the DOM", function(){
it("should call 'onShow' for the view, after the rendered HTML has been added to the DOM", function(){
expect($(view.el)).toHaveClass("onShowClass");
})

it("shoudl call 'onShow' for the region, after the rendered HTML has been added to the DOM", function(){
it("should call 'onShow' for the region, after the rendered HTML has been added to the DOM", function(){
expect(myRegion.onShow).toHaveBeenCalled();
})

Expand Down Expand Up @@ -142,6 +147,7 @@ describe("region", function(){
spyOn(view, "close");
spyOn(myRegion, "open");
spyOn(view, "render");
spyOn(view, "delegateEvents");
myRegion.show(view);
});

Expand All @@ -156,6 +162,10 @@ describe("region", function(){
it("should call 'render' on the view", function(){
expect(view.render).toHaveBeenCalled();
});

it("should not call 'delegateEvents' on the view", function(){
expect(view.delegateEvents).not.toHaveBeenCalled();
});
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need for this change in the commit


describe("when a view is already shown, close, and showing the same one", function(){
Expand All @@ -166,7 +176,7 @@ describe("region", function(){
var MyView = Backbone.Marionette.ItemView.extend({
render: function(){
$(this.el).html("some content");
},
},
open : function() {}
});

Expand All @@ -182,7 +192,8 @@ describe("region", function(){

spyOn(view, "close");
spyOn(myRegion, "open");
spyOn(view, "render")
spyOn(view, "render");
spyOn(view, "delegateEvents");
myRegion.show(view);
});

Expand All @@ -197,6 +208,10 @@ describe("region", function(){
it("should call 'render' on the view", function(){
expect(view.render).toHaveBeenCalled();
});

it("should call 'delegateEvents' on the view", function(){
expect(view.delegateEvents).toHaveBeenCalled();
});
});

describe("when a view is already closed and showing another", function(){
Expand Down Expand Up @@ -412,7 +427,7 @@ describe("region", function(){

MyApp = new Backbone.Marionette.Application();
MyApp.addRegions({
MyRegion: "#region",
MyRegion: "#region",
anotherRegion: "#region2"
});

Expand Down
23 changes: 14 additions & 9 deletions src/marionette.region.js
@@ -1,4 +1,4 @@
// Region
// Region
// ------
//
// Manage the visual regions of your composite application. See
Expand Down Expand Up @@ -53,19 +53,19 @@ _.extend(Marionette.Region, {
}

var selector, RegionType;

// get the selector for the region

if (regionIsString) {
selector = regionConfig;
}
}

if (regionConfig.selector) {
selector = regionConfig.selector;
}

// get the type for the region

if (regionIsType){
RegionType = regionConfig;
}
Expand All @@ -77,7 +77,7 @@ _.extend(Marionette.Region, {
if (regionConfig.regionType) {
RegionType = regionConfig.regionType;
}

// build the region instance
var region = new RegionType({
el: selector
Expand Down Expand Up @@ -132,7 +132,12 @@ _.extend(Marionette.Region.prototype, Backbone.Events, {
if (isDifferentView || isViewClosed) {
this.open(view);
}


if (isViewClosed) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only commit this change, not all the whitespace changes

// this is a view that was closed, events need to be re-delegated
view.delegateEvents();
}

this.currentView = view;

Marionette.triggerMethod.call(this, "show", view);
Expand Down Expand Up @@ -172,8 +177,8 @@ _.extend(Marionette.Region.prototype, Backbone.Events, {
delete this.currentView;
},

// Attach an existing view to the region. This
// will not call `render` or `onShow` for the new view,
// Attach an existing view to the region. This
// will not call `render` or `onShow` for the new view,
// and will not replace the current HTML for the `el`
// of the region.
attachView: function(view){
Expand Down