type Subscriber = () => void; type Updater = (prev: T) => T; type UpdateFn = (draft: T) => void; export type AtomConfig = { /** Skip the restricted-context guard so the atom can be created inside templates, effects, etc. */ skipRestrictedContextCheck?: boolean; }; export type AtomType = { (): T; get(): T; set(value: T | Updater, silently?: boolean): void; update(fn: UpdateFn, silently?: boolean): void; __subscribe(fn: Subscriber): () => void; toJSON(): string; /** Writable so extended atoms can stamp their own name (e.g. "iAtom"). */ name: string; readonly val: T; readonly __version__: number; readonly __isAtom___: true; readonly __id__: number; /** Set to true to suppress devtools logging for this atom's set/update calls. */ skipDevToolsLog?: boolean; }; /** * Create a reactive atom. * * The core reactive primitive in mates — a single callable function object * with `get`, `set`, `update`, `val`, `__subscribe`, `__version__`, * `__id__`, `toJSON`, and `name`. * * Callable as `count()` as shorthand for `count.get()`. * Both `get()` and the `val` getter participate in view subscription and * read-tracking so components re-render automatically. * * For lock/unlock use `superAtom()`. * * When a **function** is passed as `initial`, the atom is treated as a * derived/memoised atom. The function is called via `memo()` and the * resulting reactive atom is returned. In this mode `config` is ignored. * * @param initial - The initial value for the atom, **or** a derive function * `() => T` to create a memoised/derived atom. * @param config - Optional configuration object (ignored for derived atoms). * @param config.skipRestrictedContextCheck - When `true`, bypasses the guard * that normally prevents atom creation inside templates, effects, or memos. * Useful for directives and other advanced patterns that intentionally * create atoms from within a template function. Defaults to `false`. * * @example * const count = atom(0); * count.set(1); * count.set(n => n + 1); * count(); // 2 * count.val; // 2 * count.update(d => { d.x = 1 }); // for objects * count.toJSON(); // "2" * count.name; // "atom" * count.__id__; // unique incrementing integer * * // Derived / memoised atom — re-computes whenever its dependencies change: * const double = atom(() => count() * 2); * double(); // 4 * * // Inside a directive or other restricted context: * const flag = atom(false, { skipRestrictedContextCheck: true }); */ export declare function atom(initial: (() => T) | T, config?: AtomConfig): AtomType; export type IAtomType = { (): T; get(): T; set(value: T | ((prev: T) => T), silently?: boolean): void; __subscribe(fn: () => void): () => void; toJSON(): string; name: string; readonly val: T; readonly __version__: number; readonly __isAtom___: true; readonly __id__: number; }; /** * Create a deep-frozen reactive atom. * * Every value written via `set()` is automatically deep-frozen, preventing * accidental mutation. `update()` is removed — use `set()` with a new object. * * All other `atom()` capabilities are preserved: callable, `get`, `val`, * `__subscribe`, `__version__`, `__id__`, `toJSON`. * * For lock/unlock use `superAtom({ freeze: true })`. * * @param initial - The initial value (will be deep-frozen). * @param config - Optional configuration object. * @param config.skipRestrictedContextCheck - When `true`, bypasses the guard * that normally prevents atom creation inside templates, effects, or memos. * Defaults to `false`. * * @example * const cfg = iAtom({ api: "https://..." }); * cfg.set({ api: "https://v2..." }); * cfg.set(prev => ({ ...prev, api: "https://v3..." })); * Object.isFrozen(cfg()); // true */ export declare function iAtom(initial: T, config?: AtomConfig): IAtomType; export type SuperAtomOptions = { /** deepFreeze every value written to this atom. */ freeze?: boolean; /** Skip the restricted-context guard so the atom can be created inside templates, effects, etc. */ skipRestrictedContextCheck?: boolean; }; export type SuperAtomType = AtomType & { lock(passcode?: string): void; unlock(passcode?: string): void; reset(): void; freeze(): void; readonly name: string; }; /** * Create a full-featured reactive atom. * * Extends `atom()` with: * - `lock(passcode?)` / `unlock(passcode?)` — prevent/allow mutations. * - `reset()` — restore the initial value and notify subscribers. * - `freeze()` — deepFreeze the current value in place. * - `{ freeze: true }` — deepFreeze every value on set (like `iAtom` but * with lock/unlock and update throws a helpful error). * * @param initial - The initial value. * @param options - Optional configuration object. * @param options.freeze - When `true`, deep-freezes every value on set. * @param options.skipRestrictedContextCheck - When `true`, bypasses the guard * that normally prevents atom creation inside templates, effects, or memos. * Defaults to `false`. * * @example * const config = superAtom({ theme: "light" }); * config.lock(); * config.set({ theme: "dark" }); // silently ignored * config.unlock(); * config.set({ theme: "dark" }); // works * config.reset(); // back to { theme: "light" } * * // Immutable variant with lock: * const cfg = superAtom({ api: "https://..." }, { freeze: true }); * cfg.lock("secret"); */ export declare function superAtom(initial: T, options?: SuperAtomOptions): SuperAtomType; export { deepFreeze as df } from "../../Utils/deepFreeze"; //# sourceMappingURL=atom.d.ts.map