The best way to control Claude Code, Codex and more from any computer or phone

main
ts 31 lines 892 Bytes
Raw
1 import { RegistryContext } from "@effect/atom-react";
2 import { type Atom, AtomRegistry } from "effect/reactivity";
3 import { createElement } from "react";
4
5 export const appAtomRegistry = AtomRegistry.make();
6
7 export function AppAtomRegistryProvider({ children }: React.PropsWithChildren) {
8 return createElement(RegistryContext.Provider, { value: appAtomRegistry }, children);
9 }
10
11 /**
12 * Calls `listener` with each value after the current one. A bare `subscribe` never computes a
13 * derived atom nobody has read, so it never learns its parents and never fires.
14 */
15 export function subscribeAtomChanges<A>(
16 atom: Atom.Atom<A>,
17 listener: (value: A) => void,
18 ): () => void {
19 let current = true;
20 return appAtomRegistry.subscribe(
21 atom,
22 (value) => {
23 if (current) {
24 current = false;
25 return;
26 }
27 listener(value);
28 },
29 { immediate: true },
30 );
31 }