@but212/atom-effect 0.15.4 → 0.16.1
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/README.md +10 -10
- package/dist/atom-effect.min.js +1 -1
- package/dist/atom-effect.min.js.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +42 -93
- package/dist/index.mjs +678 -742
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -55,30 +55,13 @@ export declare interface AtomOptions {
|
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
/**
|
|
58
|
-
*
|
|
58
|
+
* Groups multiple state updates into a single notification cycle.
|
|
59
|
+
* This optimizes performance by deferring the execution of scheduled effects
|
|
60
|
+
* until the provided callback finishes execution, preventing redundant computations.
|
|
59
61
|
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
* @template T - The return type of the callback function
|
|
65
|
-
* @param callback - The function containing batched updates
|
|
66
|
-
* @returns The result of the callback function
|
|
67
|
-
* @throws {AtomError} If the callback is not a function
|
|
68
|
-
* @throws Propagates any error thrown by the callback function
|
|
69
|
-
*
|
|
70
|
-
* @example
|
|
71
|
-
* ```typescript
|
|
72
|
-
* const firstName = atom('John');
|
|
73
|
-
* const lastName = atom('Doe');
|
|
74
|
-
*
|
|
75
|
-
* // With batching: triggers 1 combined synchronous update at the end
|
|
76
|
-
* batch(() => {
|
|
77
|
-
* firstName.value = 'Jane';
|
|
78
|
-
* lastName.value = 'Smith';
|
|
79
|
-
* });
|
|
80
|
-
* // Changes are guaranteed to be applied here
|
|
81
|
-
* ```
|
|
62
|
+
* @param callback - The function containing state updates to be batched.
|
|
63
|
+
* @returns The value returned by the callback.
|
|
64
|
+
* @throws {AtomError} If the provided callback is not a function.
|
|
82
65
|
*/
|
|
83
66
|
export declare function batch<T>(callback: () => T): T;
|
|
84
67
|
|
|
@@ -95,14 +78,7 @@ export declare type Branded<T, Brand> = T & {
|
|
|
95
78
|
* Context tracked during the computation phase of a reactive node.
|
|
96
79
|
*/
|
|
97
80
|
export declare interface ComputationContext {
|
|
98
|
-
|
|
99
|
-
prevVersions: number[];
|
|
100
|
-
nextDeps: Dependency[];
|
|
101
|
-
nextVersions: number[];
|
|
102
|
-
originalAdd: (dep: Dependency) => void;
|
|
103
|
-
state: {
|
|
104
|
-
depCount: number;
|
|
105
|
-
};
|
|
81
|
+
links: DependencyLink[];
|
|
106
82
|
}
|
|
107
83
|
|
|
108
84
|
/**
|
|
@@ -212,15 +188,6 @@ export declare interface Dependency {
|
|
|
212
188
|
_lastSeenEpoch: number;
|
|
213
189
|
/* Excluded from this release type: _tempUnsub */
|
|
214
190
|
/* Excluded from this release type: _modifiedAtEpoch */
|
|
215
|
-
/* Excluded from this release type: _visitedEpoch */
|
|
216
|
-
/**
|
|
217
|
-
* Calculates the logical distance (shift) between current and cached version.
|
|
218
|
-
* Used for priority scheduling - large shifts indicate stale updates.
|
|
219
|
-
*
|
|
220
|
-
* @param cachedVersion - The previously cached version
|
|
221
|
-
* @returns Non-negative shift distance (0 to 0x3fffffff)
|
|
222
|
-
*/
|
|
223
|
-
getShift(cachedVersion: number): number;
|
|
224
191
|
/**
|
|
225
192
|
* Subscribe to dependency updates
|
|
226
193
|
*/
|
|
@@ -250,27 +217,28 @@ export declare interface DependencyEntry<T extends object = Dependency> {
|
|
|
250
217
|
export declare type DependencyId = Branded<number, 'DependencyId'>;
|
|
251
218
|
|
|
252
219
|
/**
|
|
253
|
-
*
|
|
254
|
-
*
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
220
|
+
* Encapsulates a link to a dependency with its version and subscription.
|
|
221
|
+
* Part of the AOS (Array of Structs) refactoring to improve data cohesion.
|
|
222
|
+
*/
|
|
223
|
+
declare class DependencyLink {
|
|
224
|
+
/** The dependency node being tracked */
|
|
225
|
+
node: Dependency;
|
|
226
|
+
/** The version of the dependency at the time of tracking */
|
|
227
|
+
version: number;
|
|
228
|
+
/** The unsubscription function for the dependency */
|
|
229
|
+
unsub: (() => void) | undefined;
|
|
230
|
+
constructor(node: Dependency, version: number, unsub?: (() => void) | undefined);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Creates and starts a reactive effect that automatically tracks dependencies.
|
|
235
|
+
* The effect function is executed immediately and re-scheduled whenever its
|
|
236
|
+
* reactive dependencies change.
|
|
265
237
|
*
|
|
266
|
-
* @
|
|
267
|
-
*
|
|
268
|
-
*
|
|
269
|
-
*
|
|
270
|
-
* console.log('Count changed:', count.value);
|
|
271
|
-
* return () => console.log('Cleaning up...');
|
|
272
|
-
* });
|
|
273
|
-
* ```
|
|
238
|
+
* @param fn - The function to be executed as a reactive effect.
|
|
239
|
+
* @param options - Configuration options to customize effect behavior (e.g., scheduling, error handling).
|
|
240
|
+
* @returns An effect instance providing control over the effect's lifecycle.
|
|
241
|
+
* @throws {EffectError} If the provided `fn` is not a function.
|
|
274
242
|
*/
|
|
275
243
|
export declare function effect(fn: EffectFunction, options?: EffectOptions): EffectObject;
|
|
276
244
|
|
|
@@ -294,12 +262,8 @@ export declare class EffectError extends AtomError {
|
|
|
294
262
|
* Bundles prev/next state for atomic lifecycle transitions.
|
|
295
263
|
*/
|
|
296
264
|
export declare interface EffectExecutionContext {
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
prevUnsubs: (() => void)[];
|
|
300
|
-
nextDeps: Dependency[];
|
|
301
|
-
nextVersions: number[];
|
|
302
|
-
nextUnsubs: (() => void)[];
|
|
265
|
+
prevLinks: DependencyLink[];
|
|
266
|
+
nextLinks: DependencyLink[];
|
|
303
267
|
}
|
|
304
268
|
|
|
305
269
|
/**
|
|
@@ -415,17 +379,17 @@ export declare interface ReadonlyAtom<T = unknown> {
|
|
|
415
379
|
* Simplified scheduler for reactive updates with double-buffered queue.
|
|
416
380
|
*/
|
|
417
381
|
declare class Scheduler {
|
|
418
|
-
private _queueBuffer;
|
|
382
|
+
private readonly _queueBuffer;
|
|
419
383
|
private _bufferIndex;
|
|
420
384
|
private _size;
|
|
421
385
|
private _epoch;
|
|
422
|
-
private
|
|
386
|
+
private _isProcessing;
|
|
423
387
|
private _isBatching;
|
|
424
|
-
private
|
|
425
|
-
private
|
|
426
|
-
private
|
|
427
|
-
private
|
|
428
|
-
private
|
|
388
|
+
private _batchDepth;
|
|
389
|
+
private _batchQueue;
|
|
390
|
+
private _batchQueueSize;
|
|
391
|
+
private _isFlushingSync;
|
|
392
|
+
private _maxFlushIterations;
|
|
429
393
|
constructor();
|
|
430
394
|
/**
|
|
431
395
|
* Returns the current operational phase of the scheduler.
|
|
@@ -543,27 +507,12 @@ export declare interface Subscriber {
|
|
|
543
507
|
export declare type TransformFunction<T, U> = (value: T) => U;
|
|
544
508
|
|
|
545
509
|
/**
|
|
546
|
-
* Executes a function without tracking any reactive dependencies.
|
|
547
|
-
*
|
|
548
|
-
* This utility allows reading atom values without establishing
|
|
549
|
-
* a dependency relationship, useful for accessing values that
|
|
550
|
-
* shouldn't trigger recomputation when they change.
|
|
551
|
-
*
|
|
552
|
-
* @template T - The return type of the function
|
|
553
|
-
* @param fn - The function to execute without tracking
|
|
554
|
-
* @returns The result of the executed function
|
|
555
|
-
* @throws {AtomError} If the callback is not a function
|
|
556
|
-
* @throws Propagates any error thrown by the callback function
|
|
510
|
+
* Executes a function without tracking any reactive dependencies accessed during its execution.
|
|
511
|
+
* This prevents the calling context from subscribing to any atoms read within the callback.
|
|
557
512
|
*
|
|
558
|
-
* @
|
|
559
|
-
*
|
|
560
|
-
*
|
|
561
|
-
* const doubled = computed(() => {
|
|
562
|
-
* // This read will NOT be tracked as a dependency
|
|
563
|
-
* const untrackedValue = untracked(() => count.value);
|
|
564
|
-
* return untrackedValue * 2;
|
|
565
|
-
* });
|
|
566
|
-
* ```
|
|
513
|
+
* @param fn - The function to execute in an untracked context.
|
|
514
|
+
* @returns The value returned by the provided function.
|
|
515
|
+
* @throws {AtomError} If the provided argument is not a function.
|
|
567
516
|
*/
|
|
568
517
|
export declare function untracked<T>(fn: () => T): T;
|
|
569
518
|
|