all repos — h3 @ b6869379ef47565fa12ec675d21d34c4e918434b

A tiny, extremely minimalist JavaScript microframework.

Improved redrawing algorithm
h3rald h3rald@h3rald.com
Mon, 25 May 2020 17:50:51 +0200
commit

b6869379ef47565fa12ec675d21d34c4e918434b

parent

2e9de06504275c2d54a4bf969e76836bf4abb460

4 files changed, 34 insertions(+), 16 deletions(-)

jump to
M docs/H3_DeveloperGuide.htmdocs/H3_DeveloperGuide.htm

@@ -8044,7 +8044,7 @@ </ul>

</div> <div id="footer"> - <p><span class="copy"></span> Fabio Cevasco &ndash; May 23, 2020</p> + <p><span class="copy"></span> Fabio Cevasco &ndash; 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.jsdocs/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.jsdocs/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.jsh3.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],