import { type AtomConfig } from "./atom"; /** * A reactive `Map` returned by `mapAtom`. * * Extends the standard `Map` with two extra mutation methods: * * - `update(fn)` — pass the live map instance into `fn` so you can * call any Map method directly (set/delete/clear/get). * `fn` returns nothing; mutations are in-place. * One notification fires after `fn` returns. * * - `updateItem(key, fn)` — get the object stored at `key` and pass it to * `fn` for in-place mutation (no return value). * Only meaningful when `V` is an object type. * Use `map.set(key, newValue)` to replace primitives. */ export type MapAtomType = Map & { /** * Receive the live `Map` instance and mutate it directly. * `fn` may call any Map method (`set`, `delete`, `clear`, `get`, …). * No return value — mutations are in-place. * One reactive notification fires after `fn` returns. * * ```ts * const users = mapAtom([["alice", { name: "Alice", score: 0 }]]); * * users.update((map) => { * map.get("alice")!.score += 10; // mutate a nested object * map.set("bob", { name: "Bob", score: 5 }); // add an entry * map.delete("carol"); // remove an entry * }); * ``` * * @param fn - Receives the live map and should mutate it in place. * @returns The map instance for chaining. */ update(fn: (map: Map) => void): MapAtomType; /** * Get the object stored at `key` and pass it to `fn` for in-place mutation. * `fn` returns nothing — the value is mutated directly. * One reactive notification fires after `fn` returns. * * Only meaningful when `V` is an object type. To replace a primitive value * use `map.set(key, newValue)` instead. * No-op when `key` is absent or its value is not an object. * * ```ts * const users = mapAtom([["alice", { name: "Alice", age: 30 }]]); * * users.updateItem("alice", (user) => { * user.age += 1; * user.name = user.name.toUpperCase(); * }); * * users.get("alice"); // { name: "ALICE", age: 31 } * ``` * * @param key - The key whose value should be mutated. * @param fn - Receives the current value and should mutate it in place. * @returns The map instance for chaining. */ updateItem(key: K, fn: (value: V) => void): MapAtomType; }; /** * Creates a reactive `Map` whose mutation methods notify subscribers * and whose read methods register the map as a tracked dependency. * * **Mutations** — each triggers a notification so subscribers are informed: * - `set(key, value)`, `delete(key)`, `clear()` * - `update(fn)` — in-place whole-map mutation * - `updateItem(key, fn)` — in-place mutation of a single object value * * **Reads** — each registers a reactive dependency: * - `get(key)`, `has(key)`, `size`, `entries()`, `values()`, `keys()`, * `forEach()`, `[Symbol.iterator]()` * * The underlying atom is exposed via two non-enumerable properties: * - `m.__isAtom___` — the raw `AtomType>` for manual subscriptions * - `m.__version__` — current version counter of the underlying atom * * @param initialState - Optional `[key, value]` pairs (same as `Map` ctor). * @param config - Optional atom configuration. * @returns A `MapAtomType` instance with reactive tracking. * * @example * ```ts * const scores = mapAtom([["alice", { value: 10 }], ["bob", { value: 5 }]]); * * // Replace a value (use set for primitives too) * scores.set("carol", { value: 3 }); * * // Mutate the whole map in one go * scores.update((map) => { * map.get("alice")!.value += 1; * map.delete("bob"); * }); * * // Mutate one entry in place * scores.updateItem("alice", (entry) => { * entry.value *= 2; * }); * ``` */ export declare const mapAtom: (initialState?: [K, V][], config?: AtomConfig) => MapAtomType; //# sourceMappingURL=mapAtom.d.ts.map