Defer splitting namespace until needed

pull/180/head
Matt Kaemmerer 8 years ago
parent 7399632795
commit e1d93dca97

@ -16,7 +16,7 @@ for(var i=0, len = booleanAttrs.length; i < len; i++) {
function updateAttrs(oldVnode, vnode) { function updateAttrs(oldVnode, vnode) {
var key, cur, old, elm = vnode.elm, var key, cur, old, elm = vnode.elm,
oldAttrs = oldVnode.data.attrs, attrs = vnode.data.attrs, namespace; oldAttrs = oldVnode.data.attrs, attrs = vnode.data.attrs, namespaceSplit;
if (!oldAttrs && !attrs) return; if (!oldAttrs && !attrs) return;
oldAttrs = oldAttrs || {}; oldAttrs = oldAttrs || {};
@ -26,16 +26,18 @@ function updateAttrs(oldVnode, vnode) {
for (key in attrs) { for (key in attrs) {
cur = attrs[key]; cur = attrs[key];
old = oldAttrs[key]; old = oldAttrs[key];
namespace = key.split(":")[0];
if (old !== cur) { if (old !== cur) {
if(!cur && booleanAttrsDict[key]) if(!cur && booleanAttrsDict[key])
elm.removeAttribute(key); elm.removeAttribute(key);
else if(key.match(/:/) && NamespaceURIs.hasOwnProperty(namespace)) else {
elm.setAttributeNS(NamespaceURIs[namespace], key, cur); namespaceSplit = key.split(":");
if(namespaceSplit.length > 1 && NamespaceURIs.hasOwnProperty(namespaceSplit[0]))
elm.setAttributeNS(NamespaceURIs[namespaceSplit[0]], key, cur);
else else
elm.setAttribute(key, cur); elm.setAttribute(key, cur);
} }
} }
}
//remove removed attributes //remove removed attributes
// use `in` operator since the previous `for` iteration uses it (.i.e. add even attributes with undefined value) // use `in` operator since the previous `for` iteration uses it (.i.e. add even attributes with undefined value)
// the other option is to remove all attributes with value == undefined // the other option is to remove all attributes with value == undefined

Loading…
Cancel
Save