Matt-Esch / virtual-dom

A Virtual DOM and diffing algorithm
MIT License
11.67k stars 777 forks source link

HTML data-* attributes get lost after patch #406

Closed jarmo closed 8 years ago

jarmo commented 8 years ago

patch loses HTML 5 data attributes, because it does apply properties to node like this:

node[propName] = propValue

Correct (?) way would be to use node.setAttribute(propName, propValue) instead although className is a special case.

Or am I missing something?

bendrucker commented 8 years ago

Anything that needs to set using setAttribute (i.e. not a valid DOM property) must be included in attributes (see #405 among others)

jarmo commented 8 years ago

Is this the specification of hyperscript?

I'm using dom2hscript to create hyperscript from DOM elements and it seems that it does not add these properties into attributes:

var div = document.createElement("div")
div.dataset.foo = "bar"
div # <div data-foo="bar"></div>
dom2hscript.parseDOM(div) # "h('DIV',{"data-foo":"bar"},[])"
bendrucker commented 8 years ago

What are you considering the hyperscript spec?

jarmo commented 8 years ago

Okay, let me rephrase my question since I do not know too much about hyperscript - does virtual-dom expect hyperscript to define attributes with dashes like that or does it have to be like that in general? In other words - is there a bug in dom2hscript rather than in virtual-dom?

bendrucker commented 8 years ago

Hyperscript is more of a loose standard than an explicit spec. Most attributes should be camel cased because they are real DOM attributes that the browser will handle, e.g. scrollTop. Anything that's not a native DOM attribute should be set with attributes.

jarmo commented 8 years ago

Thank you for clarifying. I've opened a separate issue under dom2hscript library referencing this issue so we can close this one.