Skip to content

Commit

Permalink
Handle shared attributes object in hyperscript
Browse files Browse the repository at this point in the history
  • Loading branch information
s-ilya committed Aug 21, 2017
1 parent b59ab50 commit c041eac
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
5 changes: 5 additions & 0 deletions render/hyperscript.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ function hyperscript(selector) {
} else if (typeof attrs !== "object" || attrs.tag != null || Array.isArray(attrs)) {
attrs = {}
start = 1
} else {
attrs = Object.keys(attrs).reduce(function(newAttributes, key) {
newAttributes[key] = attrs[key]
return newAttributes
}, {})
}

if (arguments.length === start + 1) {
Expand Down
9 changes: 9 additions & 0 deletions render/tests/test-hyperscript.js
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,15 @@ o.spec("hyperscript", function() {
o(vnode.children[0].tag).equals("i")
o(vnode.children[1].tag).equals("s")
})
o("handles shared attrs", function() {
var attrs = {a: "b"}

var nodeA = m(".a", attrs)
var nodeB = m(".b", attrs)

o(nodeA.attrs.className).equals("a")
o(nodeB.attrs.className).equals("b")
})
o("handles fragment children without attr unwrapped", function() {
var vnode = m("div", [m("i")], [m("s")])

Expand Down

0 comments on commit c041eac

Please sign in to comment.