UNPKG

fluidstate

Version:

Library for fine-grained reactivity state management

26 lines (25 loc) 1.59 kB
import { Atom, ComputedAtom } from "./reactive-primitive-types"; /** * Manages the observation of a local atom (or computed atom) by registered reactive remotes. * * For each reactive remote: * - If the remote is currently tracking (i.e., a reactive computation is active on the remote): * - It ensures a corresponding "remote atom" exists on that remote instance. * - If not, it creates one. This remote atom is linked to the local `layerAtom` * such that changes in the `layerAtom` propagate to the remote atom. * - The creation involves setting up a local reaction that listens to the `layerAtom` * and calls `reportChanged` on the remote atom. This local reaction's scheduling * can be influenced by the `scheduler` provided when the remote was added. * - It then calls `reportObserved()` on this remote atom. * * This function is crucial for establishing a reactive link from a local atom * to its representation on a remote reactive system. * * @param atom - The local atom (or computed atom) being observed. * Used as a key to map to remote atoms. * @param layerAtom - The actual atom (or computed atom) from the underlying reactive layer * that the remote system will effectively listen to. * @param name - The name of the local atom, used for naming the derived remote atom. * @returns `true` if at least one reactive remote observed the atom, `false` otherwise. */ export declare const observeRemoteAtoms: (atom: Atom | ComputedAtom<unknown>, layerAtom: Atom | ComputedAtom<unknown>, name: string) => boolean;