@xaendar/signals 0.5.7 → 0.5.8

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.
@@ -263,43 +263,6 @@ declare class Computed<T = any> {
263
263
  */
264
264
  declare type ComputedState = 'dirty' | 'checked' | 'computing' | 'clean';
265
265
 
266
- /**
267
- * Runs a side-effectful function and automatically re-runs it whenever any
268
- * Signal read during its execution changes.
269
- *
270
- * Internally, `effect` wraps the user callback inside a `Computed` node
271
- * (for dependency tracking) and observes it with a `Watcher` (for push
272
- * notifications). When any tracked dependency changes, the `Watcher`
273
- * schedules a microtask that re-evaluates the `Computed`, which in turn
274
- * re-runs the user callback and re-registers the new set of dependencies.
275
- *
276
- * The returned disposer function stops the effect: it unwatches the internal
277
- * `Computed` from the `Watcher`, severing all dependency subscriptions so
278
- * the callback is never called again and the graph nodes can be
279
- * garbage-collected.
280
- *
281
- * @example
282
- * ```ts
283
- * const count = new State(0);
284
- *
285
- * const stop = effect(() => {
286
- * console.log('count is', count.get());
287
- * });
288
- * // logs: "count is 0"
289
- *
290
- * count.set(1); // logs: "count is 1"
291
- * count.set(2); // logs: "count is 2"
292
- *
293
- * stop(); // no more logs
294
- * count.set(3); // silent
295
- * ```
296
- *
297
- * @param fn - The side-effectful function to run. Any Signal read inside it
298
- * is tracked as a dependency.
299
- * @returns A disposer function that, when called, permanently stops the effect.
300
- */
301
- export declare function effect(fn: NoArgsVoidFunction, options?: EffectOptions): NoArgsVoidFunction;
302
-
303
266
  /**
304
267
  * Options for configuring an effect.
305
268
  */
@@ -308,7 +271,7 @@ export declare type EffectOptions = {
308
271
  * Registers a cleanup function that is called before the effect re-runs or when it is disposed.
309
272
  * @param cleanupFn - The function to invoke during cleanup.
310
273
  */
311
- onCleanup?: NoArgsVoidFunction_2;
274
+ onCleanup?: NoArgsVoidFunction;
312
275
  /**
313
276
  * Called before the effect re-runs.
314
277
  */
@@ -440,7 +403,7 @@ declare class Watcher {
440
403
  *
441
404
  * @see Signal algorithms — 'Constructor: new Signal.subtle.Watcher(callback)'
442
405
  */
443
- constructor(notifyCallback: NoArgsVoidFunction);
406
+ constructor(notifyCallback: NoArgsVoidFunction_2);
444
407
  /**
445
408
  * Returns the subset of watched Signals that are `Computed` instances
446
409
  * currently in a `~dirty~` or `~checked~` state, meaning they may have a
@@ -944,84 +944,4 @@ function loadSignals(options) {
944
944
  };
945
945
  }
946
946
  //#endregion
947
- //#region ../packages/signals/src/lib/models/effect/effect.ts
948
- /**
949
- * Runs a side-effectful function and automatically re-runs it whenever any
950
- * Signal read during its execution changes.
951
- *
952
- * Internally, `effect` wraps the user callback inside a `Computed` node
953
- * (for dependency tracking) and observes it with a `Watcher` (for push
954
- * notifications). When any tracked dependency changes, the `Watcher`
955
- * schedules a microtask that re-evaluates the `Computed`, which in turn
956
- * re-runs the user callback and re-registers the new set of dependencies.
957
- *
958
- * The returned disposer function stops the effect: it unwatches the internal
959
- * `Computed` from the `Watcher`, severing all dependency subscriptions so
960
- * the callback is never called again and the graph nodes can be
961
- * garbage-collected.
962
- *
963
- * @example
964
- * ```ts
965
- * const count = new State(0);
966
- *
967
- * const stop = effect(() => {
968
- * console.log('count is', count.get());
969
- * });
970
- * // logs: "count is 0"
971
- *
972
- * count.set(1); // logs: "count is 1"
973
- * count.set(2); // logs: "count is 2"
974
- *
975
- * stop(); // no more logs
976
- * count.set(3); // silent
977
- * ```
978
- *
979
- * @param fn - The side-effectful function to run. Any Signal read inside it
980
- * is tracked as a dependency.
981
- * @returns A disposer function that, when called, permanently stops the effect.
982
- */
983
- function effect(fn, options) {
984
- /**
985
- * Wrap the user callback in a Computed so that automatic dependency
986
- * tracking (via pushComputed / popComputed) works for free.
987
- * The Computed always returns `undefined` — we only care about the
988
- * side-effects and the tracked sources, not the value.
989
- */
990
- const computed = new Signal.Computed(() => fn());
991
- let needsEnqueue = true;
992
- /**
993
- * The Watcher is notified synchronously as soon as any tracked dependency
994
- * changes. Its job is purely to schedule the re-execution; the actual
995
- * re-evaluation happens asynchronously in a microtask so that multiple
996
- * synchronous signal updates are batched into a single re-run.
997
- */
998
- const watcher = new Signal.subtle.Watcher(() => {
999
- if (needsEnqueue) {
1000
- needsEnqueue = false;
1001
- queueMicrotask(() => {
1002
- needsEnqueue = true;
1003
- options?.onBeforeRun?.();
1004
- watcher.getPending().forEach((computed) => computed.get());
1005
- options?.onAfterRun?.();
1006
- watcher.watch();
1007
- });
1008
- }
1009
- });
1010
- options?.onBeforeRun?.();
1011
- watcher.watch(computed);
1012
- computed.get();
1013
- options?.onAfterRun?.();
1014
- /**
1015
- * Disposer — call this to permanently stop the effect.
1016
- *
1017
- * Unwatching the Computed tears down the entire live dependency chain
1018
- * (Watcher → Computed → all sources), preventing any further
1019
- * notifications and allowing GC.
1020
- */
1021
- return () => {
1022
- options?.onCleanup?.();
1023
- watcher.unwatch(computed);
1024
- };
1025
- }
1026
- //#endregion
1027
- export { effect, loadSignals };
947
+ export { loadSignals };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xaendar/signals",
3
- "version": "0.5.7",
3
+ "version": "0.5.8",
4
4
  "description": "A library implementing a reactive system for Xaendar framework. This signal implementation is based on the TC39 Stage1 proposal for reactive primitives.",
5
5
  "sideEffects": false,
6
6
  "type": "module",
@@ -16,7 +16,7 @@
16
16
  }
17
17
  },
18
18
  "dependencies": {
19
- "@xaendar/common": "0.5.7",
20
- "@xaendar/types": "0.5.7"
19
+ "@xaendar/common": "0.5.8",
20
+ "@xaendar/types": "0.5.8"
21
21
  }
22
22
  }