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

Data: align data accessors with the ultimate "Embrace HTML5" direction #2257

Closed
timmywil opened this Issue May 4, 2015 · 3 comments

Comments

Projects
None yet
2 participants
@timmywil
Member

timmywil commented May 4, 2015

camelCasing in .data() has always been problematic. Our attempts to work around camelCasing whenever possible has always caused problems. We've decided to just always camelCase. Not only will our implementation align with the dataset spec, but it makes everything a lot simpler.

I've made a separate issue because #1751 is not broad enough in scope. It only pertains to keys with dashes and digits, which will also be fixed, but in a separate commit.

The solution as @gibson042 laid out in this comment, is this...

assert.equal( jQuery("<div>").data({ "a-b": 1 }).data( "a-b", 2 ).data( "a-b" ), 2 )

And per #1515 (comment) , we want the "Embrace HTML5" option:

  • camelCase data-* attributes into the data object on first access
  • set only camelCase key on .data( key, val ) (setter)
  • camelCase all the added keys on .data( obj ) (bulk setter)
  • look for only camelCase key on .data( key ) (getter)
  • ignore direct manipulation from operations on .data()

@timmywil timmywil self-assigned this May 4, 2015

@timmywil timmywil added this to the 3.0.0 milestone May 4, 2015

@timmywil timmywil closed this in 0e79098 May 4, 2015

timmywil added a commit that referenced this issue May 4, 2015

Data: always camelCase keys in .data()
- This effectively implements our "Embrace HTML5" option
- Related: http://goo.gl/GcQAtn

Fixes gh-2257
@rwaldron

This comment has been minimized.

Show comment
Hide comment
@rwaldron

rwaldron May 4, 2015

Member

I thought I had posted a question when I was mobile this morning, but I guess it didn't go through...

There is no mention (maybe there is, and I missed it?) of this use case:

jQuery("<div>").data({ "a-b": 1 }).data(); // => { "a-b": 1}

Which is definitely broken now, but if that was intentional (which is fine, I guess), then it needs to be made really clear in the docs. Undoubtedly, there is code that expects to be able to serialize and deserialize that data without jQuery screwing with it.

Member

rwaldron commented May 4, 2015

I thought I had posted a question when I was mobile this morning, but I guess it didn't go through...

There is no mention (maybe there is, and I missed it?) of this use case:

jQuery("<div>").data({ "a-b": 1 }).data(); // => { "a-b": 1}

Which is definitely broken now, but if that was intentional (which is fine, I guess), then it needs to be made really clear in the docs. Undoubtedly, there is code that expects to be able to serialize and deserialize that data without jQuery screwing with it.

@timmywil

This comment has been minimized.

Show comment
Hide comment
@timmywil

timmywil May 4, 2015

Member

jQuery("<div>").data({ "a-b": 1 }).data();

Right, we have intentionally broken this case. We will be covering this in the migrate plugin and docs.

Member

timmywil commented May 4, 2015

jQuery("<div>").data({ "a-b": 1 }).data();

Right, we have intentionally broken this case. We will be covering this in the migrate plugin and docs.

@timmywil

This comment has been minimized.

Show comment
Hide comment
@timmywil

timmywil May 4, 2015

Member

That said, jQuery("<div>").data({ "a-b": 1 }).data("a-b") === 1 still works.

Member

timmywil commented May 4, 2015

That said, jQuery("<div>").data({ "a-b": 1 }).data("a-b") === 1 still works.

@mgol mgol referenced this issue Jun 21, 2015

Closed

.data() bug? #2416

@lock lock bot locked as resolved and limited conversation to collaborators Jun 19, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.