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

Add setAttributes for View #4128

Closed
wants to merge 1 commit into from

Conversation

paulfalgout
Copy link
Collaborator

Users may decide to set className, id, or attributes with a function such that the values can change based on the view's state or model.

In general the user is expected to update these values manually once the element is set. It isn't terribly hard to manage className or other attributes directly, but there is a little bit of logic regarding className and id overriding the attributes hash.

This simplifies answering how to update the el's attributes after initialization.

@@ -297,8 +297,8 @@
assert.expect(2);
var View = Backbone.View.extend({
attributes: {
'id': 'id',
'class': 'class'
id: 'id',
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

These changes to the quotes here fix a linter warning

@blikblum
Copy link

Maybe rename to updateAttributes ?

@akre54
Copy link
Collaborator

akre54 commented Mar 20, 2017

I don't love that this changes the method signature of setAttributes. What if instead we allowed both setAttributes(attrs) and setAttributes(), checking if an attrs object was passed in and then falling back to the old behavior if not?

Admittedly I've never had a use case for either, but I can see arguments both ways.

@paulfalgout
Copy link
Collaborator Author

Yeah I was on the fence about that very issue originally having one function and renaming _setAttributes.

If setAttributes handles both signatures should we keep_setAttributes?

@akre54
Copy link
Collaborator

akre54 commented Mar 21, 2017 via email

Users may decide to set className, id, or attributes with a function such that the values can change based on the view's state or model.

In general the user is expected to update these values manually once the element is set.  It isn't terribly hard to manage className or other attributes directly, but there is a little bit of logic regarding className and id overriding the attributes hash.

This simplifies answering how to update the el's attributes after initialization.
@paulfalgout
Copy link
Collaborator Author

Alright updated.

TBH I've never really needed this before either.. but I recently consulted on a project doing a lot of filling in attributes from an endpoint that configures the views. The data isn't super consistent and the logic they were using to handle it was intense (certainly unnecessarily) when really all they wanted to do was re-run what was happening initially. Easy enough to implement myself, but I think they would have avoided this had their been the method available.

Won't be heart broken either way, but it seems reasonable to me.

@akre54
Copy link
Collaborator

akre54 commented Mar 21, 2017

So I'm gonna be a weak close on this. It's easy enough to write your own plugin / base view if you really need it, and no sense adding complexity to the API for the folks that don't.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants