Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't ignore default options in the view constructor when it's a function. #819

Merged
merged 1 commit into from
Jan 10, 2014
Merged

Don't ignore default options in the view constructor when it's a function. #819

merged 1 commit into from
Jan 10, 2014

Conversation

seansfkelley
Copy link

Fixed #818

@@ -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 = _.extend({}, this.options, options);
this.options = _.extend({}, _.result(this, 'options'), options);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@seansfkelley if we are going to add this which I am not opposed to let's also add a conditional _.isFunction on the options passed into the constructor

@seansfkelley
Copy link
Author

That shouldn't be necessary; the interaction between extend and result should handle all three cases of nonexistent, literal, and function (added a test to make sure of this). I can add a test for the nonexistent case, if you'd like.

@samccone
Copy link
Member

@seansfkelley

_.extend({}, function(){return {bar: 1}}) === {}

All i am saying is if we are going to allow functional evaluation, might as well do this then

this.options = _.extend({}, _.result(this, 'options'), _.isFunction(options) ? options.call(this) : options );

@seansfkelley
Copy link
Author

Right, I just realized I'd misread after I stepped away from the computer! We could do that as well, however, I was merely trying to recreate the old Backbone behavior, which notably did not treat specially a function as argument. Has there been a use case for this? Personally I have not seen one, and as I use Backbone 1.0 right now I would err on the side of simply mimicking it.

@samccone
Copy link
Member

Fair comment, I think that allowing for the functional evaluation of the options param could be handy in some cases.

@jasonenglish
Copy link

+1

@seansfkelley
Copy link
Author

@samccone Done and good catch.

@cobbweb
Copy link
Member

cobbweb commented Jan 2, 2014

👍

@samccone
Copy link
Member

samccone commented Jan 2, 2014

1 little thing before a merge, the format of this commit message is not according to the ideal way.

see http://git-scm.com/book/ch5-2.html

Once that is fixed we can merge :shipit:

Fixes an issue where Marionette would not respect a function that returned
an object as the `options` field of a View.
cobbweb added a commit that referenced this pull request Jan 10, 2014
Don't ignore default options in the view constructor when it's a function.
@cobbweb cobbweb merged commit 581f1f9 into marionettejs:master Jan 10, 2014
@seansfkelley seansfkelley deleted the options-as-fn branch January 10, 2014 21:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

If predefined options are a function, they are ignored
4 participants