UNPKG

fluidstate

Version:

Library for fine-grained reactivity state management

56 lines (55 loc) 2.66 kB
import { NameOptions } from "../extras/reactive-names"; import { ContextReactiveOptions, CreateReactive } from "./reactive-abstraction-types"; /** * Creates a reactive version of the provided object. * This is the primary entry point for making data structures reactive. * It supports objects, arrays, Sets, Maps, and Promises. * * @param value The object to make reactive. * @param reactiveOptions Optional configuration for the reactive instance. * @returns A reactive proxy of the input object, or the value itself if it cannot be made reactive. */ export declare const createReactive: CreateReactive; export declare const createProxy: <T>(value: T, reactiveOptions?: ContextReactiveOptions, nameOptions?: NameOptions) => T; export declare const setProxy: <T extends object>(inertObject: T, proxy: T) => T; /** * Checks if a given value is a reactive proxy. * * @param value The value to check. * @returns `true` if the value is a reactive proxy, `false` otherwise. */ export declare const isReactive: <T>(value: T) => value is T & object; /** * Retrieves the reactive proxy associated with a given object. * If the object itself is a proxy, it is returned. * If the object is an inert (original) object that has a reactive proxy, that proxy is returned. * * @param value The object for which to get the reactive proxy. * @returns The reactive proxy if one exists, otherwise `null`. */ export declare const getReactive: <T extends object>(value: T) => T | null; /** * Retrieves the original, underlying non-reactive (inert) object from a reactive proxy. * * @param proxy The reactive proxy. * @returns The underlying inert object if `proxy` is a known reactive proxy, otherwise `null`. */ export declare const getInert: <T extends object>(proxy: T) => T | null; /** * Ensures that the returned value is the inert (non-reactive) version of the input. * If the input is a reactive proxy, its underlying inert version is returned. * Otherwise, the input value is returned as is. * * @param value The value to ensure is inert. * @returns The underlying inert version of the value. */ export declare const ensureInert: <T>(value: T) => T; /** * Retrieves a set of keys that correspond to computed properties (getters) on a reactive object. * For non-object types or non-reactive objects, an empty set is returned. * * @param object The reactive object (or any value). * @returns A `Set` of string or symbol keys representing computed properties. */ export declare const getComputedKeys: <T>(object: T) => Set<string | symbol>; export declare const getProxyComputedKeys: <T extends object>(proxy: T) => Set<string | symbol>;