Actualizar sigpro_work.js

This commit is contained in:
2026-04-07 17:30:26 +02:00
parent 7483700681
commit 1716b0c80c

View File

@@ -251,19 +251,43 @@ const Use = (key, defaultValue) => {
return defaultValue; return defaultValue;
}; };
const If = (cond, a, b = null) => { const If = (cond, a, b = null, options = {}) => {
const marker = createText(""); const marker = createText("");
const container = Tag("div", { style: "display:contents" }, [marker]); const container = Tag("div", { style: "display:contents" }, [marker]);
let view = null; let currentView = null;
let lastState = null;
Watch(() => { Watch(() => {
const state = !!(typeof cond === "function" ? cond() : cond); const state = !!(typeof cond === "function" ? cond() : cond);
if (view) view.destroy(); if (state === lastState) return;
lastState = state;
const branch = state ? a : b; const branch = state ? a : b;
const oldView = currentView;
if (oldView) {
if (options.off) {
options.off(oldView.container, () => oldView.destroy());
} else {
oldView.destroy();
}
}
if (branch) { if (branch) {
view = Render(() => typeof branch === "function" ? branch() : branch); currentView = Render(() => typeof branch === "function" ? branch() : branch);
container.insertBefore(view.container, marker); const el = currentView.container;
container.insertBefore(el, marker);
if (options.on) {
requestAnimationFrame(() => {
requestAnimationFrame(() => options.on(el));
});
}
} else {
currentView = null;
} }
}); });
return container; return container;
}; };
@@ -336,7 +360,7 @@ const Mount = (component, target) => {
return instance; return instance;
}; };
const SigPro = { $, Render, Watch, Tag, If, For, Router, Mount, Share, Use }; const SigPro = { $, $$, Render, Watch, Tag, If, For, Router, Mount, Share, Use };
if (typeof window !== "undefined") { if (typeof window !== "undefined") {
Object.assign(window, SigPro); Object.assign(window, SigPro);
@@ -350,5 +374,5 @@ if (typeof window !== "undefined") {
window.SigPro = Object.freeze(SigPro); window.SigPro = Object.freeze(SigPro);
} }
export { $, Render, Watch, Tag, If, For, Router, Mount, Share, Use }; export { $, $$, Render, Watch, Tag, If, For, Router, Mount, Share, Use };
export default SigPro; export default SigPro;