Improved redrawing algorithm
h3rald h3rald@h3rald.com
Mon, 25 May 2020 17:50:51 +0200
4 files changed,
34 insertions(+),
16 deletions(-)
M
docs/H3_DeveloperGuide.htm
→
docs/H3_DeveloperGuide.htm
@@ -8044,7 +8044,7 @@ </ul>
</div> <div id="footer"> - <p><span class="copy"></span> Fabio Cevasco – May 23, 2020</p> + <p><span class="copy"></span> Fabio Cevasco – May 25, 2020</p> <p><span>Powered by</span> <a href="https://h3rald.com/hastyscribe"><span class="hastyscribe"></span></a></p> </div> </div>
M
docs/example/assets/js/h3.js
→
docs/example/assets/js/h3.js
@@ -442,8 +442,8 @@ // Map positions of oldvnode children in relation to newvnode children
let oldmap = mapChildren(oldvnode, newvnode); let notFoundInOld = newmap.indexOf(-1); let notFoundInNew = oldmap.indexOf(-1); - if (newmap.length === oldmap.length && notFoundInNew >= 0) { - // Something changed + if (equal(newmap, oldmap) && notFoundInNew >= 0) { + // Something changed (some nodes are different at the same position) for (let i = 0; i < newmap.length; i++) { if (newmap[i] === -1 || oldmap[i] === -1) { oldvnode.children[i].redraw({@@ -459,9 +459,15 @@ if (notFoundInNew >= 0) {
const childOfNew = 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 + const childOfOld = oldvnode.children[notFoundInNew]; + if ( + childOfNew && + childOfOld && + childOfOld.type === childOfNew.type && + childOfNew.children.length === 0 && + childOfNew.children.length === 0 + ) { + // Optimization to avoid removing simple nodes of the same type oldvnode.children[notFoundInNew].redraw({ node: node.childNodes[notFoundInNew], vnode: newvnode.children[notFoundInNew],
M
docs/js/h3.js
→
docs/js/h3.js
@@ -442,8 +442,8 @@ // Map positions of oldvnode children in relation to newvnode children
let oldmap = mapChildren(oldvnode, newvnode); let notFoundInOld = newmap.indexOf(-1); let notFoundInNew = oldmap.indexOf(-1); - if (newmap.length === oldmap.length && notFoundInNew >= 0) { - // Something changed + if (equal(newmap, oldmap) && notFoundInNew >= 0) { + // Something changed (some nodes are different at the same position) for (let i = 0; i < newmap.length; i++) { if (newmap[i] === -1 || oldmap[i] === -1) { oldvnode.children[i].redraw({@@ -459,9 +459,15 @@ if (notFoundInNew >= 0) {
const childOfNew = 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 + const childOfOld = oldvnode.children[notFoundInNew]; + if ( + childOfNew && + childOfOld && + childOfOld.type === childOfNew.type && + childOfNew.children.length === 0 && + childOfNew.children.length === 0 + ) { + // Optimization to avoid removing simple nodes of the same type oldvnode.children[notFoundInNew].redraw({ node: node.childNodes[notFoundInNew], vnode: newvnode.children[notFoundInNew],
M
h3.js
→
h3.js
@@ -442,8 +442,8 @@ // Map positions of oldvnode children in relation to newvnode children
let oldmap = mapChildren(oldvnode, newvnode); let notFoundInOld = newmap.indexOf(-1); let notFoundInNew = oldmap.indexOf(-1); - if (newmap.length === oldmap.length && notFoundInNew >= 0) { - // Something changed + if (equal(newmap, oldmap) && notFoundInNew >= 0) { + // Something changed (some nodes are different at the same position) for (let i = 0; i < newmap.length; i++) { if (newmap[i] === -1 || oldmap[i] === -1) { oldvnode.children[i].redraw({@@ -459,9 +459,15 @@ if (notFoundInNew >= 0) {
const childOfNew = 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 + const childOfOld = oldvnode.children[notFoundInNew]; + if ( + childOfNew && + childOfOld && + childOfOld.type === childOfNew.type && + childOfNew.children.length === 0 && + childOfNew.children.length === 0 + ) { + // Optimization to avoid removing simple nodes of the same type oldvnode.children[notFoundInNew].redraw({ node: node.childNodes[notFoundInNew], vnode: newvnode.children[notFoundInNew],