From f8247bdba191f26a17d11eba651362977d45345d Mon Sep 17 00:00:00 2001 From: Sam Saccone Date: Sun, 8 Dec 2013 10:37:19 -0500 Subject: [PATCH] retain default options set on a view's constructor --- spec/javascripts/layout.spec.js | 2 +- spec/javascripts/view.spec.js | 10 ++++++++++ src/marionette.view.js | 2 +- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/spec/javascripts/layout.spec.js b/spec/javascripts/layout.spec.js index 40740e8c5c..7697e09ddb 100644 --- a/spec/javascripts/layout.spec.js +++ b/spec/javascripts/layout.spec.js @@ -125,7 +125,7 @@ describe("layout", function(){ }); it("should supply the layout.options to the function when calling it", function(){ - expect(options).toBe(layout.options); + expect(options).toEqual(layout.options); }); it("should build the regions from the returns object literal", function(){ diff --git a/spec/javascripts/view.spec.js b/spec/javascripts/view.spec.js index ab6e9841e1..5264639306 100644 --- a/spec/javascripts/view.spec.js +++ b/spec/javascripts/view.spec.js @@ -132,6 +132,11 @@ describe("base view", function(){ describe("constructing a view with default options", function(){ var view = Marionette.ItemView.extend(); + var presetOptions = Marionette.View.extend({ + options: { + 'lila': 'zoidberg' + } + }); it("should take and store view options", function() { var viewInstance = new view({"Guybrush": "Island"}); @@ -142,6 +147,11 @@ describe("base view", function(){ var viewInstance = new view; expect(typeof(viewInstance.options.Guybrush)).toBe("undefined"); }); + + it("should retain options set on view class", function() { + var viewInstance = new presetOptions; + expect(viewInstance.options.lila).toBe("zoidberg"); + }); }); describe("should expose its options in the constructor", function() { diff --git a/src/marionette.view.js b/src/marionette.view.js index 99836b0fa0..ab31ef0b75 100644 --- a/src/marionette.view.js +++ b/src/marionette.view.js @@ -13,7 +13,7 @@ Marionette.View = Backbone.View.extend({ // this is a backfill since backbone removed the assignment // of this.options // at some point however this may be removed - this.options = options || {}; + this.options = _.extend({}, this.options, options); // parses out the @ui DSL for events this.events = this.normalizeUIKeys(_.result(this, 'events'));