/** * Stores and runs atoms for one reactive runtime. * * An `AtomRegistry` evaluates atoms, caches their current values, tracks * dependencies, applies writes and refreshes, manages subscriptions, and * disposes unused nodes. Each registry is independent, so the same atom can hold * different values in different registries. Serializable atom values can also be * preloaded before the first read. * * @stability unstable * @since 4.0.0 */ import * as Context from "../Context.ts"; import * as Effect from "../Effect.ts"; import * as Layer from "../Layer.ts"; import * as Option from "../Option.ts"; import type { Scheduler } from "../Scheduler.ts"; import * as Scope from "../Scope.ts"; import * as Stream from "../Stream.ts"; import * as Result from "./AsyncResult.ts"; import type * as Atom from "./Atom.ts"; /** * The literal type used to identify `AtomRegistry` services and values. * * @stability unstable * @category type IDs * @since 4.0.0 */ export type TypeId = "~effect/reactivity/AtomRegistry"; /** * The runtime type id used to identify `AtomRegistry` services and values. * * @stability unstable * @category type IDs * @since 4.0.0 */ export declare const TypeId: TypeId; /** * Returns `true` when the value has the `AtomRegistry` type id. * * @stability unstable * @category guards * @since 4.0.0 */ export declare const isAtomRegistry: (u: unknown) => u is AtomRegistry; /** * The runtime registry that stores atom nodes and coordinates reads, writes, * refreshes, subscriptions, and disposal. * * **Details** * * It also manages scheduler configuration, serializable preloaded values, and node * addition/removal callbacks. * * @stability unstable * @category models * @since 4.0.0 */ export interface AtomRegistry { readonly [TypeId]: TypeId; readonly scheduler: Scheduler; readonly schedulerAsync: Scheduler; readonly getNodes: () => ReadonlyMap | string, Node>; readonly ensureNode: (atom: Atom.Atom) => Node; readonly get: (atom: Atom.Atom) => A; readonly mount: (atom: Atom.Atom) => () => void; readonly refresh: (atom: Atom.Atom) => void; readonly set: (atom: Atom.Writable, value: W) => void; readonly setSerializable: (key: string, encoded: unknown) => void; readonly preloadedSerializable: Map; readonly modify: (atom: Atom.Writable, f: (_: R) => [returnValue: A, nextValue: W]) => A; readonly update: (atom: Atom.Writable, f: (_: R) => W) => void; readonly subscribe: (atom: Atom.Atom, f: (_: A) => void, options?: { readonly immediate?: boolean; }) => () => void; readonly reset: () => void; readonly dispose: () => void; scheduleNodeRemoval(node: Node): void; onNodeAdded?: ((node: Node) => void) | undefined; onNodeRemoved?: ((node: Node) => void) | undefined; } /** * A registry node for a single atom. * * **Details** * * Nodes expose the current value, parent and child dependency links, listener set, * and current lifecycle state. * * @stability unstable * @category models * @since 4.0.0 */ export interface Node { readonly atom: Atom.Atom; readonly value: () => A; readonly valueOption: () => Option.Option; readonly canBeRemoved: boolean; parents: Set>; children: Set>; listeners: Set<() => void>; currentState(): "uninitialized" | "stale" | "valid" | "removed"; setInitialValue(value: A): void; subscribe(listener: () => void): () => void; } /** * Creates an `AtomRegistry`. * * **Details** * * Options can preload initial atom values, provide a custom task scheduler, * configure timeout bucket resolution, and set a default idle time-to-live for * unused atoms. * * @stability unstable * @category constructors * @since 4.0.0 */ export declare const make: (options?: { readonly initialValues?: Iterable, any, Atom.InitialValueOptions?]> | undefined; readonly scheduleTask?: ((f: () => void) => () => void) | undefined; readonly timeoutResolution?: number | undefined; readonly defaultIdleTTL?: number | undefined; } | undefined) => AtomRegistry; /** * Service tag for the active atom runtime cache. * * **When to use** * * Use to access or provide the registry that stores atom values, * dependencies, subscriptions, and disposal state for a reactive lifetime. * * @stability unstable * @category services * @since 4.0.0 */ export declare const AtomRegistry: Context.Service; /** * Creates a layer that provides an `AtomRegistry` configured with the supplied * options. * * **Details** * * The registry is disposed when the layer scope is finalized. * * @stability unstable * @category layers * @since 4.0.0 */ export declare const layerOptions: (options?: { readonly initialValues?: Iterable, any, Atom.InitialValueOptions?]> | undefined; readonly scheduleTask?: ((f: () => void) => () => void) | undefined; readonly timeoutResolution?: number | undefined; readonly defaultIdleTTL?: number | undefined; }) => Layer.Layer; /** * The default layer that provides a fresh `AtomRegistry`. * * @stability unstable * @category layers * @since 4.0.0 */ export declare const layer: Layer.Layer; /** * Converts an atom in this registry into a stream. * * **Details** * * The stream emits the current value immediately, emits subsequent changes, and * unsubscribes from the registry when the stream scope closes. * * @stability unstable * @category converting * @since 4.0.0 */ export declare const toStream: { /** * Converts an atom in this registry into a stream. * * **Details** * * The stream emits the current value immediately, emits subsequent changes, and * unsubscribes from the registry when the stream scope closes. * * @stability unstable * @category converting * @since 4.0.0 */ (atom: Atom.Atom): (self: AtomRegistry) => Stream.Stream; /** * Converts an atom in this registry into a stream. * * **Details** * * The stream emits the current value immediately, emits subsequent changes, and * unsubscribes from the registry when the stream scope closes. * * @stability unstable * @category converting * @since 4.0.0 */ (self: AtomRegistry, atom: Atom.Atom): Stream.Stream; }; /** * Converts an `AsyncResult` atom in this registry into a stream of successful * values. * * **Details** * * Initial results are skipped, failures fail the stream with their cause, and * duplicate stream values are dropped with `Stream.changes`. * * @stability unstable * @category converting * @since 4.0.0 */ export declare const toStreamResult: { /** * Converts an `AsyncResult` atom in this registry into a stream of successful * values. * * **Details** * * Initial results are skipped, failures fail the stream with their cause, and * duplicate stream values are dropped with `Stream.changes`. * * @stability unstable * @category converting * @since 4.0.0 */ (atom: Atom.Atom>): (self: AtomRegistry) => Stream.Stream; /** * Converts an `AsyncResult` atom in this registry into a stream of successful * values. * * **Details** * * Initial results are skipped, failures fail the stream with their cause, and * duplicate stream values are dropped with `Stream.changes`. * * @stability unstable * @category converting * @since 4.0.0 */ (self: AtomRegistry, atom: Atom.Atom>): Stream.Stream; }; /** * Reads an `AsyncResult` atom from this registry as an effect. * * **Details** * * The effect waits for the result to leave `Initial`, and also waits through * waiting results when `suspendOnWaiting` is enabled. * * @stability unstable * @category converting * @since 4.0.0 */ export declare const getResult: { /** * Reads an `AsyncResult` atom from this registry as an effect. * * **Details** * * The effect waits for the result to leave `Initial`, and also waits through * waiting results when `suspendOnWaiting` is enabled. * * @stability unstable * @category converting * @since 4.0.0 */ (atom: Atom.Atom>, options?: { readonly suspendOnWaiting?: boolean | undefined; }): (self: AtomRegistry) => Effect.Effect; /** * Reads an `AsyncResult` atom from this registry as an effect. * * **Details** * * The effect waits for the result to leave `Initial`, and also waits through * waiting results when `suspendOnWaiting` is enabled. * * @stability unstable * @category converting * @since 4.0.0 */ (self: AtomRegistry, atom: Atom.Atom>, options?: { readonly suspendOnWaiting?: boolean | undefined; }): Effect.Effect; }; /** * Mounts an atom in this registry for the lifetime of the current scope. * * **Details** * * The atom is subscribed with a no-op listener and the subscription is released * when the scope finalizer runs. * * @stability unstable * @category converting * @since 4.0.0 */ export declare const mount: { /** * Mounts an atom in this registry for the lifetime of the current scope. * * **Details** * * The atom is subscribed with a no-op listener and the subscription is released * when the scope finalizer runs. * * @stability unstable * @category converting * @since 4.0.0 */ (atom: Atom.Atom): (self: AtomRegistry) => Effect.Effect; /** * Mounts an atom in this registry for the lifetime of the current scope. * * **Details** * * The atom is subscribed with a no-op listener and the subscription is released * when the scope finalizer runs. * * @stability unstable * @category converting * @since 4.0.0 */ (self: AtomRegistry, atom: Atom.Atom): Effect.Effect; }; //# sourceMappingURL=AtomRegistry.d.ts.map