UNPKG

nrgy

Version:

The library for reactive programming using efficient computing and MVC/MVVM patterns

68 lines (65 loc) 2.01 kB
import { A as Atom, D as DestroyableAtom, S as Signal, V as ValueEqualityFn } from './types-CxOJPpKX.cjs'; /** * Checks if the given `value` is a reactive `Atom`. */ declare function isAtom<T>(value: unknown): value is Atom<T>; /** * Returns a name of the given Atom. */ declare function getAtomName(value: Atom<any>): string | undefined; /** * A writable `Atom` with a value that can be mutated via a setter interface. */ interface WritableAtom<T> extends DestroyableAtom<T> { /** * Signals that the `AtomEffect` has been destroyed */ readonly onDestroyed: Signal<void>; /** * Directly set the atom to a new value, and notify any dependents. */ set(value: T): boolean; /** * Update the value of the atom based on its current value, and * notify any dependents. */ update(updateFn: (value: T) => T): boolean; /** * Update the current value by mutating it in-place, and * unconditionally notify any dependents. */ mutate(mutatorFn: (value: T) => void): void; /** * Returns a readonly version of this atom. Readonly atom can be accessed to read their value * but can't be changed using set, update or mutate methods. */ asReadonly(): Atom<T>; /** * Destroys the atom, notifies any dependents and calls `onDestroy` callback. */ destroy(): void; } /** * Options passed to the `atom` creation function. */ type AtomOptions<T> = { /** * Atom's name */ name?: string; /** * A comparison function which defines equality for atom values. */ equal?: ValueEqualityFn<T>; /** * Callback is called when the store is destroyed. */ onDestroy?: () => void; }; /** * Error thrown when an attempt is made to update an atom in a tracked context. */ declare class AtomUpdateError extends Error { constructor(name?: string); } export { type AtomOptions as A, type WritableAtom as W, AtomUpdateError as a, getAtomName as g, isAtom as i };