The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { secondTick } from "@t3tools/client-runtime/clock"; |
| 2 | |
| 3 | /** |
| 4 | * Ref callback that writes `format(Date.now())` into a node and, while `live`, |
| 5 | * rewrites it on the shared second tick. Running timers update through the DOM |
| 6 | * so a ticking label never re-renders the timeline or composer around it. |
| 7 | */ |
| 8 | export function tickTextContent(format: (nowMs: number) => string, live: boolean) { |
| 9 | return (node: HTMLElement | null) => { |
| 10 | if (!node) return; |
| 11 | const write = () => { |
| 12 | const text = format(Date.now()); |
| 13 | if (node.textContent !== text) node.textContent = text; |
| 14 | }; |
| 15 | write(); |
| 16 | return live ? secondTick.subscribe(write) : undefined; |
| 17 | }; |
| 18 | } |