Skip to content

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

@timmywil

Description

@timmywil

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()

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions