mirror of
https://github.com/jaandrle/deka-dom-el
synced 2024-11-23 00:59:38 +01:00
17 lines
519 B
JavaScript
17 lines
519 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= 5000;
|
||
|
const id= setInterval(()=> signal(signal()+1), interval);
|
||
|
ac.signal.addEventListener("abort",
|
||
|
()=> setTimeout(()=> clearInterval(id), 2*interval));
|
||
|
|
||
|
setTimeout(()=> ac.abort(), 3*interval)
|