import { type AtomType } from "../atom/atom"; /** * Mutates `stateObj` in place and returns a read-tracked wrapper around it. * * **Step 1 — mutate `stateObj` in place:** * - Getters are redefined with version-based caching: the getter result is * recomputed only when `a.__version__` changes, avoiding redundant calls. * - Methods are wrapped so that every call is automatically batched inside * `a.update()`, making method-based mutations reactive with no extra boilerplate. * - Async functions are not supported and will throw. * * **Step 2 — build a read-tracked wrapper:** * - `Object.create(stateObj)` gives the wrapper free access to all methods and * version-cached getters through the prototype chain — no need to redefine them. * - Plain data properties (non-function, non-getter) get their own tracked * `get`/`set` pair on the wrapper: * - `get` calls `a()`, which registers the atom as a dependency inside * `memo()`, `effect()`, and component template functions, so they * automatically re-run when `a.update()` is called. * - `set` is a convenience shorthand: `wrapper.count = 5` is equivalent to * `a.update(s => { s.count = 5; })`. * - Functions and getters are intentionally skipped on the wrapper — they are * already accessible via the prototype chain. * * @param stateObj - The plain state object to wrap. Mutated in place. * @param a - The atom that holds `stateObj` and drives reactivity. * @param contextName - Display name used in error messages (`"store"` / `"useState"`). * @returns A read-tracked wrapper whose data-property reads subscribe the * caller to `a` as a reactive dependency. */ export declare const wrapStateFunctions: >(stateObj: T, a: AtomType, contextName: string) => T; /** * Creates a global reactive state container from a plain object. * * Unlike `useState`, `store` is designed to be called at module level (outside * any component) and shared across the application. The returned factory * function can be called inside any component to obtain the shared * `[wrapper, update]` pair. * * - `wrapper` is a read-tracked object (built by `wrapStateFunctions`): * - Reading a data property (e.g. `state.count`) subscribes the current * component / `memo` / `effect` to re-run when the store updates. * - Methods defined on the initial object are automatically wrapped to call * `a.update()` — no manual batching needed. * - Getters are version-cached and recomputed only when `a.update()` is called. * - Direct assignment (`state.count = 5`) is also reactive and equivalent to * `update(s => { s.count = 5; })`. * - `update` is the raw `a.update` handle for external mutations that don't go * through a method. * * @param initialState - A plain object (with optional methods and getters) that * represents the initial state of the store. * @returns A factory function `() => [wrapper, update]` to be called inside * components or reactive contexts. * * @example * // module-level — created once * const counterStore = store({ * count: 0, * incr() { this.count++; }, * get doubled() { return this.count * 2; }, * }); * * // inside a component or effect * const [state, update] = counterStore(); * * state.count; // 0 — tracked read, component re-renders on change * state.incr(); // calls a.update() automatically * state.doubled; // 0 — version-cached getter * update(() => { state.count = 10; }); // direct external mutation */ export declare const store: >(initialState: T) => () => (T | ((fn: (draft: T) => void, silently?: boolean) => void))[]; //# sourceMappingURL=store.d.ts.map