[render/hyperscript] have the attrs take precedence over the selector, improve class normalization

fix #1773
fix #2172
This commit is contained in:
Pierre-Yves Gérardy 2018-06-02 23:09:50 +02:00 committed by Pierre-Yves Gérardy
parent 1a87cc44cd
commit 92b22fe8e6
2 changed files with 35 additions and 35 deletions

View file

@ -31,7 +31,8 @@ function compileSelector(selector) {
function execSelector(state, attrs, children) {
var hasAttrs = false, childList, text
var className = attrs.className || attrs.class
var classAttr = hasOwn.call(attrs, "class") ? "class" : "className"
var className = attrs[classAttr]
if (!isEmpty(state.attrs) && !isEmpty(attrs)) {
var newAttrs = {}
@ -46,21 +47,18 @@ function execSelector(state, attrs, children) {
}
for (var key in state.attrs) {
if (hasOwn.call(state.attrs, key)) {
if (hasOwn.call(state.attrs, key) && key !== "className" && !hasOwn.call(attrs, key)){
attrs[key] = state.attrs[key]
}
}
if (className !== undefined) {
if (attrs.class !== undefined) {
attrs.class = undefined
attrs.className = className
}
if (state.attrs.className != null) {
attrs.className = state.attrs.className + " " + className
}
}
if (className || state.attrs.className) attrs[classAttr] =
className
? state.attrs.className
? state.attrs.className + " " + className
: className
: state.attrs.className
? state.attrs.className
: null
for (var key in attrs) {
if (hasOwn.call(attrs, key) && key !== "key") {
@ -75,7 +73,7 @@ function execSelector(state, attrs, children) {
childList = children
}
return Vnode(state.tag, attrs.key, hasAttrs ? attrs : undefined, childList, text)
return Vnode(state.tag, attrs.key, hasAttrs ? attrs : null, childList, text)
}
function hyperscript(selector) {