@estjs/signals 0.0.15-beta.13 → 0.0.15-beta.17
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/signals.cjs.js +3 -3
- package/dist/signals.cjs.js.map +1 -1
- package/dist/signals.d.cts +170 -184
- package/dist/signals.d.ts +170 -184
- package/dist/signals.dev.cjs.js +462 -337
- package/dist/signals.dev.esm.js +462 -337
- package/dist/signals.esm.js +3 -3
- package/dist/signals.esm.js.map +1 -1
- package/package.json +2 -2
package/dist/signals.d.ts
CHANGED
|
@@ -215,21 +215,29 @@ interface ReactiveNode {
|
|
|
215
215
|
*/
|
|
216
216
|
onTrack?: (event: DebuggerEvent) => void;
|
|
217
217
|
/**
|
|
218
|
-
* Optional debugging hook called when reactive changes are triggered
|
|
218
|
+
* Optional debugging hook called when reactive changes are triggered.
|
|
219
219
|
*/
|
|
220
220
|
onTrigger?: (event: DebuggerEvent) => void;
|
|
221
|
+
/**
|
|
222
|
+
* When true, this node is a pure dependency (leaf); it should not receive
|
|
223
|
+
* a DIRTY flag during invalidation because it has no derived value to recompute.
|
|
224
|
+
*/
|
|
225
|
+
isDep?: boolean;
|
|
226
|
+
/**
|
|
227
|
+
* Deduplication stamp used during batch notification.
|
|
228
|
+
* Prevents the same effect from being pushed into the pending queue twice.
|
|
229
|
+
*/
|
|
230
|
+
_triggerVersion?: number;
|
|
221
231
|
}
|
|
222
232
|
/**
|
|
223
|
-
* Execute function with tracking disabled
|
|
224
|
-
*
|
|
225
|
-
* During function execution, accessing Signals won't establish dependencies.
|
|
233
|
+
* Execute function with tracking disabled.
|
|
226
234
|
*
|
|
227
|
-
* @param fn - The function to execute
|
|
228
|
-
* @returns The function's return value
|
|
235
|
+
* @param fn - The function to execute.
|
|
236
|
+
* @returns {T} The function's return value.
|
|
229
237
|
*/
|
|
230
238
|
declare function untrack<T>(fn: () => T): T;
|
|
231
239
|
/**
|
|
232
|
-
* Trigger updates for subscribers of a reactive object property
|
|
240
|
+
* Trigger updates for subscribers of a reactive object property.
|
|
233
241
|
*
|
|
234
242
|
* This function notifies all subscribers (effects/computed) that depend on a specific
|
|
235
243
|
* property of a reactive object that the property has changed.
|
|
@@ -250,11 +258,11 @@ declare function untrack<T>(fn: () => T): T;
|
|
|
250
258
|
* - **CLEAR**: Collection cleared (affects iteration)
|
|
251
259
|
*
|
|
252
260
|
* ## Iteration Dependencies
|
|
253
|
-
|
|
254
|
-
* @param target - The reactive object that changed
|
|
255
|
-
* @param type - The type of operation: 'SET' | 'ADD' | 'DELETE' | 'CLEAR'
|
|
256
|
-
* @param key - The property key that changed (optional for CLEAR operations)
|
|
257
|
-
* @param newValue - The new value
|
|
261
|
+
*
|
|
262
|
+
* @param target - The reactive object that changed.
|
|
263
|
+
* @param type - The type of operation: 'SET' | 'ADD' | 'DELETE' | 'CLEAR'.
|
|
264
|
+
* @param key - The property key that changed (optional for CLEAR operations).
|
|
265
|
+
* @param newValue - The new value.
|
|
258
266
|
*
|
|
259
267
|
* @example
|
|
260
268
|
* ```typescript
|
|
@@ -276,6 +284,15 @@ declare function untrack<T>(fn: () => T): T;
|
|
|
276
284
|
* // trigger(state.items, 'ADD', '3', 4)
|
|
277
285
|
* ```
|
|
278
286
|
*/
|
|
287
|
+
/**
|
|
288
|
+
* Trigger updates for subscribers of a reactive object property.
|
|
289
|
+
*
|
|
290
|
+
* @param target - The reactive object that changed.
|
|
291
|
+
* @param type - The type of operation: 'SET' | 'ADD' | 'DELETE' | 'CLEAR'.
|
|
292
|
+
* @param key - The property key that changed (optional for CLEAR operations).
|
|
293
|
+
* @param newValue - The new value.
|
|
294
|
+
* @returns {void}
|
|
295
|
+
*/
|
|
279
296
|
declare function trigger(target: object, type: string, key?: string | symbol | (string | symbol)[], newValue?: unknown): void;
|
|
280
297
|
|
|
281
298
|
/**
|
|
@@ -337,9 +354,9 @@ type SignalType<T> = T extends Signal<infer V> ? V : never;
|
|
|
337
354
|
* Create a new signal with the given initial value.
|
|
338
355
|
* The signal will track all nested properties of object values.
|
|
339
356
|
*
|
|
340
|
-
* @template T - The type of value to store in the signal
|
|
341
|
-
* @param value - Initial value (defaults to undefined)
|
|
342
|
-
* @returns A new signal instance
|
|
357
|
+
* @template T - The type of value to store in the signal.
|
|
358
|
+
* @param value - Initial value (defaults to undefined).
|
|
359
|
+
* @returns A new signal instance.
|
|
343
360
|
*
|
|
344
361
|
* @example
|
|
345
362
|
* ```typescript
|
|
@@ -348,15 +365,14 @@ type SignalType<T> = T extends Signal<infer V> ? V : never;
|
|
|
348
365
|
* const empty = signal(); // undefined
|
|
349
366
|
* ```
|
|
350
367
|
*/
|
|
351
|
-
declare function signal<T>(value: Signal<T>): Signal<T>;
|
|
352
368
|
declare function signal<T>(value?: T): Signal<T>;
|
|
353
369
|
/**
|
|
354
370
|
* Create a new shallow signal with the given initial value.
|
|
355
371
|
* Only the top-level properties of object values are reactive.
|
|
356
372
|
*
|
|
357
|
-
* @template T - The type of value to store in the signal
|
|
358
|
-
* @param value - Initial value (defaults to undefined)
|
|
359
|
-
* @returns A new shallow signal instance
|
|
373
|
+
* @template T - The type of value to store in the signal.
|
|
374
|
+
* @param value - Initial value (defaults to undefined).
|
|
375
|
+
* @returns A new shallow signal instance.
|
|
360
376
|
*
|
|
361
377
|
* @example
|
|
362
378
|
* ```typescript
|
|
@@ -364,14 +380,13 @@ declare function signal<T>(value?: T): Signal<T>;
|
|
|
364
380
|
* // Only state.nested is reactive, not state.nested.value
|
|
365
381
|
* ```
|
|
366
382
|
*/
|
|
367
|
-
declare function shallowSignal<T>(value: Signal<T>): Signal<T>;
|
|
368
383
|
declare function shallowSignal<T>(value?: T): Signal<T>;
|
|
369
384
|
/**
|
|
370
385
|
* Type guard to check if a value is a Signal instance.
|
|
371
386
|
*
|
|
372
|
-
* @template T - The type of value held by the signal
|
|
373
|
-
* @param value - The value to check
|
|
374
|
-
* @returns true if the value is a Signal instance
|
|
387
|
+
* @template T - The type of value held by the signal.
|
|
388
|
+
* @param value - The value to check.
|
|
389
|
+
* @returns true if the value is a Signal instance.
|
|
375
390
|
*/
|
|
376
391
|
declare function isSignal<T>(value: unknown): value is Signal<T>;
|
|
377
392
|
|
|
@@ -451,25 +466,30 @@ declare class ComputedImpl<T = any> implements Computed<T>, ReactiveNode {
|
|
|
451
466
|
readonly onTrigger?: (event: DebuggerEvent) => void;
|
|
452
467
|
private _value;
|
|
453
468
|
/**
|
|
454
|
-
* Create a Computed instance
|
|
469
|
+
* Create a Computed instance.
|
|
455
470
|
*
|
|
456
|
-
* @param getter - The computation function
|
|
457
|
-
* @param setter - Optional setter function
|
|
458
|
-
* @param onTrack - Optional debug callback for dependency tracking
|
|
459
|
-
* @param onTrigger - Optional debug callback for triggers
|
|
471
|
+
* @param getter - The computation function.
|
|
472
|
+
* @param setter - Optional setter function.
|
|
473
|
+
* @param onTrack - Optional debug callback for dependency tracking.
|
|
474
|
+
* @param onTrigger - Optional debug callback for triggers.
|
|
460
475
|
*/
|
|
461
476
|
constructor(getter: ComputedGetter<T>, setter?: ComputedSetter<T>, onTrack?: (event: DebuggerEvent) => void, onTrigger?: (event: DebuggerEvent) => void);
|
|
477
|
+
/**
|
|
478
|
+
* Returns the current value.
|
|
479
|
+
*
|
|
480
|
+
* @returns {T} The current value.
|
|
481
|
+
*/
|
|
462
482
|
get value(): T;
|
|
463
483
|
/**
|
|
464
|
-
* Set value (only effective when setter is provided)
|
|
484
|
+
* Set value (only effective when setter is provided).
|
|
465
485
|
*
|
|
466
|
-
* @param newValue - The new value
|
|
486
|
+
* @param newValue - The new value.
|
|
467
487
|
*/
|
|
468
488
|
set value(newValue: T);
|
|
469
489
|
/**
|
|
470
|
-
* Read value without tracking dependencies
|
|
490
|
+
* Read value without tracking dependencies.
|
|
471
491
|
*
|
|
472
|
-
* @returns
|
|
492
|
+
* @returns {T} The current value.
|
|
473
493
|
*/
|
|
474
494
|
peek(): T;
|
|
475
495
|
/**
|
|
@@ -485,19 +505,19 @@ declare class ComputedImpl<T = any> implements Computed<T>, ReactiveNode {
|
|
|
485
505
|
*/
|
|
486
506
|
private recompute;
|
|
487
507
|
/**
|
|
488
|
-
* Check if update is needed
|
|
508
|
+
* Check if update is needed.
|
|
489
509
|
*
|
|
490
510
|
* Internal use, called by reactive system.
|
|
491
511
|
*
|
|
492
|
-
* @returns
|
|
512
|
+
* @returns {boolean} True if value changed.
|
|
493
513
|
*/
|
|
494
514
|
shouldUpdate(): boolean;
|
|
495
515
|
}
|
|
496
516
|
/**
|
|
497
|
-
* Create a Computed value
|
|
517
|
+
* Create a Computed value.
|
|
498
518
|
*
|
|
499
|
-
* @param getterOrOptions - Computation function or configuration object
|
|
500
|
-
* @returns Computed instance
|
|
519
|
+
* @param getterOrOptions - Computation function or configuration object.
|
|
520
|
+
* @returns {ComputedImpl<T>} Computed instance.
|
|
501
521
|
*
|
|
502
522
|
* @example
|
|
503
523
|
* ```typescript
|
|
@@ -528,10 +548,11 @@ declare class ComputedImpl<T = any> implements Computed<T>, ReactiveNode {
|
|
|
528
548
|
*/
|
|
529
549
|
declare function computed<T>(getterOrOptions: ComputedGetter<T> | ComputedOptions<T>): ComputedImpl<T>;
|
|
530
550
|
/**
|
|
531
|
-
* Type guard - Check if value is Computed
|
|
551
|
+
* Type guard - Check if value is a Computed instance.
|
|
532
552
|
*
|
|
533
|
-
* @
|
|
534
|
-
* @
|
|
553
|
+
* @template T - The type of value held by the computed instance.
|
|
554
|
+
* @param value - The value to check.
|
|
555
|
+
* @returns {boolean} True if value is a Computed instance.
|
|
535
556
|
*/
|
|
536
557
|
declare function isComputed<T>(value: unknown): value is Computed<T>;
|
|
537
558
|
|
|
@@ -540,22 +561,22 @@ declare function isComputed<T>(value: unknown): value is Computed<T>;
|
|
|
540
561
|
* Recursively unwraps nested reactive objects and arrays.
|
|
541
562
|
*
|
|
542
563
|
* @param value - Reactive or signal value.
|
|
543
|
-
* @returns Raw value without any reactive wrapping.
|
|
564
|
+
* @returns {T} Raw value without any reactive wrapping.
|
|
544
565
|
*/
|
|
545
566
|
declare function toRaw<T>(value: T): T;
|
|
546
567
|
/**
|
|
547
568
|
* Check if the target object is reactive.
|
|
548
569
|
*
|
|
549
570
|
* @param target - The object to check.
|
|
550
|
-
* @returns True if the object is reactive, false otherwise.
|
|
571
|
+
* @returns {boolean} True if the object is reactive, false otherwise.
|
|
551
572
|
*/
|
|
552
573
|
declare function isReactive(target: unknown): boolean;
|
|
553
574
|
/**
|
|
554
575
|
* Create a reactive proxy for the given target object. If the object is already reactive, return directly.
|
|
555
576
|
*
|
|
556
|
-
* @template T - The type of the object to make reactive
|
|
557
|
-
* @param target - The object to make reactive
|
|
558
|
-
* @returns The reactive proxy of the target object
|
|
577
|
+
* @template T - The type of the object to make reactive.
|
|
578
|
+
* @param target - The object to make reactive.
|
|
579
|
+
* @returns {T} The reactive proxy of the target object.
|
|
559
580
|
*
|
|
560
581
|
* @example
|
|
561
582
|
* ```typescript
|
|
@@ -567,9 +588,9 @@ declare function reactive<T extends object>(target: T): T;
|
|
|
567
588
|
/**
|
|
568
589
|
* Create a shallow reactive proxy for the given object. Only root-level properties are reactive.
|
|
569
590
|
*
|
|
570
|
-
* @template T - The type of the object to make shallow reactive
|
|
571
|
-
* @param target - The object to make shallow reactive
|
|
572
|
-
* @returns The shallow reactive proxy of the object
|
|
591
|
+
* @template T - The type of the object to make shallow reactive.
|
|
592
|
+
* @param target - The object to make shallow reactive.
|
|
593
|
+
* @returns {T} The shallow reactive proxy of the object.
|
|
573
594
|
*
|
|
574
595
|
* @example
|
|
575
596
|
* ```typescript
|
|
@@ -582,7 +603,7 @@ declare function shallowReactive<T extends object>(target: T): T;
|
|
|
582
603
|
* Check if the target object is a shallow reactive proxy.
|
|
583
604
|
*
|
|
584
605
|
* @param value - The object to check.
|
|
585
|
-
* @returns True if the object is shallow reactive, false otherwise.
|
|
606
|
+
* @returns {boolean} True if the object is shallow reactive, false otherwise.
|
|
586
607
|
*/
|
|
587
608
|
declare function isShallow(value: unknown): boolean;
|
|
588
609
|
/**
|
|
@@ -590,6 +611,7 @@ declare function isShallow(value: unknown): boolean;
|
|
|
590
611
|
* If the given value is not an object, return the original value itself.
|
|
591
612
|
*
|
|
592
613
|
* @param value - The value that needs a reactive proxy created for it.
|
|
614
|
+
* @returns {T} The reactive proxy of the value, or the original value.
|
|
593
615
|
*/
|
|
594
616
|
declare const toReactive: <T extends unknown>(value: T) => T;
|
|
595
617
|
/**
|
|
@@ -616,29 +638,22 @@ type PreFlushCallback = () => void;
|
|
|
616
638
|
*/
|
|
617
639
|
type FlushTiming = 'pre' | 'post' | 'sync';
|
|
618
640
|
/**
|
|
619
|
-
* Schedules a function to be executed in the next microtask
|
|
620
|
-
*
|
|
621
|
-
* If no function is provided, returns a Promise that resolves in the next microtask.
|
|
622
|
-
* This is useful for waiting until the DOM is update or deferring execution.
|
|
641
|
+
* Schedules a function to be executed in the next microtask.
|
|
623
642
|
*
|
|
624
|
-
* @param fn - Optional function to execute
|
|
625
|
-
* @returns A Promise that resolves after the function execution
|
|
643
|
+
* @param fn - Optional function to execute.
|
|
644
|
+
* @returns A Promise that resolves after the function execution.
|
|
626
645
|
*/
|
|
627
646
|
declare function nextTick(fn?: () => void): Promise<void>;
|
|
628
647
|
/**
|
|
629
|
-
* Adds a job to the main queue and ensures it will be executed
|
|
648
|
+
* Adds a job to the main queue and ensures it will be executed.
|
|
630
649
|
*
|
|
631
|
-
*
|
|
632
|
-
* This is useful for batching updates and avoiding redundant work.
|
|
633
|
-
* @param job - The job to enqueue
|
|
650
|
+
* @param job - The job to enqueue.
|
|
634
651
|
*/
|
|
635
652
|
declare function queueJob(job: Job): void;
|
|
636
653
|
/**
|
|
637
|
-
* Adds a callback to be executed before the main queue processing
|
|
654
|
+
* Adds a callback to be executed before the main queue processing.
|
|
638
655
|
*
|
|
639
|
-
*
|
|
640
|
-
* such as computing derived values or preparing state.
|
|
641
|
-
* @param cb - The callback to execute before the main queue
|
|
656
|
+
* @param cb - The callback to execute before the main queue.
|
|
642
657
|
*/
|
|
643
658
|
declare function queuePreFlushCb(cb: PreFlushCallback): void;
|
|
644
659
|
|
|
@@ -750,82 +765,66 @@ declare class EffectImpl<T = any> implements ReactiveNode {
|
|
|
750
765
|
flag: ReactiveFlags;
|
|
751
766
|
private readonly [SignalFlags.IS_EFFECT];
|
|
752
767
|
readonly fn: EffectFunction<T>;
|
|
753
|
-
readonly
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
readonly flash?: 'sync' | 'pre' | 'post';
|
|
768
|
+
readonly options?: EffectOptions;
|
|
769
|
+
private _flushScheduler?;
|
|
770
|
+
onTrack?: (event: DebuggerEvent) => void;
|
|
771
|
+
onTrigger?: (event: DebuggerEvent) => void;
|
|
758
772
|
private _active;
|
|
759
773
|
/**
|
|
760
|
-
* Create an Effect instance
|
|
774
|
+
* Create an Effect instance.
|
|
761
775
|
*
|
|
762
|
-
* @param fn - The effect function
|
|
763
|
-
* @param options - Configuration options
|
|
776
|
+
* @param fn - The effect function.
|
|
777
|
+
* @param options - Configuration options.
|
|
764
778
|
*/
|
|
765
779
|
constructor(fn: EffectFunction<T>, options?: EffectOptions);
|
|
766
780
|
/**
|
|
767
|
-
* Check if the Effect is active
|
|
781
|
+
* Check if the Effect is active.
|
|
782
|
+
*
|
|
783
|
+
* @returns {boolean} True if the effect is active.
|
|
768
784
|
*/
|
|
769
785
|
get active(): boolean;
|
|
770
786
|
/**
|
|
771
|
-
* Check if the Effect is dirty (needs re-execution)
|
|
772
|
-
|
|
787
|
+
* Check if the Effect is dirty (needs re-execution).
|
|
788
|
+
*
|
|
789
|
+
* @returns {boolean} True if the effect is dirty.
|
|
773
790
|
*/
|
|
774
791
|
get dirty(): boolean;
|
|
775
792
|
/**
|
|
776
|
-
* Pause Effect execution
|
|
793
|
+
* Pause Effect execution.
|
|
777
794
|
*
|
|
778
795
|
* When an effect is paused:
|
|
779
|
-
* - It stops responding to dependency changes
|
|
780
|
-
* - Notifications are ignored (see notify method)
|
|
781
|
-
* - DIRTY and PENDING flags are still set when dependencies change
|
|
782
|
-
* - The effect remains active and maintains its dependency links
|
|
796
|
+
* - It stops responding to dependency changes.
|
|
797
|
+
* - Notifications are ignored (see notify method).
|
|
798
|
+
* - DIRTY and PENDING flags are still set when dependencies change.
|
|
799
|
+
* - The effect remains active and maintains its dependency links.
|
|
783
800
|
*
|
|
784
801
|
* Use cases:
|
|
785
|
-
* - Temporarily disable effects during bulk updates
|
|
786
|
-
* - Prevent effects from running during initialization
|
|
787
|
-
* - Control when side effects should execute
|
|
788
|
-
*
|
|
789
|
-
* @example
|
|
790
|
-
* ```typescript
|
|
791
|
-
* const count = signal(0);
|
|
792
|
-
* const runner = effect(() => console.log(count.value));
|
|
802
|
+
* - Temporarily disable effects during bulk updates.
|
|
803
|
+
* - Prevent effects from running during initialization.
|
|
804
|
+
* - Control when side effects should execute.
|
|
793
805
|
*
|
|
794
|
-
*
|
|
795
|
-
* count.value = 1; // Effect won't run
|
|
796
|
-
* count.value = 2; // Effect won't run
|
|
797
|
-
* runner.effect.resume(); // Effect runs once with latest value
|
|
798
|
-
* ```
|
|
806
|
+
* @returns {void}
|
|
799
807
|
*/
|
|
800
808
|
pause(): void;
|
|
801
809
|
/**
|
|
802
|
-
* Resume Effect execution
|
|
810
|
+
* Resume Effect execution.
|
|
803
811
|
*
|
|
804
812
|
* When an effect is resumed:
|
|
805
|
-
* - The PAUSED flag is cleared
|
|
813
|
+
* - The PAUSED flag is cleared.
|
|
806
814
|
* - If dependencies changed during pause (DIRTY or PENDING flags set),
|
|
807
|
-
* the effect executes immediately via notify()
|
|
808
|
-
* - If no changes occurred, the effect simply becomes active again
|
|
815
|
+
* the effect executes immediately via notify().
|
|
816
|
+
* - If no changes occurred, the effect simply becomes active again.
|
|
809
817
|
*
|
|
810
818
|
* State management:
|
|
811
|
-
* - Clears PAUSED flag atomically
|
|
812
|
-
* - Checks for accumulated DIRTY/PENDING flags
|
|
813
|
-
* - Triggers execution if needed
|
|
814
|
-
*
|
|
815
|
-
* @example
|
|
816
|
-
* ```typescript
|
|
817
|
-
* const count = signal(0);
|
|
818
|
-
* const runner = effect(() => console.log(count.value));
|
|
819
|
+
* - Clears PAUSED flag atomically.
|
|
820
|
+
* - Checks for accumulated DIRTY/PENDING flags.
|
|
821
|
+
* - Triggers execution if needed.
|
|
819
822
|
*
|
|
820
|
-
*
|
|
821
|
-
* count.value = 1; // Queued
|
|
822
|
-
* count.value = 2; // Queued
|
|
823
|
-
* runner.effect.resume(); // Executes once with count.value = 2
|
|
824
|
-
* ```
|
|
823
|
+
* @returns {void}
|
|
825
824
|
*/
|
|
826
825
|
resume(): void;
|
|
827
826
|
/**
|
|
828
|
-
* Execute the Effect function
|
|
827
|
+
* Execute the Effect function.
|
|
829
828
|
*
|
|
830
829
|
* Core execution flow:
|
|
831
830
|
* 1. Check if active
|
|
@@ -833,40 +832,46 @@ declare class EffectImpl<T = any> implements ReactiveNode {
|
|
|
833
832
|
* 3. Start tracking dependencies
|
|
834
833
|
* 4. Execute user function
|
|
835
834
|
* 5. End tracking, clean up stale dependencies
|
|
836
|
-
|
|
837
|
-
* @returns The return value of the effect function
|
|
835
|
+
*
|
|
836
|
+
* @returns {T} The return value of the effect function.
|
|
838
837
|
*/
|
|
839
838
|
run(): T;
|
|
840
839
|
private _job?;
|
|
841
840
|
/**
|
|
842
|
-
* Get or create the job function for this effect
|
|
841
|
+
* Get or create the job function for this effect.
|
|
842
|
+
*
|
|
843
|
+
* @returns {() => void} The job function.
|
|
843
844
|
*/
|
|
844
845
|
private getJob;
|
|
845
846
|
/**
|
|
846
|
-
* Notify that the Effect needs to execute
|
|
847
|
+
* Notify that the Effect needs to execute.
|
|
847
848
|
*
|
|
848
849
|
* Called by dependent reactive values.
|
|
849
850
|
* Decides whether to execute immediately or defer based on scheduling strategy.
|
|
851
|
+
*
|
|
852
|
+
* @returns {void}
|
|
850
853
|
*/
|
|
851
854
|
notify(): void;
|
|
852
855
|
/**
|
|
853
|
-
* Stop the Effect
|
|
856
|
+
* Stop the Effect.
|
|
854
857
|
*
|
|
855
858
|
* After stopping:
|
|
856
|
-
* - No longer responds to dependency changes
|
|
857
|
-
* - Disconnects all dependency links
|
|
858
|
-
* - Clears cached job function
|
|
859
|
-
* - Calls onStop callback
|
|
860
|
-
* - Verifies complete cleanup in development mode
|
|
859
|
+
* - No longer responds to dependency changes.
|
|
860
|
+
* - Disconnects all dependency links.
|
|
861
|
+
* - Clears cached job function.
|
|
862
|
+
* - Calls onStop callback.
|
|
863
|
+
* - Verifies complete cleanup in development mode.
|
|
864
|
+
*
|
|
865
|
+
* @returns {void}
|
|
861
866
|
*/
|
|
862
867
|
stop(): void;
|
|
863
868
|
}
|
|
864
869
|
/**
|
|
865
|
-
* Create and immediately execute an Effect
|
|
870
|
+
* Create and immediately execute an Effect.
|
|
866
871
|
*
|
|
867
|
-
* @param fn - The effect function
|
|
868
|
-
* @param options - Configuration options
|
|
869
|
-
* @returns Effect runner
|
|
872
|
+
* @param fn - The effect function.
|
|
873
|
+
* @param options - Configuration options.
|
|
874
|
+
* @returns {EffectRunner<T>} Effect runner.
|
|
870
875
|
*
|
|
871
876
|
* @example
|
|
872
877
|
* ```typescript
|
|
@@ -897,16 +902,17 @@ declare class EffectImpl<T = any> implements ReactiveNode {
|
|
|
897
902
|
*/
|
|
898
903
|
declare function effect<T = any>(fn: EffectFunction<T>, options?: EffectOptions): EffectRunner<T>;
|
|
899
904
|
/**
|
|
900
|
-
* Stop Effect execution
|
|
905
|
+
* Stop Effect execution.
|
|
901
906
|
*
|
|
902
|
-
* @param runner - The effect runner
|
|
907
|
+
* @param runner - The effect runner to stop.
|
|
908
|
+
* @returns {void}
|
|
903
909
|
*/
|
|
904
910
|
declare function stop(runner: EffectRunner): void;
|
|
905
911
|
/**
|
|
906
|
-
* Type guard - Check if value is an Effect
|
|
912
|
+
* Type guard - Check if value is an Effect instance.
|
|
907
913
|
*
|
|
908
|
-
* @param value - The value to check
|
|
909
|
-
* @returns
|
|
914
|
+
* @param value - The value to check.
|
|
915
|
+
* @returns {boolean} True if value is an Effect instance.
|
|
910
916
|
*/
|
|
911
917
|
declare function isEffect(value: any): value is EffectImpl;
|
|
912
918
|
/**
|
|
@@ -918,21 +924,15 @@ declare function isEffect(value: any): value is EffectImpl;
|
|
|
918
924
|
*/
|
|
919
925
|
type MemoEffectFn<T> = (prevState: T) => T;
|
|
920
926
|
/**
|
|
921
|
-
* Create a memoized Effect
|
|
927
|
+
* Create a memoized Effect.
|
|
922
928
|
*
|
|
923
929
|
* A memoized effect remembers the return value from the previous execution
|
|
924
930
|
* and passes it as a parameter on the next execution.
|
|
925
931
|
*
|
|
926
|
-
*
|
|
927
|
-
* -
|
|
928
|
-
* -
|
|
929
|
-
*
|
|
930
|
-
* - Difference detection
|
|
931
|
-
*
|
|
932
|
-
* @param fn - The memoized function
|
|
933
|
-
* @param initialState - Initial state
|
|
934
|
-
* @param options - Configuration options
|
|
935
|
-
* @returns Effect runner
|
|
932
|
+
* @param fn - The memoized function.
|
|
933
|
+
* @param initialState - Initial state.
|
|
934
|
+
* @param options - Configuration options.
|
|
935
|
+
* @returns {EffectRunner<void>} Effect runner.
|
|
936
936
|
*
|
|
937
937
|
* @example
|
|
938
938
|
* ```typescript
|
|
@@ -954,13 +954,10 @@ type MemoEffectFn<T> = (prevState: T) => T;
|
|
|
954
954
|
declare function memoEffect<T>(fn: MemoEffectFn<T>, initialState: T, options?: EffectOptions): EffectRunner<void>;
|
|
955
955
|
|
|
956
956
|
/**
|
|
957
|
-
* Execute a function in batch mode
|
|
958
|
-
*
|
|
959
|
-
* Executes the function in a batch context, where all Signal changes
|
|
960
|
-
* are deferred and processed together after the batch ends.
|
|
957
|
+
* Execute a function in batch mode.
|
|
961
958
|
*
|
|
962
|
-
* @param fn - The function to execute in batch mode
|
|
963
|
-
* @returns The return value of the function
|
|
959
|
+
* @param fn - The function to execute in batch mode.
|
|
960
|
+
* @returns The return value of the function.
|
|
964
961
|
*
|
|
965
962
|
* @example
|
|
966
963
|
* ```typescript
|
|
@@ -984,45 +981,27 @@ declare function memoEffect<T>(fn: MemoEffectFn<T>, initialState: T, options?: E
|
|
|
984
981
|
*/
|
|
985
982
|
declare function batch<T>(fn: () => T): T;
|
|
986
983
|
/**
|
|
987
|
-
* Start batch update
|
|
984
|
+
* Start batch update.
|
|
988
985
|
*
|
|
989
|
-
*
|
|
990
|
-
* During batch, Effects won't execute immediately.
|
|
986
|
+
* @returns {void}
|
|
991
987
|
*/
|
|
992
988
|
declare function startBatch(): void;
|
|
993
989
|
/**
|
|
994
|
-
* End batch update
|
|
995
|
-
*
|
|
996
|
-
* Decreases batch depth.
|
|
997
|
-
* When depth reaches zero, flush all queued Effects.
|
|
990
|
+
* End batch update.
|
|
998
991
|
*
|
|
999
|
-
*
|
|
1000
|
-
*
|
|
1001
|
-
* When the outermost batch ends:
|
|
1002
|
-
* 1. Flush all queued jobs (effects execute)
|
|
1003
|
-
* 2. Job queue is automatically cleared by flushJobs()
|
|
1004
|
-
* 3. Temporary flags (QUEUED, DIRTY) are cleared by effect execution
|
|
1005
|
-
*
|
|
1006
|
-
* ## Development Mode Checks
|
|
1007
|
-
*
|
|
1008
|
-
* In development mode, this function performs additional validation:
|
|
1009
|
-
* - Detects unbalanced batch calls (endBatch without startBatch)
|
|
1010
|
-
* - Prevents batchDepth from becoming negative
|
|
1011
|
-
* - Provides clear error messages to help debug batch management issues
|
|
992
|
+
* @returns {void}
|
|
1012
993
|
*/
|
|
1013
994
|
declare function endBatch(): void;
|
|
1014
995
|
/**
|
|
1015
|
-
* Check if currently in batch update mode
|
|
996
|
+
* Check if currently in batch update mode.
|
|
1016
997
|
*
|
|
1017
|
-
* @returns
|
|
998
|
+
* @returns True if currently in batch mode.
|
|
1018
999
|
*/
|
|
1019
1000
|
declare function isBatching(): boolean;
|
|
1020
1001
|
/**
|
|
1021
|
-
* Get current batch depth
|
|
1002
|
+
* Get current batch depth.
|
|
1022
1003
|
*
|
|
1023
|
-
*
|
|
1024
|
-
*
|
|
1025
|
-
* @returns Current batch nesting depth
|
|
1004
|
+
* @returns Current batch nesting depth.
|
|
1026
1005
|
*/
|
|
1027
1006
|
declare function getBatchDepth(): number;
|
|
1028
1007
|
|
|
@@ -1098,6 +1077,12 @@ interface StoreActions<S extends State> {
|
|
|
1098
1077
|
* @param callback - Function to call on action execution
|
|
1099
1078
|
*/
|
|
1100
1079
|
onAction$: (callback: StoreCallback<S>) => void;
|
|
1080
|
+
/**
|
|
1081
|
+
* Removes a previously registered action callback.
|
|
1082
|
+
*
|
|
1083
|
+
* @param callback - The callback to remove.
|
|
1084
|
+
*/
|
|
1085
|
+
offAction$: (callback: StoreCallback<S>) => void;
|
|
1101
1086
|
/**
|
|
1102
1087
|
* Resets the store state to its initial values.
|
|
1103
1088
|
*/
|
|
@@ -1123,11 +1108,11 @@ type StoreDefinition<S extends State, G extends Getters<S>, A extends Actions> =
|
|
|
1123
1108
|
* Creates a new store with the given definition.
|
|
1124
1109
|
* The store can be defined either as a class or as an options object.
|
|
1125
1110
|
*
|
|
1126
|
-
* @template S - The type of the store's state
|
|
1127
|
-
* @template G - The type of the store's getters
|
|
1128
|
-
* @template A - The type of the store's actions
|
|
1129
|
-
* @param storeDefinition - The store definition (class or options)
|
|
1130
|
-
* @returns A function that creates a new store instance
|
|
1111
|
+
* @template S - The type of the store's state.
|
|
1112
|
+
* @template G - The type of the store's getters.
|
|
1113
|
+
* @template A - The type of the store's actions.
|
|
1114
|
+
* @param storeDefinition - The store definition (class or options).
|
|
1115
|
+
* @returns A function that creates a new store instance.
|
|
1131
1116
|
*
|
|
1132
1117
|
* @example
|
|
1133
1118
|
* ```ts
|
|
@@ -1181,9 +1166,9 @@ interface Ref<T> extends Signal<T> {
|
|
|
1181
1166
|
* Creates a new ref with the given initial value.
|
|
1182
1167
|
* Unlike signals, refs don't create reactive proxies for object values.
|
|
1183
1168
|
*
|
|
1184
|
-
* @template T - The type of value to store in the ref
|
|
1185
|
-
* @param value - The initial value
|
|
1186
|
-
* @returns A new ref instance
|
|
1169
|
+
* @template T - The type of value to store in the ref.
|
|
1170
|
+
* @param value - The initial value.
|
|
1171
|
+
* @returns A new ref instance.
|
|
1187
1172
|
*
|
|
1188
1173
|
* @example
|
|
1189
1174
|
* ```ts
|
|
@@ -1195,9 +1180,9 @@ declare function ref<T>(value?: T): Ref<T>;
|
|
|
1195
1180
|
/**
|
|
1196
1181
|
* Type guard to check if a value is a Ref instance.
|
|
1197
1182
|
*
|
|
1198
|
-
* @template T - The type of value held by the ref
|
|
1199
|
-
* @param value - The value to check
|
|
1200
|
-
* @returns True if the value is a Ref instance
|
|
1183
|
+
* @template T - The type of value held by the ref.
|
|
1184
|
+
* @param value - The value to check.
|
|
1185
|
+
* @returns True if the value is a Ref instance.
|
|
1201
1186
|
*/
|
|
1202
1187
|
declare function isRef<T>(value: unknown): value is Ref<T>;
|
|
1203
1188
|
|
|
@@ -1211,10 +1196,11 @@ type WatchSource<T = any> = T | {
|
|
|
1211
1196
|
type WatchCallback<T = any> = (newValue: T, oldValue: T | undefined) => void;
|
|
1212
1197
|
/**
|
|
1213
1198
|
* Watch one or more reactive data sources and execute callback when sources change.
|
|
1199
|
+
*
|
|
1214
1200
|
* @param source - The source(s) to watch.
|
|
1215
1201
|
* @param callback - The callback function to execute when source changes.
|
|
1216
1202
|
* @param options - Configuration options like immediate and deep.
|
|
1217
|
-
* @returns A function to stop watching.
|
|
1203
|
+
* @returns {Function} A function to stop watching.
|
|
1218
1204
|
*/
|
|
1219
1205
|
declare function watch<T = any>(source: WatchSource<T>, callback: WatchCallback<T>, options?: WatchOptions): () => void;
|
|
1220
1206
|
|