import type { Atom, WritableAtom } from './atom.mjs'; type AnyValue = unknown; type AnyError = unknown; type AnyAtom = Atom; type OnUnmount = () => void; /** * State tracked for mounted atoms. An atom is considered "mounted" if it has a * subscriber, or is a transitive dependency of another atom that has a * subscriber. * * The mounted state of an atom is freed once it is no longer mounted. */ type Mounted = { /** Set of listeners to notify when the atom value changes. */ readonly l: Set<() => void>; /** Set of mounted atoms that the atom depends on. */ readonly d: Set; /** Set of mounted atoms that depends on the atom. */ readonly t: Set; /** Function to run when the atom is unmounted. */ u?: (batch: Batch) => void; }; /** * Mutable atom state, * tracked for both mounted and unmounted atoms in a store. */ type AtomState = { /** * Map of atoms that the atom depends on. * The map value is the epoch number of the dependency. */ readonly d: Map; /** * Set of atoms with pending promise that depend on the atom. * * This may cause memory leaks, but it's for the capability to continue promises */ readonly p: Set; /** The epoch number of the atom. */ n: number; /** Object to store mounted state of the atom. */ m?: Mounted; /** Atom value */ v?: Value; /** Atom error */ e?: AnyError; /** Indicates that the atom value has been changed */ x?: true; }; type Batch = Readonly<{ /** Atom dependents map */ D: Map>; /** High priority functions */ H: Set<() => void>; /** Medium priority functions */ M: Set<() => void>; /** Low priority functions */ L: Set<() => void>; }>; type StoreArgs = readonly [ getAtomState: (atom: Atom) => AtomState, atomRead: (atom: Atom, ...params: Parameters['read']>) => Value, atomWrite: (atom: WritableAtom, ...params: Parameters['write']>) => Result, atomOnMount: (atom: WritableAtom, setAtom: (...args: Args) => Result) => OnUnmount | void ]; type DevStoreRev4 = { dev4_get_internal_weak_map: () => { get: (atom: AnyAtom) => AtomState | undefined; }; dev4_get_mounted_atoms: () => Set; dev4_restore_atoms: (values: Iterable) => void; }; type Store = { get: (atom: Atom) => Value; set: (atom: WritableAtom, ...args: Args) => Result; sub: (atom: AnyAtom, listener: () => void) => () => void; unstable_derive: (fn: (...args: StoreArgs) => StoreArgs) => Store; }; export type INTERNAL_DevStoreRev4 = DevStoreRev4; export type INTERNAL_PrdStore = Store; type PrdOrDevStore = Store | (Store & DevStoreRev4); export declare const createStore: () => PrdOrDevStore; export declare const getDefaultStore: () => PrdOrDevStore; export {};