import { JSXElementType, JSXElement, Props } from '../elements.js'; import '../jsx-globals.js'; import { capture } from './lifecycle.js'; import { For } from './control.js'; /** * State value holder - callable to read, has set method to update * @example * const count = state(0); * count(); // read: 0 * count.set(1); // write: triggers re-render */ interface State { (): T; set(...args: StateSetterArgs): void; [Symbol.iterator](): IterableIterator[number]>; } type StateUpdater = (prev: T) => T; type StateSetterArgs = [Extract unknown>] extends [ never, ] ? [value: T] | [updater: StateUpdater] : [updater: StateUpdater]; /** * Public setter type for state cells. */ type StateSetter = (...args: StateSetterArgs) => void; /** * Tuple-first state handle returned by `state()`. */ type StateTuple = [get: State, set: StateSetter] & State; /** * Creates a local state value for a component * Optimized for: * - O(1) read performance * - Minimal allocation per state * - Fast scheduler integration * * IMPORTANT: state() must be called during component render execution. * It captures the current component instance from context. * Calling outside a component function will throw an error. * * @example * ```ts * // ✅ Correct: called during render * export function Counter() { * const [count, setCount] = state(0); * return { type: 'button', children: [count()] }; * } * * // ❌ Wrong: called outside component * const count = state(0); * export function BadComponent() { * return { type: 'div' }; * } * ``` */ declare function state(initialValue: T): StateTuple; declare const SNAPSHOT_SOURCE_BRAND: unique symbol; type SnapshotSourceBrand = { readonly [SNAPSHOT_SOURCE_BRAND]: true; }; /** A reactive derived value produced by {@link derive}; call it to read the current result. */ interface Derived { (): T; } type SnapshotSource = { value: T | null; pending?: boolean; error?: Error | null; } & SnapshotSourceBrand; /** Creates a render-scoped derived value; must be called during component render. */ declare function derive(fn: () => TOut): Derived; declare function derive( source: SnapshotSource | TIn | (() => TIn), map: (value: TIn) => TOut ): Derived; /** A fine-grained reactive membership check produced by {@link selector}. */ interface Selector { (candidate: T): boolean; } type SelectorEquals = { bivarianceHack(a: T, b: T): boolean; }['bivarianceHack']; /** * Creates a render-scoped predicate for keyed membership in reactive list rows. * * Use this when a `` child needs to compare each stable item with a * changing selected value. Unlike a plain closure capture, the predicate * subscribes the affected rows and updates them without rebuilding the list. * Must be called during component render. */ declare function selector( source: () => T, equals?: SelectorEquals ): Selector; export { State, StateUpdater, StateSetterArgs, StateSetter, StateTuple, state, SNAPSHOT_SOURCE_BRAND, SnapshotSourceBrand, Derived, SnapshotSource, derive, Selector, SelectorEquals, selector, };