mirror of
https://github.com/jaandrle/deka-dom-el
synced 2024-11-24 17:39:36 +01:00
17 lines
523 B
JavaScript
17 lines
523 B
JavaScript
|
import { S } from "deka-dom-el/signals";
|
||
|
const signal= S(0);
|
||
|
// computation pattern
|
||
|
const double= S(()=> 2*signal());
|
||
|
|
||
|
const ac= new AbortController();
|
||
|
S.on(signal, v=> console.log("signal", v), { signal: ac.signal });
|
||
|
S.on(double, v=> console.log("double", v), { signal: ac.signal });
|
||
|
|
||
|
signal(signal()+1);
|
||
|
const interval= 5 * 1000;
|
||
|
const id= setInterval(()=> signal(signal()+1), interval);
|
||
|
ac.signal.addEventListener("abort",
|
||
|
()=> setTimeout(()=> clearInterval(id), 2*interval));
|
||
|
|
||
|
setTimeout(()=> ac.abort(), 3*interval)
|