import { type AtomType } from "../atom/atom"; /** * Creates a reactive computed atom whose value is derived from other atoms/stores. * * - Calls `fn` immediately, tracking all atoms/stores read inside it as dependencies. * - Returns a reactive `AtomType` atom that holds the computed value. * - Whenever any dependency changes, `fn` re-runs and the returned atom is updated, * triggering its own subscribers and any component re-renders that depend on it. * - The returned atom is a full `AtomType` — it can be subscribed to, read as * `result()` or `result.val`, passed into templates, used inside other `memo()`/ * `effect()` calls, etc. * - This is a "computed" / "derived" atom pattern. It is functionally equivalent to * `atom(() => fn())` but implemented separately to avoid a circular import between * `atom` and `memo`. Prefer `atom(() => derived)` for inline derived atoms inside * components. * - Correctly handles memos whose `fn` returns a function value: the function is * stored as the atom value, not called as an updater. * - Must NOT be called inside a template function (restricted context guard applies * via `createReactiveRunner`). * * @param fn - A pure function that reads reactive dependencies and returns a derived value. * @returns A reactive `AtomType` atom whose value stays in sync with `fn`. * * @example * const firstName = atom("Alice"); * const lastName = atom("Smith"); * * const fullName = memo(() => `${firstName()} ${lastName()}`); * * fullName(); // "Alice Smith" * firstName.set("Bob"); * fullName(); // "Bob Smith" — recomputed automatically * fullName.__subscribe(() => console.log("name changed:", fullName())); * * @example * // memo can return a function value — it is stored as-is, not called: * const multiplier = atom(2); * const memoFn = memo(() => { * const m = multiplier(); * return (x: number) => x * m; * }); * memoFn()(5); // 10 * multiplier.set(3); * memoFn()(5); // 15 */ export declare function memo(fn: () => T): AtomType; //# sourceMappingURL=memo.d.ts.map