import { type AtomConfig } from "./atom"; /** * A reactive `Set` returned by `setAtom`. * * Extends the standard `Set` with two extra mutation methods: * * - `update(fn)` — pass the live set instance into `fn` so you can * call any Set method directly (add/delete/clear/has). * `fn` returns nothing; mutations are in-place. * One notification fires after `fn` returns. * * - `updateItem(item, fn)` — find the object stored at `item` (by reference) * and pass it to `fn` for in-place mutation. * Only meaningful when `T` is an object type. * Use `set.delete(old); set.add(new)` to replace * primitive values. */ export type SetAtomType = Set & { /** * Receive the live `Set` instance and mutate it directly. * `fn` may call any Set method (`add`, `delete`, `clear`, `has`, …). * No return value — mutations are in-place. * One reactive notification fires after `fn` returns. * * ```ts * const ids = setAtom([1, 2, 3]); * * ids.update((set) => { * set.add(4); * set.delete(1); * }); * ``` * * @param fn - Receives the live set and should mutate it in place. * @returns The set instance for chaining. */ update(fn: (set: Set) => void): SetAtomType; /** * Find `item` in the set (by reference) and pass it to `fn` for in-place * mutation. `fn` returns nothing — the object is mutated directly. * One reactive notification fires after `fn` returns. * * Only meaningful when `T` is an object type. Because Set uses reference * equality the mutated object stays in the set automatically — no * delete/re-add needed. * No-op when `item` is not an object or is `null`. * * ```ts * const alice = { id: 1, name: "Alice", score: 0 }; * const users = setAtom([alice, { id: 2, name: "Bob", score: 5 }]); * * users.updateItem(alice, (user) => { * user.score += 10; * user.name = user.name.toUpperCase(); * }); * * // alice is still in the set, now { id: 1, name: "ALICE", score: 10 } * ``` * * @param item - The object already stored in the set (matched by reference). * @param fn - Receives the item and should mutate it in place. * @returns The set instance for chaining. */ updateItem(item: T, fn: (item: T) => void): SetAtomType; }; /** * Creates a reactive `Set` whose mutations automatically notify subscribers. * * **Mutations** — each triggers a notification so subscribers are informed: * - `add(value)`, `delete(value)`, `clear()` * - `update(fn)` — in-place whole-set mutation * - `updateItem(item, fn)` — in-place mutation of a single object item * * **Reads** — each registers a reactive dependency: * - `has(value)`, `size`, `entries()`, `values()`, `keys()`, * `forEach()`, `[Symbol.iterator]()` * * The underlying atom is accessible via two non-enumerable properties: * - `s.__isAtom___` — the raw `AtomType>` for manual subscriptions * - `s.__version__` — current version counter of the underlying atom * * @param initialState - Optional array of initial values (defaults to `[]`). * @param config - Optional atom configuration. * @returns A `SetAtomType` instance with reactive tracking. * * @example * ```ts * const tags = setAtom(["typescript", "javascript"]); * * // Replace / add primitives * tags.add("rust"); * tags.delete("javascript"); * * // Mutate the whole set in one go * tags.update((set) => { * set.add("go"); * set.delete("typescript"); * }); * * // Mutate one object item in place * const user = { id: 1, name: "Alice" }; * const users = setAtom([user]); * users.updateItem(user, (u) => { u.name = "ALICE"; }); * ``` */ export declare const setAtom: (initialState?: T[], config?: AtomConfig) => SetAtomType; //# sourceMappingURL=setAtom.d.ts.map