Skip to content

Commit

Permalink
Re-added this.options to the View base class
Browse files Browse the repository at this point in the history
In Backbone v1.1.0, one of the breaking changes was to no longer
automatically assign the options hash passed into Backbone.View to
this.options.

This change caused things to break in lots of places where
[Marionette.getOption](https://github.com/marionettejs/backbone.marionette/blob/master/src/marionette.helpers.js#L27)
was called since it looked for things to automatically be added to
`view.options`.

Example:
[Marionette.View#getTemplate](https://github.com/marionettejs/backbone.marionette/blob/master/src/marionette.view.js#L26)
will work if you define the template through extend, but will fail if
template is passed as an option.

This change re-adds the assignment to `this.options` in the
Marionette.View constructor. This effectively solves the problem, though
perhaps a more extensive solution that doesn't try to knee-jerk re-add
previous behavior would be preferable.

Links:
    [Changelog](http://backbonejs.org/#changelog)
    [The code removed](jashkenas/backbone@1.0.0...1.1.0#diff-0d56d0d310de7ff18b3cef9c2f8f75dcL1086)
    [View initialization 1.0.0](https://github.com/jashkenas/backbone/blob/1.0.0/backbone.js#L983)
    [View initialization 1.1.0](https://github.com/jashkenas/backbone/blob/1.1.0/backbone.js#L986)
  • Loading branch information
jmorrell authored and samccone committed Oct 12, 2013
1 parent 01d902a commit f3c632d
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/marionette.view.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@
// The core view type that other Marionette views extend from.
Marionette.View = Backbone.View.extend({

constructor: function(){
constructor: function(options){
_.bindAll(this, "render");

var args = Array.prototype.slice.apply(arguments);
Backbone.View.prototype.constructor.apply(this, args);
this.options = options;

Marionette.MonitorDOMRefresh(this);
this.listenTo(this, "show", this.onShowCalled, this);
},

// import the "triggerMethod" to trigger events with corresponding
// methods if the method exists
// methods if the method exists
triggerMethod: Marionette.triggerMethod,

// Get the template for this view
Expand Down Expand Up @@ -77,7 +78,7 @@ Marionette.View = Backbone.View.extend({
return triggerEvents;
},

// Overriding Backbone.View's delegateEvents to handle
// Overriding Backbone.View's delegateEvents to handle
// the `triggers`, `modelEvents`, and `collectionEvents` configuration
delegateEvents: function(events){
this._delegateDOMEvents(events);
Expand Down

0 comments on commit f3c632d

Please sign in to comment.