From fc148fdbcc9726cd3c2e48f863b5c5fe12944ecb Mon Sep 17 00:00:00 2001 From: natxocc Date: Wed, 8 Apr 2026 11:51:40 +0200 Subject: [PATCH] Add mount --- sw.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/sw.js b/sw.js index c350d64..1d14954 100644 --- a/sw.js +++ b/sw.js @@ -295,6 +295,23 @@ export const Router = (routes) => { }); }; +export const mount = (root, target, props = {}) => { + const dest = typeof target === 'string' ? document.querySelector(target) : target; + if (!dest) return; + + while (dest.firstChild) remove(dest.firstChild); + + const el = h(root, props); + dest.appendChild(el); + + if (el.$c) { + el.$c.m.forEach(f => f()); + el.$c.m.length = 0; + } + + return () => remove(el); +}; + export default (target, root, props) => { const el = h(root, props); target.appendChild(el);