fix some attributes not being set properly under vdom#29
fix some attributes not being set properly under vdom#29tswaters wants to merge 1 commit intochoojs:masterfrom
Conversation
Should that be I'm not sure that other implementations aside from virtual-dom use an var h = require('virtual-dom/h')
var hx = require('hyperx')(function (tagName, props, children) {
if (!props.attributes) props.attributes = {}
Object.keys(props).forEach(function (key) {
if (/^data-/.test(key)) props.attributes[key] = props[key]
})
return h(tagName, attr, children)
}) |
Yes... yes it should. This approach in general is a good call. I found that when the change applied to all engines, hypertext promptly blew up. (seems it doesn't like Anyway, I've added the flag as |
238830d to
20e817d
Compare
- enabled by passing {vdom: true} flag to the hyperx contructor options
- fixes data-*, aria-* and style as a string. vdom expects these to be
under an 'attributes' property under props and will gladly ignore them
otherwise
fixes choojs#28
There was a problem hiding this comment.
Was looking for a fix for exactly this (switching view framework from React to something else breaks as styles need to be specified as an object in one, and a string in another), so it would be great if this could be merged.
EDIT - sorry I was only referring to the styles fix, not moving anything into attributes object. What would be best/most generic would be the ability to pass opts.wrapper to hyperx, which then could apply additional wrapping to h before returning the result to hyperx.
|
Any update on this? |
|
I don't think hyperx should add logic specific to a particular virtual dom library. I think substack's custom factory suggestion is a better approach. |
|
fwiw, that's basically what the PR does, but it puts it behind a flag so the library can handle it for users in a consistent manner. If consumers do need to implement this in their own app, a note should probably be added to the readme about lack of For posterity, an implementation that supports var h = require('virtual-dom/h')
var hx = require('hyperx')(function (tagName, props, children) {
if (!props.attributes) props.attributes = {}
Object.keys(props).forEach(function (key) {
if (/^(data|aria)-/.test(key) || (key === 'style' && typeof props[key] === 'string')) {
props.attributes[key] = props[key]
}
})
return h(tagName, attr, children)
}) |
|
I think a note like that in the virtual-dom example section would be great, yes :) |
fixes #28
I tried to keep with the coding convention - hope this is OK.
also, I wasn't able to run the coverage script on windows without manually expanding the glob pattern :( ... there's a few failures when running that, but it's nothing that has been introduced here.