From 888be6701e0f29e2290b5a5429763e2a65384798 Mon Sep 17 00:00:00 2001 From: Derick Bailey Date: Tue, 13 Aug 2013 21:10:47 -0500 Subject: [PATCH] fixed bug that prevented default regionType from being used. fixes #674 --- changelog.md | 1 + spec/javascripts/layout.spec.js | 15 ++++++++------- src/marionette.layout.js | 3 ++- src/marionette.region.js | 1 + 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/changelog.md b/changelog.md index ccd8f7195e..39cc88dcea 100644 --- a/changelog.md +++ b/changelog.md @@ -7,6 +7,7 @@ * Layout * Will properly attach regions if the layout's `close` method was called prior to `render` * Calling `.addRegions` will correctly modify the layout instance' region list instead of the prototype's + * Fixed bug that prevented default `regionType` from being used * CompositeView * The `itemViewContainer` can be supplied in the constructor function options diff --git a/spec/javascripts/layout.spec.js b/spec/javascripts/layout.spec.js index 254e9e11da..797cadb615 100644 --- a/spec/javascripts/layout.spec.js +++ b/spec/javascripts/layout.spec.js @@ -83,13 +83,6 @@ describe("layout", function(){ layoutManager = new LayoutCustomRegion }); - it("should instantiate the default regionManager if specified", function() { - expect(layoutManager).toHaveOwnProperty("regionThree"); - expect(layoutManager.regionThree).toBeInstanceOf(Marionette.Region); - expect(layoutManager).toHaveOwnProperty("regionThree"); - expect(layoutManager.regionThree).toBeInstanceOf(Marionette.Region); - }); - it("should instantiate specific regions with custom regions if speficied", function() { expect(layoutManager).toHaveOwnProperty("regionOne"); expect(layoutManager.regionOne).toBeInstanceOf(CustomRegion1); @@ -97,11 +90,19 @@ describe("layout", function(){ expect(layoutManager.regionTwo).toBeInstanceOf(CustomRegion2); }); + it("should instantiate the default regionManager if specified", function() { + expect(layoutManager).toHaveOwnProperty("regionThree"); + expect(layoutManager.regionThree).toBeInstanceOf(CustomRegion1); + expect(layoutManager).toHaveOwnProperty("regionFour"); + expect(layoutManager.regionThree).toBeInstanceOf(CustomRegion1); + }); + it("should instantiate marionette regions is no regionType is specified", function() { var layoutManagerNoDefault = new LayoutNoDefaultRegion(); expect(layoutManagerNoDefault).toHaveOwnProperty("regionTwo"); expect(layoutManagerNoDefault.regionTwo).toBeInstanceOf(Backbone.Marionette.Region); }); + }); describe("when regions are defined as a function", function(){ diff --git a/src/marionette.layout.js b/src/marionette.layout.js index a49e9d516c..ba061dc7e2 100644 --- a/src/marionette.layout.js +++ b/src/marionette.layout.js @@ -60,7 +60,7 @@ Marionette.Layout = Marionette.ItemView.extend({ addRegion: function(name, definition){ var regions = {}; regions[name] = definition; - return this.addRegions(regions)[name]; + return this._buildRegions(regions)[name]; }, // Add multiple regions as a {name: definition, name2: def2} object literal @@ -80,6 +80,7 @@ Marionette.Layout = Marionette.ItemView.extend({ var that = this; var defaults = { + regionType: Marionette.getOption(this, "regionType"), parentEl: function(){ return that.$el; } }; diff --git a/src/marionette.region.js b/src/marionette.region.js index d4bc301920..0b9acb84da 100644 --- a/src/marionette.region.js +++ b/src/marionette.region.js @@ -42,6 +42,7 @@ _.extend(Marionette.Region, { // ``` // buildRegion: function(regionConfig, defaultRegionType){ + var regionIsString = (typeof regionConfig === "string"); var regionSelectorIsString = (typeof regionConfig.selector === "string"); var regionTypeIsUndefined = (typeof regionConfig.regionType === "undefined");