mount mas minimalista pero eficiente

This commit is contained in:
2026-04-08 12:20:15 +02:00
parent 4b5243052b
commit 557bd1428a

19
sw.js
View File

@@ -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) => {