mirror of
https://github.com/jaandrle/deka-dom-el
synced 2024-11-23 00:59:38 +01:00
17 lines
555 B
JavaScript
17 lines
555 B
JavaScript
|
import { O } from "deka-dom-el/observables";
|
||
|
const observable= O(0);
|
||
|
// computation pattern
|
||
|
const double= O(()=> 2*observable());
|
||
|
|
||
|
const ac= new AbortController();
|
||
|
O.on(observable, v=> console.log("observable", v), { signal: ac.signal });
|
||
|
O.on(double, v=> console.log("double", v), { signal: ac.signal });
|
||
|
|
||
|
observable(observable()+1);
|
||
|
const interval= 5000;
|
||
|
const id= setInterval(()=> observable(observable()+1), interval);
|
||
|
ac.signal.addEventListener("abort",
|
||
|
()=> setTimeout(()=> clearInterval(id), 2*interval));
|
||
|
|
||
|
setTimeout(()=> ac.abort(), 3*interval)
|