Handled checked attribute.
h3rald h3rald@h3rald.com
Sun, 03 May 2020 19:06:54 +0200
1 files changed,
17 insertions(+),
12 deletions(-)
jump to
M
h3.js
→
h3.js
@@ -267,6 +267,9 @@ const a = document.createAttribute(attr);
a.value = this.attributes[attr]; node.setAttributeNode(a); } + if ([false, true].includes(this.attributes.checked)) { + node.checked = this.attributes.checked; + } }); // Event Listeners Object.keys(this.eventListeners).forEach((event) => {@@ -364,13 +367,17 @@ }
// Attributes if (!equal(oldvnode.attributes, newvnode.attributes)) { Object.keys(oldvnode.attributes).forEach((a) => { - if (!newvnode.attributes[a]) { - node.removeAttribute(a); - } else if ( - newvnode.attributes[a] && - newvnode.attributes[a] !== oldvnode.attributes[a] - ) { - node.setAttribute(a, newvnode.attributes[a]); + if ([false, true].includes(newvnode.attributes.checked)) { + node.checked = newvnode.attributes.checked; + } else { + if (!newvnode.attributes[a]) { + node.removeAttribute(a); + } else if ( + newvnode.attributes[a] && + newvnode.attributes[a] !== oldvnode.attributes[a] + ) { + node.setAttribute(a, newvnode.attributes[a]); + } } }); Object.keys(newvnode.attributes).forEach((a) => {@@ -414,7 +421,6 @@ found = true;
break; } } - // node not in oldvnode if (!found) { map.push(-1); }@@ -446,19 +452,18 @@ newvnode.children.length > notFoundInNew &&
newvnode.children[notFoundInNew]; const childofOld = oldvnode.children[notFoundInNew]; if (childOfNew && childofOld && childofOld.type === childOfNew.type) { - // optimization to avoid removing nodes of the same type + // Optimization to avoid removing nodes of the same type oldvnode.children[notFoundInNew].redraw({ node: node.childNodes[notFoundInNew], vnode: newvnode.children[notFoundInNew], }); } else { - // while there are children not found in newvnode, remove them and re-check + // While there are children not found in newvnode, remove them and re-check node.removeChild(node.childNodes[notFoundInNew]); oldvnode.children.splice(notFoundInNew, 1); } } else { - //(notFoundInOld >= 0) { - // while there are children not found in oldvnode, add them and re-check + // While there are children not found in oldvnode, add them and re-check node.insertBefore( newvnode.children[notFoundInOld].render(), node.childNodes[notFoundInOld]