/** * Reactive state management via signals and effects. * * Wraps plain objects in a Proxy that tracks property reads inside * effect callbacks and schedules re-runs on writes. Supports * isolated contexts, untracked reads, and async getters. * * @module signal */ /** * Creates a reactive proxy around the given data object. * * Property reads inside an active {@link effect} are automatically tracked. * Writes and deletions schedule a debounced re-run of dependent effects. * * @typeParam T The initial data type. Defaults to a plain object. * @this {object} Reactive context; defaults to the shared global context when * called without an explicit receiver. To isolate signals, bind or call with * a custom object: `signal.call(myCtx, data)`. * @param data The initial data. Defaults to an empty plain object. * @returns A reactive Proxy that mirrors `data`, preserving array vs object shape. * * @category Signal * * @example * ```ts * // creates a reactive signal * const state = signal({ * // reactive field * page: 1, * // computed reactive field * get left() { * return 100 - this.page; * }, * // non-reactive methods * nextPost() { * if (this.page < 100) this.page++; * }, * prevPost() { * if (this.page > 0) this.page--; * }, * async fetchPost() { * const response = await fetch( * `https://jsonplaceholder.typicode.com/posts/${this.page}`, * ); * return await response.json(); * }, * }); * ``` */ export declare function signal = Record>(this: object | void, data?: T): T; /** * Runs a function without tracking property accesses. * * Reads performed inside the callback will not subscribe the current * {@link effect} to the accessed properties. Useful for breaking cycles * or performing intentional non-reactive reads. * * The context is determined by `this`, following the same rules as * {@link signal}. * * @typeParam T The type of the returned value. * @this {object} Reactive context; defaults to the shared global context. * @param fn The function to run outside the tracking system. * @returns The value returned by `fn`. * * @category Signal * * @example * ```ts * const state = signal({ count: 0 }); * // reads without subscribing * const dispose = effect(() => { * untrack(() => { * console.log(state.count); * }); * }); * // triggers the effect * state.count += 1; * // later … * dispose(); * ``` */ export declare function untrack(this: object | void, fn: () => T): T; /** * Creates a reactive effect that re-runs whenever tracked properties change. * * The `getter` function is executed immediately. Any property read on a * signal during this execution is subscribed to the effect. When a * subscribed property is written, the effect is scheduled to re-run * (debounced via `setTimeout 0`). * * An optional `setter` receives the return value of `getter`. When the * getter returns a `Promise`, `setter` is called with its resolved value. * * The context is determined by `this`, following the same rules as * {@link signal}. * * @this {object} Reactive context; defaults to the shared global context. * @param getter Function that reads reactive properties and optionally returns a value. * @param setter Optional callback that receives the return value of `getter`, or its resolved value when getter returns a promise. * @returns A disposal function that unsubscribes the effect from all tracked properties. * * @category Signal * * @example * ```ts * // creates a reactive signal * const state = signal({ count: 0 }); * // subscribes to changes * const dispose = effect(() => { * // read with subscription * console.log(state.count); * }); * // triggers the effect * state.count += 1; * // later … * dispose(); * ``` */ export declare function effect(this: object | void, getter: () => any | Promise, setter?: (value: any) => void): () => void; //# sourceMappingURL=signal.d.ts.map