all repos — h3 @ a5d734df7b9a47f8582b475bb7373d5dd69e5395

A tiny, extremely minimalist JavaScript microframework.

$onrender now executed every time a node is added to the DOM.
h3rald h3rald@h3rald.com
Thu, 04 Jun 2020 17:22:48 +0200
commit

a5d734df7b9a47f8582b475bb7373d5dd69e5395

parent

09c7b2541c8b63decfea9c0105825e0be6d8e498

1 files changed, 5 insertions(+), 6 deletions(-)

jump to
M h3.jsh3.js

@@ -59,7 +59,6 @@ }

return checkProperties(obj1, obj2); // && checkProperties(obj2, obj1); }; -let $onrenderCallbacks = []; const selectorRegex = /^([a-z][a-z0-9:_=-]*)(#[a-z0-9:_=-]+)?(\.[^ ]+)*$/i; // Virtual Node Implementation with HyperScript-like syntax

@@ -302,11 +301,11 @@ // Children

this.children.forEach((c) => { const cnode = c.render(); node.appendChild(cnode); + c.$onrender && c.$onrender(cnode); }); if (this.$html) { node.innerHTML = this.$html; } - this.$onrender && $onrenderCallbacks.push(() => this.$onrender(node)); return node; }

@@ -324,6 +323,7 @@ oldvnode !== newvnode)

) { const renderedNode = newvnode.render(); node.parentNode.replaceChild(renderedNode, node); + newvnode.$onrender && newvnode.$onrender(renderedNode); oldvnode.from(newvnode); return; }

@@ -471,7 +471,9 @@ break;

case -2: // add node oldvnode.children.push(newvnode.children[count]); - node.appendChild(newvnode.children[count].render()); + const renderedNode = newvnode.children[count].render(); + node.appendChild(renderedNode); + newvnode.children[count].$onrender && newvnode.children[count].$onrender(renderedNode); breakFor = true; break; case -3:

@@ -581,7 +583,6 @@ }

async start() { const processPath = async (data) => { - $onrenderCallbacks = []; const oldRoute = this.route; const fragment = (data &&

@@ -639,8 +640,6 @@ }

const vnode = newRouteComponent(newRouteComponent.state); const node = vnode.render(); this.element.appendChild(node); - $onrenderCallbacks.forEach((cbk) => cbk()); - $onrenderCallbacks = []; this.setRedraw(vnode, newRouteComponent.state); window.scrollTo(0, 0); this.store.dispatch("$redraw");