From 557bd1428abe629f01b5164b2744a673b2083b05 Mon Sep 17 00:00:00 2001 From: natxocc Date: Wed, 8 Apr 2026 12:20:15 +0200 Subject: [PATCH] mount mas minimalista pero eficiente --- sw.js | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/sw.js b/sw.js index 0ee1a9e..0066108 100644 --- a/sw.js +++ b/sw.js @@ -305,21 +305,16 @@ export const Router = (routes) => { }; -export const mount = (rootComponent, target, props = {}) => { - const destination = typeof target === 'string' ? document.querySelector(target) : target; - if (!destination) return; +export const mount = (root, target, props = {}) => { + const container = typeof target === 'string' ? document.querySelector(target) : target; + if (!container) return; - while (destination.firstChild) remove(destination.firstChild); + container.replaceChildren(); - const element = h(rootComponent, props); - destination.appendChild(element); + const el = h(root, props); + container.appendChild(el); - if (element.$context) { - element.$context.mountHooks.forEach(hook => hook()); - element.$context.mountHooks.length = 0; - } - - return () => remove(element); + return () => remove(el); }; export default (target, rootComponent, props) => {