Skip to content

Dashes in .data() names behavior change #87

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

Closed
dmethvin opened this issue Feb 9, 2015 · 6 comments
Closed

Dashes in .data() names behavior change #87

dmethvin opened this issue Feb 9, 2015 · 6 comments
Assignees
Milestone

Comments

@dmethvin
Copy link
Member

dmethvin commented Feb 9, 2015

We're using camelCase for data names where possible, and only use the dash-name if it exists in the object already. Ideally, API callers should use camelCase for accessing data names rather than dashes. If the caller gets the raw data object they'll see camelCase if they put in dash-name via the API. (Clearly this will need a longer explanation somewhere.)

jquery/jquery#1751
jquery/jquery#2257

@dmethvin
Copy link
Member Author

dmethvin commented Feb 9, 2015

API docs need some variant of this description: jquery/jquery#1751 (comment)

@dmethvin
Copy link
Member Author

dmethvin commented Apr 6, 2015

At this point I'm not sure how to make a non-noisy warning about this. It might just have to be a documentation change.

@gibson042
Copy link
Member

I think this can be done: http://jsfiddle.net/aq992xxb/

The following cases will need warnings:

  • Dashed key in a bulk setter ($el.data({ "dashed-key": … }) does not camelCase before 3.0)
  • Dashed key getter when an exact match key exists in the data object ($el.data()["dashed-key"] = …; $el.data("dashed-key") retrieves the exact match instead of the camelCase before 3.0)
  • Update dashed key when an exact match key exists in the data object ($el.data()["dashed-key"] = …; $el.data("dashed-key", newValue) updates both values instead of just the camelCased one in 2.x)

@dmethvin
Copy link
Member Author

dmethvin commented Apr 8, 2015

We're only talking about breaking changes with regard to migration though. So we only want to give a warning if some old code no longer works. Merely using dashed keys needs to be silent unless mixed with direct data object access where the new representation would be visible?

@gibson042
Copy link
Member

Pretty much, yeah. Access is backwards- incompatible only when the data object includes a dashed key, and that can only happen through a bulk setter call (which itself is one of those warning cases) or direct manipulation.

@dmethvin
Copy link
Member Author

@gibson042 How does this sound? In a call to .data("some-name") the 3.0 behavior is to only look for someName in the data item, even if some-name is set. Migrate can do the probe for some-name and see if it is present in the data object, then return that value instead of someName and warn about it. That's the only case I see that's easy to detect.

@dmethvin dmethvin self-assigned this Mar 23, 2016
dmethvin added a commit to dmethvin/jquery-migrate that referenced this issue Mar 25, 2016
dmethvin added a commit to dmethvin/jquery-migrate that referenced this issue Mar 28, 2016
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

No branches or pull requests

2 participants