@but212/atom-effect 0.30.1 → 0.31.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.
package/dist/index.d.ts CHANGED
@@ -1,3 +1,12 @@
1
+ /**
2
+ * Returns a promise that resolves after the next scheduler flush.
3
+ * This can be used to wait for all asynchronous effects to be processed.
4
+ *
5
+ * @param fn - Optional callback to execute after the flush.
6
+ * @returns A promise that resolves after the flush completes.
7
+ */
8
+ export declare function aeNextTick(fn?: () => void): Promise<void>;
9
+
1
10
  /**
2
11
  * Async operation states for public API and high-level checks.
3
12
  */
@@ -105,7 +114,7 @@ export declare const composeLens: <T extends object, P extends Paths<T>>(lens: W
105
114
 
106
115
  /**
107
116
  * Creates a computed value.
108
- * @param fn - Computation function
117
+ * @param computation - Computation function
109
118
  * @param options - Options object
110
119
  */
111
120
  export declare function computed<T>(fn: () => T, options?: ComputedOptions<T>): ComputedAtom<T>;
@@ -117,7 +126,7 @@ export declare function computed<T>(fn: () => Promise<T>, options: ComputedOptio
117
126
  /**
118
127
  * Computed atom interface.
119
128
  */
120
- export declare interface ComputedAtom<T = unknown> extends ReadonlyAtom<T>, Disposable_2 {
129
+ export declare interface ComputedAtom<T = unknown> extends ReadonlyAtom<T> {
121
130
  /* Excluded from this release type: [BRAND] */
122
131
  readonly state: AsyncStateType;
123
132
  readonly hasError: boolean;
@@ -129,8 +138,6 @@ export declare interface ComputedAtom<T = unknown> extends ReadonlyAtom<T>, Disp
129
138
  readonly errors: readonly Error[];
130
139
  /** Invalidates atom. */
131
140
  invalidate(): void;
132
- dispose(): void;
133
- [Symbol.dispose](): void;
134
141
  }
135
142
 
136
143
  /** Thrown when a computation fails. */
@@ -223,10 +230,6 @@ declare interface Disposable_2 {
223
230
  * Cleans up the object and releases resources.
224
231
  */
225
232
  dispose(): void;
226
- /**
227
- * Support for explicit resource management (TS 5.2+).
228
- */
229
- [Symbol.dispose](): void;
230
233
  }
231
234
  export { Disposable_2 as Disposable }
232
235
 
@@ -259,8 +262,6 @@ export declare type EffectFunction = () => (void | EffectCleanup) | Promise<void
259
262
 
260
263
  export declare interface EffectObject extends Disposable_2 {
261
264
  /* Excluded from this release type: [BRAND] */
262
- dispose(): void;
263
- [Symbol.dispose](): void;
264
265
  run(): void;
265
266
  readonly isDisposed: boolean;
266
267
  readonly executionCount: number;
@@ -329,7 +330,7 @@ export declare type PathValue<T, P extends string> = P extends `${infer K}.${inf
329
330
  /**
330
331
  * Readonly atom interface.
331
332
  */
332
- export declare interface ReadonlyAtom<T = unknown> {
333
+ export declare interface ReadonlyAtom<T = unknown> extends Disposable_2 {
333
334
  /* Excluded from this release type: [BRAND] */
334
335
  /** The current value of the atom. */
335
336
  readonly value: T;
@@ -351,11 +352,7 @@ export declare interface ReadonlyAtom<T = unknown> {
351
352
 
352
353
  /**
353
354
  * The global debug singleton instance.
354
- * Automatically switches between development and production implementations
355
- * based on the environment configuration (IS_DEV).
356
- *
357
- * In production, this becomes a lightweight object with empty methods,
358
- * allowing engines to inline or ignore calls, effectively providing zero overhead.
355
+ * Automatically switches between development and production implementations.
359
356
  *
360
357
  * @public
361
358
  */
@@ -371,26 +368,18 @@ export declare const runtimeDebug: DebugConfig;
371
368
  * - Microsecond-level scheduling via queueMicrotask.
372
369
  */
373
370
  declare class Scheduler_2 {
374
- /** Double buffer to allow scheduling new jobs while processing the current queue. */
375
- private _queueBuffer;
376
- /** Pointer to the currently active buffer for ingestion. */
377
371
  private _bufferIndex;
378
- /** Current size of the active ingestion buffer. */
379
372
  private _size;
380
- /** Current internal epoch for job tagging. */
381
373
  private _epoch;
382
- /** Flag indicating the scheduler is currently draining a microtask loop. */
374
+ private _batchDepth;
375
+ private _batchQueueSize;
376
+ private _maxFlushIterations;
383
377
  private _isProcessing;
384
- /** Flag indicating a synchronous flush (batch end) is currently active. */
385
378
  private _isFlushingSync;
386
- /** Number of active nested batch contexts. */
387
- private _batchDepth;
379
+ private _buffer0;
380
+ private _buffer1;
388
381
  /** Temporary holding area for jobs scheduled during an active batch or sync flush. */
389
382
  private _batchQueue;
390
- /** Current number of jobs in the batch holding area. */
391
- private _batchQueueSize;
392
- /** Maximum allowed internal loop iterations before assuming an infinite loop. */
393
- private _maxFlushIterations;
394
383
  /** Optional callback fired when the scheduler drops jobs due to overflow. */
395
384
  onOverflow: ((droppedCount: number) => void) | null;
396
385
  private readonly _boundRunLoop;
@@ -400,8 +389,7 @@ declare class Scheduler_2 {
400
389
  get isBatching(): boolean;
401
390
  /**
402
391
  * Schedules a job for execution.
403
- * Jobs are deduplicated based on the current epoch; if the same job is scheduled twice
404
- * in the same epoch, the second call is ignored.
392
+ * Jobs are deduplicated based on the current epoch.
405
393
  *
406
394
  * @param callback - The task to be executed.
407
395
  */
@@ -414,26 +402,21 @@ declare class Scheduler_2 {
414
402
  _flushSync(): void;
415
403
  /**
416
404
  * Merges the temporal batch queue into the main active buffer.
417
- * Increments the epoch to allow previously executed jobs to be re-scheduled if needed.
418
405
  */
419
406
  private _mergeBatchQueue;
420
407
  /**
421
408
  * Continuous loop that drains both main and batch queues.
422
- * Processes until all queues are empty or max iterations reached.
423
409
  */
424
410
  private _drainQueue;
425
411
  /** Executes all jobs currently in the primary buffer and swaps buffers. */
426
412
  private _processQueue;
427
- /** Resets the scheduler state on infinite loop detection and notifies via onOverflow. */
413
+ /** Resets the scheduler state on infinite loop detection. */
428
414
  private _handleFlushOverflow;
429
415
  /** Enters a new batching depth. */
430
416
  startBatch(): void;
431
- /**
432
- * Decrements batching depth. If depth reaches 0, triggers a synchronous flush
433
- * to apply all coherent updates collected during the batch.
434
- */
417
+ /** Decrements batching depth. */
435
418
  endBatch(): void;
436
- /** Configures the maximum safety iterations for the flush loop. */
419
+ /** Configures the maximum safety iterations. */
437
420
  setMaxFlushIterations(max: number): void;
438
421
  }
439
422
 
@@ -473,7 +456,7 @@ declare interface SchedulerJobObject {
473
456
 
474
457
  /**
475
458
  * Internal recursive helper for creating deep immutable copies with structural sharing.
476
- * Only clones nodes along the path where changes occur.
459
+ * Optimized for performance: avoids Regex overhead and minimizes object allocations.
477
460
  */
478
461
  export declare function setDeepValue(obj: unknown, keys: string[], index: number, value: unknown): unknown;
479
462
 
@@ -498,13 +481,8 @@ export declare function untracked<T>(fn: () => T): T;
498
481
  /**
499
482
  * Writable atom interface.
500
483
  */
501
- export declare interface WritableAtom<T = unknown> extends ReadonlyAtom<T>, Disposable_2 {
484
+ export declare interface WritableAtom<T = unknown> extends ReadonlyAtom<T> {
502
485
  value: T;
503
- /**
504
- * Cleans up the atom and releases resources.
505
- */
506
- dispose(): void;
507
- [Symbol.dispose](): void;
508
486
  }
509
487
 
510
488
  export { }