Skip to content

Commit 5a498d2

Browse files
committed
Merge pull request #811 from marionettejs/sjs/fix-default-options
retain default options set on a view's constructor
2 parents 3289b58 + f8247bd commit 5a498d2

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

spec/javascripts/layout.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ describe("layout", function(){
125125
});
126126

127127
it("should supply the layout.options to the function when calling it", function(){
128-
expect(options).toBe(layout.options);
128+
expect(options).toEqual(layout.options);
129129
});
130130

131131
it("should build the regions from the returns object literal", function(){

spec/javascripts/view.spec.js

+10
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,11 @@ describe("base view", function(){
132132

133133
describe("constructing a view with default options", function(){
134134
var view = Marionette.ItemView.extend();
135+
var presetOptions = Marionette.View.extend({
136+
options: {
137+
'lila': 'zoidberg'
138+
}
139+
});
135140

136141
it("should take and store view options", function() {
137142
var viewInstance = new view({"Guybrush": "Island"});
@@ -142,6 +147,11 @@ describe("base view", function(){
142147
var viewInstance = new view;
143148
expect(typeof(viewInstance.options.Guybrush)).toBe("undefined");
144149
});
150+
151+
it("should retain options set on view class", function() {
152+
var viewInstance = new presetOptions;
153+
expect(viewInstance.options.lila).toBe("zoidberg");
154+
});
145155
});
146156

147157
describe("should expose its options in the constructor", function() {

src/marionette.view.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Marionette.View = Backbone.View.extend({
1313
// this is a backfill since backbone removed the assignment
1414
// of this.options
1515
// at some point however this may be removed
16-
this.options = options || {};
16+
this.options = _.extend({}, this.options, options);
1717

1818
// parses out the @ui DSL for events
1919
this.events = this.normalizeUIKeys(_.result(this, 'events'));

0 commit comments

Comments
 (0)