File size: 9,521 Bytes
31e8457 e391660 31e8457 e391660 31e8457 e391660 31e8457 e391660 31e8457 e391660 31e8457 e391660 31e8457 e391660 31e8457 e391660 31e8457 e391660 31e8457 e391660 31e8457 e391660 31e8457 e391660 31e8457 e391660 31e8457 e391660 31e8457 e391660 31e8457 e391660 31e8457 e391660 31e8457 e391660 31e8457 e391660 31e8457 e391660 31e8457 e391660 31e8457 e391660 31e8457 e391660 31e8457 e391660 31e8457 e391660 31e8457 e391660 31e8457 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 | /**
* 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.
*
* @since 4.0.0
*/
import * as Context from "../../Context.ts";
import * as Effect from "../../Effect.ts";
import * as Layer from "../../Layer.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.
*
* @category type IDs
* @since 4.0.0
*/
export type TypeId = "~effect/reactivity/AtomRegistry";
/**
* The runtime type id used to identify `AtomRegistry` services and values.
*
* @category type IDs
* @since 4.0.0
*/
export declare const TypeId: TypeId;
/**
* Returns `true` when the value has the `AtomRegistry` type id.
*
* @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.
*
* @category models
* @since 4.0.0
*/
export interface AtomRegistry {
readonly [TypeId]: TypeId;
readonly scheduler: Scheduler;
readonly schedulerAsync: Scheduler;
readonly getNodes: () => ReadonlyMap<Atom.Atom<any> | string, Node<any>>;
readonly get: <A>(atom: Atom.Atom<A>) => A;
readonly mount: <A>(atom: Atom.Atom<A>) => () => void;
readonly refresh: <A>(atom: Atom.Atom<A>) => void;
readonly set: <R, W>(atom: Atom.Writable<R, W>, value: W) => void;
readonly setSerializable: (key: string, encoded: unknown) => void;
readonly modify: <R, W, A>(atom: Atom.Writable<R, W>, f: (_: R) => [returnValue: A, nextValue: W]) => A;
readonly update: <R, W>(atom: Atom.Writable<R, W>, f: (_: R) => W) => void;
readonly subscribe: <A>(atom: Atom.Atom<A>, f: (_: A) => void, options?: {
readonly immediate?: boolean;
}) => () => void;
readonly reset: () => void;
readonly dispose: () => void;
onNodeAdded?: ((node: Node<any>) => void) | undefined;
onNodeRemoved?: ((node: Node<any>) => 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.
*
* @category models
* @since 4.0.0
*/
export interface Node<A> {
readonly atom: Atom.Atom<A>;
readonly value: () => A;
parents: Array<Node<any>>;
children: Array<Node<any>>;
listeners: Set<() => void>;
currentState(): "uninitialized" | "stale" | "valid" | "removed";
}
/**
* 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.
*
* @category constructors
* @since 4.0.0
*/
export declare const make: (options?: {
readonly initialValues?: Iterable<readonly [Atom.Atom<any>, any]> | 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.
*
* @category services
* @since 4.0.0
*/
export declare const AtomRegistry: Context.Service<AtomRegistry, AtomRegistry>;
/**
* Creates a layer that provides an `AtomRegistry` configured with the supplied
* options.
*
* **Details**
*
* The registry is disposed when the layer scope is finalized.
*
* @category layers
* @since 4.0.0
*/
export declare const layerOptions: (options?: {
readonly initialValues?: Iterable<readonly [Atom.Atom<any>, any]> | undefined;
readonly scheduleTask?: ((f: () => void) => () => void) | undefined;
readonly timeoutResolution?: number | undefined;
readonly defaultIdleTTL?: number | undefined;
}) => Layer.Layer<AtomRegistry>;
/**
* The default layer that provides a fresh `AtomRegistry`.
*
* @category layers
* @since 4.0.0
*/
export declare const layer: Layer.Layer<AtomRegistry>;
/**
* 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.
*
* @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.
*
* @category converting
* @since 4.0.0
*/
<A>(atom: Atom.Atom<A>): (self: AtomRegistry) => Stream.Stream<A>;
/**
* 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.
*
* @category converting
* @since 4.0.0
*/
<A>(self: AtomRegistry, atom: Atom.Atom<A>): Stream.Stream<A>;
};
/**
* 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`.
*
* @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`.
*
* @category converting
* @since 4.0.0
*/
<A, E>(atom: Atom.Atom<Result.AsyncResult<A, E>>): (self: AtomRegistry) => Stream.Stream<A, E>;
/**
* 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`.
*
* @category converting
* @since 4.0.0
*/
<A, E>(self: AtomRegistry, atom: Atom.Atom<Result.AsyncResult<A, E>>): Stream.Stream<A, E>;
};
/**
* 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.
*
* @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.
*
* @category converting
* @since 4.0.0
*/
<A, E>(atom: Atom.Atom<Result.AsyncResult<A, E>>, options?: {
readonly suspendOnWaiting?: boolean | undefined;
}): (self: AtomRegistry) => Effect.Effect<A, E>;
/**
* 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.
*
* @category converting
* @since 4.0.0
*/
<A, E>(self: AtomRegistry, atom: Atom.Atom<Result.AsyncResult<A, E>>, options?: {
readonly suspendOnWaiting?: boolean | undefined;
}): Effect.Effect<A, E>;
};
/**
* 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.
*
* @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.
*
* @category converting
* @since 4.0.0
*/
<A>(atom: Atom.Atom<A>): (self: AtomRegistry) => Effect.Effect<void, never, Scope.Scope>;
/**
* 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.
*
* @category converting
* @since 4.0.0
*/
<A>(self: AtomRegistry, atom: Atom.Atom<A>): Effect.Effect<void, never, Scope.Scope>;
};
//# sourceMappingURL=AtomRegistry.d.ts.map |