fluidstate
Version:
Library for fine-grained reactivity state management
54 lines (53 loc) • 2.23 kB
TypeScript
import { ComputedAtom, Reaction } from "./reactive-primitive-types";
/**
* Sets the current derivation (reaction or computed atom) that is being tracked.
*
* @internal
* @param newTrackingDerivation The new derivation to track, or `null` to stop tracking.
*/
export declare const setTrackingDerivation: (newTrackingDerivation: ComputedAtom<unknown> | Reaction | null) => void;
/**
* Gets the current derivation (reaction or computed atom) that is being tracked.
*
* @internal
* @returns The currently tracked derivation, or `null` if none.
*/
export declare const getTrackingDerivation: () => Reaction | ComputedAtom<unknown> | null;
/**
* Checks if fluidstate is currently tracking dependencies within a local derivation.
*
* This is determined by `fluidstate`s internal tracking of the current
* `trackingDerivation` (i.e., whether we are inside a reaction or computed
* atom's execution).
*
* @internal
* @returns `true` if a local derivation is being tracked, `false` otherwise.
*/
export declare const isTrackingDerivation: () => boolean;
/**
* Checks if any reactive instance (local or remote) is currently tracking dependencies.
*
* This function determines if a reactive context is active by checking both the
* local `fluidstate` instance (via `isTrackingDerivation`) and any connected
* reactive remotes.
*
* Dependency tracking occurs during the execution of derivations like computed
* atoms or reactions.
*
* @returns `true` if any reactive instance is tracking, `false` otherwise.
*/
export declare const isTracking: () => boolean;
export declare const untrackRemotes: <T>(action: () => T) => T;
/**
* Executes the provided `action` function without tracking any reactive
* dependencies within its scope. This applies to `fluidstate`'s own tracking,
* the underlying reactive layer, and all registered reactive remotes.
*
* This is useful when you need to read reactive values inside a reactive
* context (like a computed atom or reaction) without establishing a
* dependency on those values.
*
* @param action - The function to execute without dependency tracking.
* @returns The result of the `action` function.
*/
export declare const untrack: <T>(action: () => T) => T;