Skip to content

Commit

Permalink
h transform properties refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt-Esch committed Dec 21, 2014
1 parent b7e868e commit 79b7040
Showing 1 changed file with 21 additions and 19 deletions.
40 changes: 21 additions & 19 deletions virtual-hyperscript/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,25 +62,7 @@ function h(tagName, properties, children) {
props.value = softSetHook(props.value)
}

var keys = Object.keys(props)
var propName, value
for (var j = 0; j < keys.length; j++) {
propName = keys[j]
value = props[propName]
if (isHook(value)) {
continue
}

// add data-foo support
if (propName.substr(0, 5) === "data-") {
props[propName] = dataSetHook(value)
}

// add ev-foo support
if (propName.substr(0, 3) === "ev-") {
props[propName] = evHook(value)
}
}
transformProperties(props)

if (children !== undefined && children !== null) {
addChild(children, childNodes, tag, props)
Expand Down Expand Up @@ -119,6 +101,26 @@ function addChild(c, childNodes, tag, props) {
}
}

function transformProperties(props) {
for (var propName in props) {
if (props.hasOwnProperty(propName)) {
var value = props[propName]

if (isHook(value)) {
continue
}

if (propName.substr(0, 5) === "data-") {
// add data-foo support
props[propName] = dataSetHook(value)
} else if (propName.substr(0, 3) === "ev-") {
// add ev-foo support
props[propName] = evHook(value)
}
}
}
}

function isChild(x) {
return isVNode(x) || isVText(x) || isWidget(x) || isVThunk(x)
}
Expand Down

0 comments on commit 79b7040

Please sign in to comment.