Merge next into optimize-events
This commit is contained in:
commit
5209071011
7 changed files with 99 additions and 47 deletions
|
|
@ -6,6 +6,11 @@ var selectorParser = /(?:(^|#|\.)([^#\.\[\]]+))|(\[(.+?)(?:\s*=\s*("|'|)((?:\\["
|
|||
var selectorCache = {}
|
||||
var hasOwn = {}.hasOwnProperty
|
||||
|
||||
function isEmpty(object) {
|
||||
for (var key in object) if (hasOwn.call(object, key)) return false
|
||||
return true
|
||||
}
|
||||
|
||||
function compileSelector(selector) {
|
||||
var match, tag = "div", classes = [], attrs = {}
|
||||
while (match = selectorParser.exec(selector)) {
|
||||
|
|
@ -28,6 +33,18 @@ function execSelector(state, attrs, children) {
|
|||
var hasAttrs = false, childList, text
|
||||
var className = attrs.className || attrs.class
|
||||
|
||||
if (!isEmpty(state.attrs) && !isEmpty(attrs)) {
|
||||
var newAttrs = {}
|
||||
|
||||
for(var key in attrs) {
|
||||
if (hasOwn.call(attrs, key)) {
|
||||
newAttrs[key] = attrs[key]
|
||||
}
|
||||
}
|
||||
|
||||
attrs = newAttrs
|
||||
}
|
||||
|
||||
for (var key in state.attrs) {
|
||||
if (hasOwn.call(state.attrs, key)) {
|
||||
attrs[key] = state.attrs[key]
|
||||
|
|
|
|||
|
|
@ -638,7 +638,8 @@ module.exports = function($window) {
|
|||
updateNodes(dom, dom.vnodes, Vnode.normalizeChildren(vnodes), false, hooks, null, namespace === "http://www.w3.org/1999/xhtml" ? undefined : namespace)
|
||||
dom.vnodes = vnodes
|
||||
for (var i = 0; i < hooks.length; i++) hooks[i]()
|
||||
if ($doc.activeElement !== active) active.focus()
|
||||
// document.activeElement can return null in IE https://developer.mozilla.org/en-US/docs/Web/API/Document/activeElement
|
||||
if (active != null && $doc.activeElement !== active) active.focus()
|
||||
}
|
||||
|
||||
return {render: render, setEventCallback: setEventCallback}
|
||||
|
|
|
|||
|
|
@ -507,6 +507,23 @@ 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(nodeA.attrs.a).equals("b")
|
||||
|
||||
o(nodeB.attrs.className).equals("b")
|
||||
o(nodeB.attrs.a).equals("b")
|
||||
})
|
||||
o("doesnt modify passed attributes object", function() {
|
||||
var attrs = {a: "b"}
|
||||
m(".a", attrs)
|
||||
o(attrs).deepEquals({a: "b"})
|
||||
})
|
||||
o("handles fragment children without attr unwrapped", function() {
|
||||
var vnode = m("div", [m("i")], [m("s")])
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue