push
github
373 of 445 branches covered (83.82%)
Branch coverage included in aggregate %.
0 of 25 new or added lines in 1 file covered. (0.0%)
2860 of 3303 relevant lines covered (86.59%)
868.47 hits per line
NEW
|
import { AnyCell, ValueCell } from "./cell";
|
|
NEW
|
import { SheetProxy } from "./proxy";
|
× |
NEW
|
|
× |
NEW
|
export const clock = ( |
× |
NEW
|
proxy: SheetProxy, |
× |
NEW
|
live: AnyCell<boolean>, |
× |
NEW
|
delay: number |
× |
NEW
|
) => { |
× |
NEW
|
const clock = proxy.new(0) as ValueCell<number> & { |
× |
NEW
|
stop: () => void; |
× |
NEW
|
restart: () => void; |
× |
NEW
|
}; |
× |
NEW
|
let run: ReturnType<typeof setInterval>; |
× |
NEW
|
const start = () => {
|
× |
NEW
|
if (run) clearInterval(run);
|
× |
NEW
|
run = setInterval(() => clock.update((v) => v + 1), delay);
|
× |
NEW
|
}; |
× |
NEW
|
const stop = () => {
|
× |
NEW
|
if (run) clearInterval(run);
|
× |
NEW
|
}; |
× |
NEW
|
clock.stop = stop; |
× |
NEW
|
clock.restart = start; |
× |
NEW
|
live.subscribe((b) => (b ? start() : stop())); |
× |
NEW
|
return clock;
|
× |
NEW
|
}; |
× |