mirror of
https://github.com/jaandrle/deka-dom-el
synced 2025-04-02 20:15:53 +02:00
* ⚡ 🎉 * ⚡ wip * 🔤 * ⚡ wip * ⚡ wip * ⚡ Refatc signals to .get/.set syntax #26 * 🐛 Better types for on* * 🔤 * 🔤 * 🐛 coumputed signal * 🔤 ⚡ Docs UI/UX * ⚡ 🔤 UI enhancements * ⚡ (bs) (un)min * 🔤 adds debugging * 🔤 ssr * 🔤 * ⚡ bs/lint * 🔤 * 🔤 UI * 🔤 updates texts * 🔤UI * ⚡ dispatch * 🔤 events * 🔤 elements * 🔤 intro * 🐛 fixes completitions for el with components * 🐛 wrong file(s) in git * 🔤 logo * 🐛 🔤 types 3ps * 🔤 ui/ux * 🔤 * 🔤 * 🔤 scopes * 🔤 * 🔤 ui/ux * 🔤 * ⚡ issignal * 🔤 improvemens * ⚡ irelands * 🔤 UI/UX/wording * 🐛 npx-hint [Scrollable region must have keyboard access | Axe Rules | Deque University | Deque Systems](https://dequeuniversity.com/rules/axe/4.10/scrollable-region-focusable?application=axeAPI) * 🔤 logos * ⚡ better? dts builds * Update README.md
46 lines
992 B
JavaScript
46 lines
992 B
JavaScript
import { el, scope } from "deka-dom-el";
|
|
import { S } from "deka-dom-el/signals";
|
|
|
|
function CounterWithIsolatedTimer() {
|
|
const { host } = scope;
|
|
|
|
// Main component state
|
|
const count = S(0);
|
|
|
|
// Create a timer in an isolated scope
|
|
scope.isolate(() => {
|
|
// These subscriptions won't be tied to the component lifecycle
|
|
// They would continue to run even if the component was removed
|
|
const timer = S(0);
|
|
|
|
// Not recommended for real applications!
|
|
// Just demonstrating scope isolation
|
|
setInterval(() => {
|
|
timer.set(timer.get() + 1);
|
|
console.log(`Timer: ${timer.get()}`);
|
|
}, 1000);
|
|
});
|
|
|
|
// Normal component functionality within main scope
|
|
function increment() {
|
|
count.set(count.get() + 1);
|
|
}
|
|
|
|
return el("div").append(
|
|
el("p").append(
|
|
"Count: ",
|
|
el("#text", S(() => count.get()))
|
|
),
|
|
el("button", {
|
|
textContent: "Increment",
|
|
onclick: increment
|
|
}),
|
|
el("p", "An isolated timer runs in console")
|
|
);
|
|
}
|
|
|
|
// Usage
|
|
document.body.append(
|
|
el(CounterWithIsolatedTimer)
|
|
);
|