diff --git a/render/hyperscript.js b/render/hyperscript.js index 26ff753e3..3c9e5b239 100644 --- a/render/hyperscript.js +++ b/render/hyperscript.js @@ -36,24 +36,23 @@ function execSelector(state, vnode) { var className = hasClass ? attrs.class : attrs.className vnode.tag = state.tag - vnode.attrs = {} - if (!isEmpty(state.attrs) && !isEmpty(attrs)) { + if (!isEmpty(state.attrs)) { var newAttrs = {} for (var key in attrs) { if (hasOwn.call(attrs, key)) newAttrs[key] = attrs[key] } - attrs = newAttrs - } + vnode.attrs = newAttrs - for (var key in state.attrs) { - if (hasOwn.call(state.attrs, key) && key !== "className" && !hasOwn.call(attrs, key)){ - attrs[key] = state.attrs[key] + for (var key in state.attrs) { + if (hasOwn.call(state.attrs, key) && key !== "className" && !hasOwn.call(vnode.attrs, key)) { + vnode.attrs[key] = state.attrs[key] + } } } - if (className != null || state.attrs.className != null) attrs.className = + if (className != null || state.attrs.className != null) vnode.attrs.className = className != null ? state.attrs.className != null ? String(state.attrs.className) + " " + String(className) @@ -62,14 +61,7 @@ function execSelector(state, vnode) { ? state.attrs.className : null - if (hasClass) attrs.class = null - - for (var key in attrs) { - if (hasOwn.call(attrs, key) && key !== "key") { - vnode.attrs = attrs - break - } - } + if (hasClass) vnode.attrs.class = null return vnode } diff --git a/render/tests/test-hyperscript.js b/render/tests/test-hyperscript.js index 59751f44a..f688ffd4d 100644 --- a/render/tests/test-hyperscript.js +++ b/render/tests/test-hyperscript.js @@ -271,7 +271,7 @@ o.spec("hyperscript", function() { var vnode = m("div", {key:"a"}) o(vnode.tag).equals("div") - o(vnode.attrs).deepEquals({}) + o(vnode.attrs).deepEquals({key:"a"}) o(vnode.key).equals("a") }) o("handles many attrs", function() { @@ -343,7 +343,7 @@ o.spec("hyperscript", function() { var vnode = m("custom-element", {key:"a"}) o(vnode.tag).equals("custom-element") - o(vnode.attrs).deepEquals({}) + o(vnode.attrs).deepEquals({key:"a"}) o(vnode.key).equals("a") }) o("handles many attrs", function() {