import type { Canonical } from "atom.io/foundations/canonical" import { IMPLICIT, setIntoStore } from "atom.io/internal" import type { WritableFamilyToken, WritableToken } from "./tokens.ts" /** * A function that sets the value of a state. * @param oldValue - The current value of the state. * @returns * The new value of the state. */ export type Setter = (oldValue: T) => T /** * Set the value of a state into the implicit store. * @param token - An atom or writable selector token. * @param value - The new value of the state. * @overload Default * @default */ export function setState( token: WritableToken, value: Setter | TT, ): void /** * Set the value of a state into the implicit store. * @param token - An atom family or writable selector family token. * @param key - The unique key of the state to set. * @param value - The new value of the state. * @overload Streamlined */ export function setState( token: WritableFamilyToken, key: NoInfer, value: Setter | TT, ): void export function setState( ...params: | [ token: WritableFamilyToken, key: NoInfer, value: Setter | TT, ] | [token: WritableToken, value: Setter | TT] ): void { setIntoStore(IMPLICIT.STORE, ...params) }