fluidstate
Version:
Library for fine-grained reactivity state management
28 lines (27 loc) • 1.4 kB
TypeScript
import { CreateAtom } from "./reactive-primitive-types";
/**
* Creates a reactive atom, which is a fundamental unit of reactivity.
* This atom does not hold a value itself but can be reported as observed or changed.
* It interacts with the underlying reactive layer and manages observations
* from any registered reactive remotes.
*
* The `onBecomeObservedListener` and `onBecomeUnobservedListener` options from
* the underlying reactive layer are respected.
*
* When `reportObserved` is called:
* 1. It notifies any reactive remotes that are currently tracking, potentially
* creating remote-specific atoms if they don't exist yet.
* 2. It reports observation to the underlying reactive layer.
* 3. It returns `true` if the atom was observed either by the local layer or by any remote.
*
* When `reportChanged` is called:
* 1. It reports the change to the underlying reactive layer, which in turn
* notifies its dependents.
* 2. This change will also propagate to remote atoms that were created to mirror this atom.
*
* @param name - A descriptive name for the atom, useful for debugging.
* @param options - Optional configuration for the atom, including listeners
* for when the atom becomes observed or unobserved by the local layer.
* @returns An `Atom` object with `reportObserved` and `reportChanged` methods.
*/
export declare const createAtom: CreateAtom;