@but212/atom-effect 0.1.4 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/README.md +8 -8
  2. package/dist/index.cjs +1 -1
  3. package/dist/index.cjs.map +1 -1
  4. package/dist/index.d.ts +606 -12
  5. package/dist/index.mjs +322 -500
  6. package/dist/index.mjs.map +1 -1
  7. package/package.json +4 -4
  8. package/dist/constants.d.ts +0 -64
  9. package/dist/constants.d.ts.map +0 -1
  10. package/dist/core/atom/atom.d.ts +0 -25
  11. package/dist/core/atom/atom.d.ts.map +0 -1
  12. package/dist/core/atom/index.d.ts +0 -6
  13. package/dist/core/atom/index.d.ts.map +0 -1
  14. package/dist/core/computed/computed-async-handler.d.ts +0 -237
  15. package/dist/core/computed/computed-async-handler.d.ts.map +0 -1
  16. package/dist/core/computed/computed-dependencies.d.ts +0 -173
  17. package/dist/core/computed/computed-dependencies.d.ts.map +0 -1
  18. package/dist/core/computed/computed-handlers.d.ts +0 -285
  19. package/dist/core/computed/computed-handlers.d.ts.map +0 -1
  20. package/dist/core/computed/computed-state-flags.d.ts +0 -335
  21. package/dist/core/computed/computed-state-flags.d.ts.map +0 -1
  22. package/dist/core/computed/index.d.ts +0 -35
  23. package/dist/core/computed/index.d.ts.map +0 -1
  24. package/dist/core/effect/effect.d.ts +0 -64
  25. package/dist/core/effect/effect.d.ts.map +0 -1
  26. package/dist/core/effect/index.d.ts +0 -2
  27. package/dist/core/effect/index.d.ts.map +0 -1
  28. package/dist/core/index.d.ts +0 -4
  29. package/dist/core/index.d.ts.map +0 -1
  30. package/dist/errors/errors.d.ts +0 -118
  31. package/dist/errors/errors.d.ts.map +0 -1
  32. package/dist/errors/messages.d.ts +0 -101
  33. package/dist/errors/messages.d.ts.map +0 -1
  34. package/dist/index.d.ts.map +0 -1
  35. package/dist/scheduler/batch.d.ts +0 -31
  36. package/dist/scheduler/batch.d.ts.map +0 -1
  37. package/dist/scheduler/index.d.ts +0 -3
  38. package/dist/scheduler/index.d.ts.map +0 -1
  39. package/dist/scheduler/scheduler.d.ts +0 -153
  40. package/dist/scheduler/scheduler.d.ts.map +0 -1
  41. package/dist/tracking/context.d.ts +0 -76
  42. package/dist/tracking/context.d.ts.map +0 -1
  43. package/dist/tracking/dependency-manager.d.ts +0 -224
  44. package/dist/tracking/dependency-manager.d.ts.map +0 -1
  45. package/dist/tracking/index.d.ts +0 -5
  46. package/dist/tracking/index.d.ts.map +0 -1
  47. package/dist/tracking/tracking.types.d.ts +0 -12
  48. package/dist/tracking/tracking.types.d.ts.map +0 -1
  49. package/dist/tracking/untracked.d.ts +0 -25
  50. package/dist/tracking/untracked.d.ts.map +0 -1
  51. package/dist/types/atom.d.ts +0 -13
  52. package/dist/types/atom.d.ts.map +0 -1
  53. package/dist/types/common.d.ts +0 -45
  54. package/dist/types/common.d.ts.map +0 -1
  55. package/dist/types/computed.d.ts +0 -18
  56. package/dist/types/computed.d.ts.map +0 -1
  57. package/dist/types/effect.d.ts +0 -13
  58. package/dist/types/effect.d.ts.map +0 -1
  59. package/dist/types/index.d.ts +0 -5
  60. package/dist/types/index.d.ts.map +0 -1
  61. package/dist/utils/debug.d.ts +0 -85
  62. package/dist/utils/debug.d.ts.map +0 -1
  63. package/dist/utils/object-pool.d.ts +0 -159
  64. package/dist/utils/object-pool.d.ts.map +0 -1
  65. package/dist/utils/subscriber-manager.d.ts +0 -127
  66. package/dist/utils/subscriber-manager.d.ts.map +0 -1
  67. package/dist/utils/type-guards.d.ts +0 -5
  68. package/dist/utils/type-guards.d.ts.map +0 -1
