Skip to content

Commit

Permalink
Merge pull request #811 from marionettejs/sjs/fix-default-options
Browse files Browse the repository at this point in the history
retain default options set on a view's constructor
  • Loading branch information
samccone committed Dec 9, 2013
2 parents 3289b58 + f8247bd commit 5a498d2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion spec/javascripts/layout.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(){
Expand Down
10 changes: 10 additions & 0 deletions spec/javascripts/view.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"});
Expand All @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion src/marionette.view.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down

0 comments on commit 5a498d2

Please sign in to comment.