mount mas minimalista pero eficiente
This commit is contained in:
19
sw.js
19
sw.js
@@ -305,21 +305,16 @@ export const Router = (routes) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
export const mount = (rootComponent, target, props = {}) => {
|
export const mount = (root, target, props = {}) => {
|
||||||
const destination = typeof target === 'string' ? document.querySelector(target) : target;
|
const container = typeof target === 'string' ? document.querySelector(target) : target;
|
||||||
if (!destination) return;
|
if (!container) return;
|
||||||
|
|
||||||
while (destination.firstChild) remove(destination.firstChild);
|
container.replaceChildren();
|
||||||
|
|
||||||
const element = h(rootComponent, props);
|
const el = h(root, props);
|
||||||
destination.appendChild(element);
|
container.appendChild(el);
|
||||||
|
|
||||||
if (element.$context) {
|
return () => remove(el);
|
||||||
element.$context.mountHooks.forEach(hook => hook());
|
|
||||||
element.$context.mountHooks.length = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return () => remove(element);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default (target, rootComponent, props) => {
|
export default (target, rootComponent, props) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user