package/dist/index.d.ts CHANGED
@@ -1,12 +1,606 @@
1
- /**
2
- * @fileoverview Atom Effect - Main entry point
3
- */
4
- export { AsyncState, DEBUG_CONFIG, POOL_CONFIG, SCHEDULER_CONFIG } from './constants';
5
- export { atom, computed, effect } from './core';
6
- export { AtomError, ComputedError, EffectError, SchedulerError } from './errors/errors';
7
- export { batch, scheduler } from './scheduler';
8
- export { untracked } from './tracking';
9
- export * from './types';
10
- export { debug as DEBUG_RUNTIME } from './utils/debug';
11
- export { isAtom, isComputed, isEffect } from './utils/type-guards';
12
- //# sourceMappingURL=index.d.ts.map
1
+ /**
2
+ * Async computation states for computed atoms
3
+ */
4
+ export declare const AsyncState: {
5
+ IDLE: "idle";
6
+ PENDING: "pending";
7
+ RESOLVED: "resolved";
8
+ REJECTED: "rejected";
9
+ };
10
+
11
+ export declare type AsyncStateType = 'idle' | 'pending' | 'resolved' | 'rejected';
12
+
13
+ /**
14
+ * Creates a new atom with the given initial value.
15
+ *
16
+ * @template T - The type of value stored in the atom
17
+ * @param initialValue - The initial value of the atom
18
+ * @param options - Optional configuration options
19
+ * @returns A writable atom instance
20
+ *
21
+ * @example
22
+ * ```ts
23
+ * // Basic usage
24
+ * const count = atom(0);
25
+ *
26
+ * // With sync option for immediate notifications
27
+ * const syncCount = atom(0, { sync: true });
28
+ *
29
+ * // Reading and writing
30
+ * console.log(count.value); // 0
31
+ * count.value = 5;
32
+ * console.log(count.peek()); // 5 (non-tracking read)
33
+ * ```
34
+ */
35
+ export declare function atom<T>(initialValue: T, options?: AtomOptions): WritableAtom<T>;
36
+
37
+ /**
38
+ * @fileoverview Error class hierarchy for atom-effect library
39
+ * @description Structured error classes with cause tracking and recoverability flags
40
+ */
41
+ /**
42
+ * Base error class for all atom-effect errors
43
+ *
44
+ * Provides enhanced error information including:
45
+ * - Original cause tracking for error chains
46
+ * - Recoverability flag for error handling strategies
47
+ * - Timestamp for debugging and logging
48
+ *
49
+ * @example
50
+ * ```ts
51
+ * throw new AtomError('Invalid state', originalError, false);
52
+ * ```
53
+ */
54
+ export declare class AtomError extends Error {
55
+ /** Original error that caused this error, if any */
56
+ cause: Error | null;
57
+ /** Whether this error can be recovered from */
58
+ recoverable: boolean;
59
+ /** When this error occurred */
60
+ timestamp: Date;
61
+ /**
62
+ * Creates a new AtomError
63
+ * @param message - Error message describing what went wrong
64
+ * @param cause - Original error that caused this error
65
+ * @param recoverable - Whether the operation can be retried
66
+ */
67
+ constructor(message: string, cause?: Error | null, recoverable?: boolean);
68
+ }
69
+
70
+ export declare interface AtomOptions {
71
+ sync?: boolean;
72
+ }
73
+
74
+ /**
75
+ * Executes multiple reactive updates in a single batch.
76
+ *
77
+ * Batching groups multiple state changes together, deferring notifications
78
+ * until all updates are complete. This prevents intermediate states from
79
+ * triggering unnecessary recomputations and improves performance.
80
+ *
81
+ * @template T - The return type of the callback function
82
+ * @param callback - The function containing batched updates
83
+ * @returns The result of the callback function
84
+ * @throws {AtomError} If the callback is not a function
85
+ * @throws {AtomError} If an error occurs during batch execution
86
+ *
87
+ * @example
88
+ * ```typescript
89
+ * const firstName = atom('John');
90
+ * const lastName = atom('Doe');
91
+ *
92
+ * // Without batching: triggers 2 separate updates
93
+ * firstName.value = 'Jane';
94
+ * lastName.value = 'Smith';
95
+ *
96
+ * // With batching: triggers 1 combined update
97
+ * batch(() => {
98
+ * firstName.value = 'Jane';
99
+ * lastName.value = 'Smith';
100
+ * });
101
+ * ```
102
+ */
103
+ export declare function batch<T>(callback: () => T): T;
104
+
105
+ /**
106
+ * Creates a computed value that automatically tracks and reacts to dependencies
107
+ *
108
+ * Computed atoms are derived reactive state that:
109
+ * - Automatically track dependencies accessed during computation
110
+ * - Lazily recompute only when dependencies change (dirty checking)
111
+ * - Support both synchronous and asynchronous computations
112
+ * - Cache results until dependencies change (memoization)
113
+ * - Use bit flags for efficient state management
114
+ * - Provide async state tracking (idle/pending/resolved/rejected)
115
+ *
116
+ * @template T - The type of the computed value
117
+ * @param fn - Computation function (can return T or Promise<T>)
118
+ * @param options - Configuration options
119
+ * @returns A readonly computed atom with automatic dependency tracking
120
+ *
121
+ * @example
122
+ * ```ts
123
+ * // Synchronous computed
124
+ * const count = atom(0);
125
+ * const doubled = computed(() => count.value * 2);
126
+ *
127
+ * // Asynchronous computed with default value
128
+ * const userData = computed(
129
+ * async () => fetch(`/api/user/${userId.value}`).then(r => r.json()),
130
+ * { defaultValue: null }
131
+ * );
132
+ * ```
133
+ */
134
+ export declare function computed<T>(fn: () => T, options?: ComputedOptions<T>): ComputedAtom<T>;
135
+
136
+ export declare function computed<T>(fn: () => Promise<T>, options: ComputedOptions<T> & {
137
+ defaultValue: T;
138
+ }): ComputedAtom<T>;
139
+
140
+ export declare interface ComputedAtom<T = unknown> extends ReadonlyAtom<T> {
141
+ readonly state: AsyncStateType;
142
+ readonly hasError: boolean;
143
+ readonly lastError: Error | null;
144
+ readonly isPending: boolean;
145
+ readonly isResolved: boolean;
146
+ invalidate(): void;
147
+ dispose(): void;
148
+ }
149
+
150
+ /**
151
+ * Error thrown during computed value computation
152
+ *
153
+ * Computed errors are considered recoverable by default since they typically
154
+ * result from transient data issues rather than programming errors.
155
+ */
156
+ export declare class ComputedError extends AtomError {
157
+ /**
158
+ * Creates a new ComputedError
159
+ * @param message - Error message
160
+ * @param cause - Original error
161
+ */
162
+ constructor(message: string, cause?: Error | null);
163
+ }
164
+
165
+ export declare interface ComputedOptions<T = unknown> {
166
+ equal?: (a: T, b: T) => boolean;
167
+ defaultValue?: T;
168
+ lazy?: boolean;
169
+ onError?: (error: Error) => void;
170
+ }
171
+
172
+ /**
173
+ * Debug configuration defaults
174
+ */
175
+ export declare const DEBUG_CONFIG: {
176
+ /** Maximum dependencies before warning about large dependency graphs */
177
+ readonly MAX_DEPENDENCIES: 1000;
178
+ /** Enable infinite loop detection warnings */
179
+ readonly WARN_INFINITE_LOOP: true;
180
+ };
181
+
182
+ /**
183
+ * Debug configuration instance with runtime utilities.
184
+ *
185
+ * Provides development-time features including:
186
+ * - Circular dependency detection (direct and indirect)
187
+ * - Large dependency graph warnings
188
+ * - Debug metadata attachment for inspection
189
+ *
190
+ * @remarks
191
+ * Most features are only active when `NODE_ENV === 'development'`
192
+ * to avoid performance overhead in production builds.
193
+ *
194
+ * @example
195
+ * ```typescript
196
+ * // Check for circular dependencies
197
+ * debug.checkCircular(dependencyAtom, computedAtom);
198
+ *
199
+ * // Warn about potential issues
200
+ * debug.warn(count > 100, 'Large dependency count detected');
201
+ *
202
+ * // Attach debug info to a reactive object
203
+ * debug.attachDebugInfo(atom, 'atom', 42);
204
+ * ```
205
+ */
206
+ export declare const DEBUG_RUNTIME: DebugConfig;
207
+
208
+ /**
209
+ * Debug configuration interface
210
+ */
211
+ export declare interface DebugConfig {
212
+ enabled: boolean;
213
+ maxDependencies: number;
214
+ warnInfiniteLoop: boolean;
215
+ warn(condition: boolean, message: string): void;
216
+ checkCircular(dep: unknown, current: unknown, visited?: Set<unknown>): void;
217
+ attachDebugInfo(obj: object, type: string, id: number): void;
218
+ getDebugName(obj: unknown): string | undefined;
219
+ getDebugType(obj: unknown): string | undefined;
220
+ }
221
+
222
+ /**
223
+ * Interface for subscribable dependencies
224
+ */
225
+ export declare interface Dependency {
226
+ readonly id: number;
227
+ version: number;
228
+ _lastSeenEpoch: number;
229
+ subscribe(listener: (() => void) | Subscriber): () => void;
230
+ peek?(): unknown;
231
+ value?: unknown;
232
+ }
233
+
234
+ /**
235
+ * WeakRef-based dependency entry structure
236
+ */
237
+ export declare interface DependencyEntry<T extends object = Dependency> {
238
+ ref: WeakRef<T>;
239
+ unsubscribe: () => void;
240
+ }
241
+
242
+ /**
243
+ * Creates a reactive effect that automatically re-executes when its dependencies change.
244
+ *
245
+ * @param fn - The effect function to execute. May return a cleanup function
246
+ * or a Promise that resolves to a cleanup function.
247
+ * @param options - Configuration options for the effect
248
+ * @param options.sync - If true, re-executes synchronously on dependency changes.
249
+ * Defaults to false (scheduled/batched execution).
250
+ * @param options.maxExecutionsPerSecond - Maximum executions per second before
251
+ * infinite loop detection triggers.
252
+ * Defaults to `SCHEDULER_CONFIG.MAX_EXECUTIONS_PER_SECOND`.
253
+ * @param options.trackModifications - If true, tracks and warns about dependencies
254
+ * that are both read and modified. Defaults to false.
255
+ *
256
+ * @returns An {@link EffectObject} with `run()`, `dispose()`, and state properties
257
+ *
258
+ * @throws {EffectError} If `fn` is not a function
259
+ *
260
+ * @remarks
261
+ * Effects are the primary way to perform side effects in response to reactive
262
+ * state changes. They automatically track which reactive values (atoms, computed)
263
+ * are accessed during execution and re-run when those values change.
264
+ *
265
+ * The effect function may return a cleanup function that will be called before
266
+ * the next execution or when the effect is disposed. This is useful for
267
+ * cleaning up subscriptions, timers, or other resources.
268
+ *
269
+ * @example
270
+ * Basic usage:
271
+ * ```typescript
272
+ * const counter = atom(0);
273
+ *
274
+ * const fx = effect(() => {
275
+ * console.log('Counter:', counter.value);
276
+ * });
277
+ * // Logs: "Counter: 0"
278
+ *
279
+ * counter.value = 1;
280
+ * // Logs: "Counter: 1"
281
+ *
282
+ * fx.dispose(); // Stop the effect
283
+ * ```
284
+ *
285
+ * @example
286
+ * With cleanup function:
287
+ * ```typescript
288
+ * const fx = effect(() => {
289
+ * const timer = setInterval(() => console.log('tick'), 1000);
290
+ * return () => clearInterval(timer); // Cleanup
291
+ * });
292
+ * ```
293
+ *
294
+ * @example
295
+ * Synchronous execution:
296
+ * ```typescript
297
+ * const fx = effect(
298
+ * () => console.log(counter.value),
299
+ * { sync: true }
300
+ * );
301
+ * ```
302
+ */
303
+ export declare function effect(fn: EffectFunction, options?: EffectOptions): EffectObject;
304
+
305
+ /**
306
+ * Error thrown during effect execution
307
+ *
308
+ * Effect errors are considered non-recoverable by default since effects
309
+ * typically represent critical side effects that shouldn't fail silently.
310
+ */
311
+ export declare class EffectError extends AtomError {
312
+ /**
313
+ * Creates a new EffectError
314
+ * @param message - Error message
315
+ * @param cause - Original error
316
+ */
317
+ constructor(message: string, cause?: Error | null);
318
+ }
319
+
320
+ export declare type EffectFunction = () => void | (() => void) | Promise<undefined | (() => void)>;
321
+
322
+ export declare interface EffectObject {
323
+ dispose(): void;
324
+ run(): void;
325
+ readonly isDisposed: boolean;
326
+ readonly executionCount: number;
327
+ }
328
+
329
+ export declare interface EffectOptions {
330
+ sync?: boolean;
331
+ maxExecutionsPerSecond?: number;
332
+ trackModifications?: boolean;
333
+ }
334
+
335
+ export declare function isAtom(obj: unknown): obj is ReadonlyAtom;
336
+
337
+ export declare function isComputed(obj: unknown): obj is ComputedAtom;
338
+
339
+ export declare function isEffect(obj: unknown): obj is EffectObject;
340
+
341
+ /**
342
+ * Object pool configuration
343
+ * Controls memory management and GC pressure reduction
344
+ */
345
+ export declare const POOL_CONFIG: {
346
+ /** Maximum number of pooled objects to prevent memory bloat */
347
+ readonly MAX_SIZE: 1000;
348
+ /** Number of objects to pre-allocate for performance-critical paths */
349
+ readonly WARMUP_SIZE: 100;
350
+ };
351
+
352
+ /**
353
+ * Interface for poolable objects
354
+ */
355
+ export declare interface Poolable {
356
+ reset(): void;
357
+ }
358
+
359
+ export declare interface ReadonlyAtom<T = unknown> {
360
+ readonly value: T;
361
+ subscribe(listener: (newValue?: T, oldValue?: T) => void): () => void;
362
+ peek(): T;
363
+ }
364
+
365
+ declare class Scheduler {
366
+ /** Queue of callbacks waiting for microtask execution */
367
+ /** Queue buffers for double buffering optimization */
368
+ private queueA;
369
+ private queueB;
370
+ /** Currently active queue receiving new tasks */
371
+ private queue;
372
+ private queueSize;
373
+ /** Epoch for O(1) deduplication */
374
+ private _epoch;
375
+ /** Whether the scheduler is currently processing the queue */
376
+ private isProcessing;
377
+ /** Whether batching is currently active */
378
+ isBatching: boolean;
379
+ /** Current nesting depth of batch operations */
380
+ private batchDepth;
381
+ /** Array of callbacks queued during batching */
382
+ private batchQueue;
383
+ /** Current size of the batch queue (for array reuse) */
384
+ private batchQueueSize;
385
+ /** Whether synchronous flush is in progress */
386
+ private isFlushingSync;
387
+ /** Maximum iterations allowed during flush to prevent infinite loops */
388
+ private maxFlushIterations;
389
+ /**
390
+ * Gets the current phase of the scheduler.
391
+ */
392
+ get phase(): SchedulerPhase;
393
+ /**
394
+ * Schedules a callback for execution.
395
+ *
396
+ * If batching is active or a sync flush is in progress, the callback
397
+ * is added to the batch queue. Otherwise, it's added to the main queue
398
+ * and a flush is triggered via microtask.
399
+ *
400
+ * @param callback - The function to schedule for execution
401
+ * @throws {SchedulerError} If callback is not a function
402
+ *
403
+ * @example
404
+ * ```typescript
405
+ * scheduler.schedule(() => {
406
+ * // This runs in the next microtask (or sync if batching)
407
+ * updateUI();
408
+ * });
409
+ * ```
410
+ */
411
+ schedule(callback: SchedulerJob): void;
412
+ /**
413
+ * Flushes the queue asynchronously via microtask.
414
+ *
415
+ * Executes all queued callbacks in a microtask, allowing the current
416
+ * synchronous execution to complete first. Errors in individual
417
+ * callbacks are caught and logged without interrupting others.
418
+ *
419
+ * @private
420
+ * @remarks
421
+ * This method is idempotent - calling it multiple times while
422
+ * processing is active has no effect.
423
+ */
424
+ private flush;
425
+ /**
426
+ * Flushes all queued callbacks synchronously.
427
+ *
428
+ * This method is called when a batch ends. It processes all callbacks
429
+ * in the batch queue and main queue synchronously, allowing callbacks
430
+ * to schedule additional callbacks that are processed in the same flush.
431
+ *
432
+ * @private
433
+ * @remarks
434
+ * - Includes infinite loop protection via maxFlushIterations
435
+ * - Errors in callbacks are caught and logged individually
436
+ * - The isFlushingSync flag prevents re-entrancy issues
437
+ */
438
+ private flushSync;
439
+ /**
440
+ * Starts a new batch operation.
441
+ *
442
+ * While batching is active, all scheduled callbacks are deferred
443
+ * until endBatch() is called. Batches can be nested - only the
444
+ * outermost endBatch() triggers execution.
445
+ *
446
+ * @example
447
+ * ```typescript
448
+ * scheduler.startBatch();
449
+ * // All updates here are deferred
450
+ * atom1.value = 'a';
451
+ * atom2.value = 'b';
452
+ * scheduler.endBatch(); // Both updates processed together
453
+ * ```
454
+ */
455
+ startBatch(): void;
456
+ /**
457
+ * Ends a batch operation.
458
+ *
459
+ * Decrements the batch depth counter. When depth reaches zero,
460
+ * all queued callbacks are flushed synchronously and batching
461
+ * is disabled.
462
+ *
463
+ * @remarks
464
+ * Safe to call even if startBatch() wasn't called - depth is
465
+ * clamped to zero minimum.
466
+ *
467
+ * @example
468
+ * ```typescript
469
+ * scheduler.startBatch();
470
+ * try {
471
+ * // ... batched operations
472
+ * } finally {
473
+ * scheduler.endBatch(); // Always end batch, even on error
474
+ * }
475
+ * ```
476
+ */
477
+ endBatch(): void;
478
+ /**
479
+ * Sets the maximum number of flush iterations allowed.
480
+ *
481
+ * This limit prevents infinite loops when reactive dependencies
482
+ * form cycles. If exceeded, the queue is cleared and an error
483
+ * is logged.
484
+ *
485
+ * @param max - Maximum iterations (must be at least 10)
486
+ * @throws {SchedulerError} If max is less than 10
487
+ *
488
+ * @example
489
+ * ```typescript
490
+ * // Increase limit for complex dependency graphs
491
+ * scheduler.setMaxFlushIterations(5000);
492
+ * ```
493
+ */
494
+ setMaxFlushIterations(max: number): void;
495
+ }
496
+
497
+ /** Global scheduler instance for reactive updates */
498
+ export declare const scheduler: Scheduler;
499
+
500
+ /**
501
+ * Scheduler configuration
502
+ * Controls batching behavior and performance limits
503
+ */
504
+ export declare const SCHEDULER_CONFIG: {
505
+ /** Maximum effect executions per second to detect infinite loops */
506
+ readonly MAX_EXECUTIONS_PER_SECOND: 100;
507
+ /** Threshold for cleaning up old execution timestamps */
508
+ readonly CLEANUP_THRESHOLD: 100;
509
+ };
510
+
511
+ /**
512
+ * Error thrown by the scheduler system
513
+ *
514
+ * Scheduler errors indicate fundamental issues with the batching/scheduling
515
+ * mechanism and are considered non-recoverable.
516
+ */
517
+ export declare class SchedulerError extends AtomError {
518
+ /**
519
+ * Creates a new SchedulerError
520
+ * @param message - Error message
521
+ * @param cause - Original error
522
+ */
523
+ constructor(message: string, cause?: Error | null);
524
+ }
525
+
526
+ declare type SchedulerJob = (() => void) & {
527
+ _nextEpoch?: number;
528
+ };
529
+
530
+ /**
531
+ * Scheduler for managing reactive updates and batching operations.
532
+ *
533
+ * The Scheduler is responsible for coordinating when reactive computations
534
+ * are executed. It supports both immediate (microtask) execution and
535
+ * batched synchronous execution for optimal performance.
536
+ *
537
+ * Key features:
538
+ * - Deduplication of callbacks via Set
539
+ * - Nested batch support with depth tracking
540
+ * - Infinite loop protection with configurable iteration limit
541
+ * - Error isolation to prevent one callback from breaking others
542
+ *
543
+ * @example
544
+ * ```typescript
545
+ * // Schedule a callback for microtask execution
546
+ * scheduler.schedule(() => console.log('Updated!'));
547
+ *
548
+ * // Batch multiple updates
549
+ * scheduler.startBatch();
550
+ * scheduler.schedule(() => console.log('Update 1'));
551
+ * scheduler.schedule(() => console.log('Update 2'));
552
+ * scheduler.endBatch(); // Both execute synchronously here
553
+ * ```
554
+ */
555
+ /**
556
+ * Phases of the scheduler execution cycle.
557
+ */
558
+ declare enum SchedulerPhase {
559
+ IDLE = 0,
560
+ BATCHING = 1,
561
+ FLUSHING = 2
562
+ }
563
+
564
+ /**
565
+ * Subscriber interface for dependency notifications
566
+ */
567
+ export declare interface Subscriber {
568
+ execute(): void;
569
+ }
570
+
571
+ /**
572
+ * Transform function type
573
+ */
574
+ export declare type TransformFunction<T, U> = (value: T) => U;
575
+
576
+ /**
577
+ * Executes a function without tracking any reactive dependencies.
578
+ *
579
+ * This utility allows reading atom values without establishing
580
+ * a dependency relationship, useful for accessing values that
581
+ * shouldn't trigger recomputation when they change.
582
+ *
583
+ * @template T - The return type of the function
584
+ * @param fn - The function to execute without tracking
585
+ * @returns The result of the executed function
586
+ * @throws {AtomError} If the callback is not a function
587
+ * @throws {AtomError} If an error occurs during execution
588
+ *
589
+ * @example
590
+ * ```typescript
591
+ * const count = atom(0);
592
+ * const doubled = computed(() => {
593
+ * // This read will NOT be tracked as a dependency
594
+ * const untrackedValue = untracked(() => count.value);
595
+ * return untrackedValue * 2;
596
+ * });
597
+ * ```
598
+ */
599
+ export declare function untracked<T>(fn: () => T): T;
600
+
601
+ export declare interface WritableAtom<T = unknown> extends ReadonlyAtom<T> {
602
+ value: T;
603
+ dispose(): void;
604
+ }
605
+
606
+ export { }