Anchor Namespace
The anchor function is the low-level core of the library. While most users should prefer mutable() or immutable(), anchor provides advanced configuration options and a namespace for powerful utility functions.
anchor()
Creates a reactive proxy for a given value.
export function anchor<T>(init: T, options?: StateOptions): State<T>;init: The initial value to make reactive.options: Configuration options (recursive, immutable, etc.).
Creation Utilities
anchor.raw()
Creates a reactive state without cloning the initial value. This modifies the original object in place.
anchor.raw<T>(init: T, options?: StateOptions): State<T>;anchor.flat()
Creates a "flat" reactive state. Only top-level properties are tracked; nested objects remain non-reactive.
anchor.flat<T>(init: T, options?: StateOptions): State<T>;anchor.ordered()
Creates a reactive array that maintains a sorted order.
anchor.ordered<T>(init: T[], compare: (a: T, b: T) => number): State<T[]>;anchor.model()
Creates a state validated by a schema (e.g., Zod).
anchor.model<S extends LinkableSchema>(
schema: S,
init: ModelInput<S>,
options?: StateOptions
): ModelOutput<S>;anchor.catch()
Registers an exception handler for a state.
anchor.catch<T>(state: T, handler: (error: Error) => void): void;State Utilities
anchor.has()
Checks if an object is a reactive state managed by Anchor.
anchor.has(value: unknown): boolean;anchor.get()
Retrieves the underlying raw value of a state.
anchor.get<T>(state: T, silent?: boolean): T;silent: Iftrue, accessing the value won't trigger dependency tracking (equivalent tountrack).
anchor.find()
Finds the existing reactive proxy for a given raw object, if one exists.
anchor.find<T>(init: T): State<T> | undefined;anchor.read()
Creates a readonly proxy for an existing state. This is a shallow readonly view, unlike immutable() which is deeply immutable.
anchor.read<T>(state: T): ReadonlyState<T>;anchor.snapshot()
Creates a deep clone (snapshot) of the state's current value.
anchor.snapshot<T>(state: T): T;anchor.destroy()
Destroys a state and all its associated subscriptions and observers.
anchor.destroy(state: Linkable): void;Mutation Utilities
anchor.writable()
Creates a writable interface for a state (usually an immutable one), optionally restricted by contracts.
anchor.writable<T>(state: T, contracts?: Contracts<T>): Writable<T>;anchor.assign()
Object.assign equivalent for reactive states.
anchor.assign<T>(state: T, partial: Partial<T>): T;anchor.remove()
Removes properties from a state object.
anchor.remove<T>(state: T, ...keys: (keyof T)[]): void;anchor.clear()
Clears the state. Supports objects, arrays, Maps, and Sets.
anchor.clear<T>(state: T): void;anchor.append()
Appends a string to an existing string property.
anchor.append<T, K extends keyof T>(state: T, prop: K, value: T[K]): void;anchor.prepend()
Prepends a string to an existing string property.
anchor.prepend<T, K extends keyof T>(state: T, prop: K, value: T[K]): void;