This commit is contained in:
2026-04-13 08:01:28 +02:00
parent d8ab8c75d8
commit 627cfcd5d5
3 changed files with 31 additions and 4 deletions

View File

@@ -342,19 +342,31 @@ const If = (cond, ifYes, ifNot = null, trans = null) => {
const root = Tag("div", { style: "display:contents" }, [anchor]) const root = Tag("div", { style: "display:contents" }, [anchor])
let currentView = null let currentView = null
let last = null let last = null
let exitPromise = null
Watch( Watch(
() => !!(isFunc(cond) ? cond() : cond), () => !!(isFunc(cond) ? cond() : cond),
show => { show => {
if (show === last) return if (show === last) return
last = show last = show
const disposeView = () => { const disposeView = () => {
if (currentView) { if (currentView) {
currentView.destroy() currentView.destroy()
currentView = null currentView = null
} }
} }
if (currentView && !show && trans?.out) trans.out(currentView.container, disposeView)
else disposeView() if (currentView && !show && trans?.out) {
if (exitPromise && exitPromise.cancel) exitPromise.cancel()
const anim = trans.out(currentView.container, disposeView)
exitPromise = anim
if (anim && anim.finished) anim.finished.then(disposeView)
else disposeView()
} else {
disposeView()
}
const content = show ? ifYes : ifNot const content = show ? ifYes : ifNot
if (content) { if (content) {
currentView = Render(() => isFunc(content) ? content() : content) currentView = Render(() => isFunc(content) ? content() : content)
@@ -439,7 +451,20 @@ const Mount = (comp, target) => {
return inst return inst
} }
const SigPro = Object.freeze({ $, Watch, Tag, Render, If, For, Router, Mount, onMount, onUnmount }) const set = (signal, path, value) => {
if (value === undefined) {
signal(isFunc(path) ? path(signal()) : path);
} else {
const keys = path.split('.');
const last = keys.pop();
const current = signal();
const obj = keys.reduce((o, k) => ({ ...o, [k]: { ...o[k] } }), { ...current });
obj[last] = value;
signal(obj);
}
};
const SigPro = Object.freeze({ $, Watch, Tag, Render, If, For, Router, Mount, onMount, onUnmount, set })
if (typeof window !== "undefined") { if (typeof window !== "undefined") {
Object.assign(window, SigPro) Object.assign(window, SigPro)
@@ -447,5 +472,5 @@ if (typeof window !== "undefined") {
.split(" ").forEach(t => window[t[0].toUpperCase() + t.slice(1)] = (p, c) => SigPro.Tag(t, p, c)) .split(" ").forEach(t => window[t[0].toUpperCase() + t.slice(1)] = (p, c) => SigPro.Tag(t, p, c))
} }
export { $, Watch, Tag, Render, If, For, Router, Mount, onMount, onUnmount } export { $, Watch, Tag, Render, If, For, Router, Mount, onMount, onUnmount, set }
export default SigPro export default SigPro

1
sigpro2.min.js vendored Normal file

File diff suppressed because one or more lines are too long

1
sigworkPro.min.js vendored Normal file

File diff suppressed because one or more lines are too long