@alwatr/signal 5.0.0 → 5.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 (43) hide show
  1. package/CHANGELOG.md +63 -0
  2. package/dist/{computed-signal.d.ts → core/computed-signal.d.ts} +32 -9
  3. package/dist/core/computed-signal.d.ts.map +1 -0
  4. package/dist/{effect-signal.d.ts → core/effect-signal.d.ts} +25 -7
  5. package/dist/core/effect-signal.d.ts.map +1 -0
  6. package/dist/{event-signal.d.ts → core/event-signal.d.ts} +4 -4
  7. package/dist/core/event-signal.d.ts.map +1 -0
  8. package/dist/{signal-base.d.ts → core/signal-base.d.ts} +19 -14
  9. package/dist/core/signal-base.d.ts.map +1 -0
  10. package/dist/{state-signal.d.ts → core/state-signal.d.ts} +27 -4
  11. package/dist/core/state-signal.d.ts.map +1 -0
  12. package/dist/creators/computed.d.ts +34 -0
  13. package/dist/creators/computed.d.ts.map +1 -0
  14. package/dist/creators/effect.d.ts +43 -0
  15. package/dist/creators/effect.d.ts.map +1 -0
  16. package/dist/creators/event.d.ts +28 -0
  17. package/dist/creators/event.d.ts.map +1 -0
  18. package/dist/creators/state.d.ts +25 -0
  19. package/dist/creators/state.d.ts.map +1 -0
  20. package/dist/main.cjs +225 -92
  21. package/dist/main.cjs.map +3 -3
  22. package/dist/main.d.ts +10 -5
  23. package/dist/main.d.ts.map +1 -1
  24. package/dist/main.mjs +219 -91
  25. package/dist/main.mjs.map +3 -3
  26. package/dist/operators/debounce.d.ts +57 -0
  27. package/dist/operators/debounce.d.ts.map +1 -0
  28. package/dist/operators/filter.d.ts +47 -0
  29. package/dist/operators/filter.d.ts.map +1 -0
  30. package/dist/operators/map.d.ts +36 -0
  31. package/dist/operators/map.d.ts.map +1 -0
  32. package/dist/type.d.ts +57 -15
  33. package/dist/type.d.ts.map +1 -1
  34. package/package.json +8 -8
  35. package/dist/computed-signal.d.ts.map +0 -1
  36. package/dist/effect-signal.d.ts.map +0 -1
  37. package/dist/event-signal.d.ts.map +0 -1
  38. package/dist/signal-base.d.ts.map +0 -1
  39. package/dist/state-signal.d.ts.map +0 -1
  40. /package/src/{computed-signal.test.js → core/computed-signal.test.js} +0 -0
  41. /package/src/{effect-signal.test.js → core/effect-signal.test.js} +0 -0
  42. /package/src/{event-signal.test.js → core/event-signal.test.js} +0 -0
  43. /package/src/{state-signal.test.js → core/state-signal.test.js} +0 -0
package/CHANGELOG.md CHANGED
@@ -3,6 +3,69 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [5.2.0](https://github.com/Alwatr/flux/compare/v5.1.0...v5.2.0) (2025-09-15)
7
+
8
+ ### ✨ Features
9
+
10
+ * Add comprehensive documentation to the repository ([d5569e6](https://github.com/Alwatr/flux/commit/d5569e63acd0aa926c34d9a61b2fff5139b9d3cc))
11
+ * Update EffectSignalConfig to allow optional signalId and add documentation ([6aab97e](https://github.com/Alwatr/flux/commit/6aab97e6e223f822f66cacb78c9d194fa5e2df9d))
12
+
13
+ ### 🐛 Bug Fixes
14
+
15
+ * Refactor logger initialization and ensure checkDestroyed_ is called in relevant methods ([a17884d](https://github.com/Alwatr/flux/commit/a17884d5df097d62353e5b4110d3a83a5ae093b3))
16
+
17
+ ### 🔨 Code Refactoring
18
+
19
+ * Ensure isRunning__ is reset when destroyed during delay in EffectSignal ([ff9a590](https://github.com/Alwatr/flux/commit/ff9a5905f7875e7dcb675cbdbb44869b0743e954))
20
+ * Improve signal management by consolidating destruction checks and enhancing logging ([8765ba2](https://github.com/Alwatr/flux/commit/8765ba2f701f10db89ef11a3045065442360d193))
21
+ * Remove unnecessary binding of notify_ in EventSignal constructor ([eb3be32](https://github.com/Alwatr/flux/commit/eb3be3211b13c21aa4f5c16a37f5c9fc59144951))
22
+ * Simplify ComputedSignal implementation and improve logging for lifecycle methods ([bc35e91](https://github.com/Alwatr/flux/commit/bc35e91d5871669cc22c6c92ee2b83c4d940194e))
23
+ * Simplify EffectSignal implementation and improve logging for lifecycle methods ([a5cad04](https://github.com/Alwatr/flux/commit/a5cad04469efd929e2ce7da42b371d4c054e5eaf))
24
+ * Simplify EventSignal logger initialization and constructor ([b515315](https://github.com/Alwatr/flux/commit/b515315428e8ba0c70a7ef5ede49916e899b6fcd))
25
+ * Update logger step identifiers for recalculation in ComputedSignal ([8de799f](https://github.com/Alwatr/flux/commit/8de799f40d90c2cdc3440d90bc1f2b6ce22f7013))
26
+
27
+ ## [5.1.0](https://github.com/Alwatr/flux/compare/v5.0.0...v5.1.0) (2025-09-14)
28
+
29
+ ### ✨ Features
30
+
31
+ * add createComputedSignal function for reactive value management ([da4ad2e](https://github.com/Alwatr/flux/commit/da4ad2ec31e24d0756007b666e6c6c3c3ad75709))
32
+ * add createEventSignal function for dispatching transient events ([0729eca](https://github.com/Alwatr/flux/commit/0729eca8ad7ed9fd4fca02c5f2c5f5d2f1a5acf4))
33
+ * add createFilteredSignal function to emit values from a source signal based on a predicate ([ad4873c](https://github.com/Alwatr/flux/commit/ad4873c2f5ca8d26e44db371c1387f450e12189b))
34
+ * add createMappedSignal function for transforming source signal values ([6fcefed](https://github.com/Alwatr/flux/commit/6fcefed778bd6007c639d218e3736aaf9d071d10))
35
+ * add createStateSignal function for creating stateful signals ([2764b50](https://github.com/Alwatr/flux/commit/2764b501dfc39488f7b5446935e7ebdfe06fcd35))
36
+ * add optional onDestroy callback to SignalConfig and EffectSignalConfig for resource cleanup ([d0ed93a](https://github.com/Alwatr/flux/commit/d0ed93a1f7e9da5c73222fb9a3e7e1b95fa88212))
37
+ * add signalId property to IReadonlySignal for debugging and update DebounceSignalConfig type ([d7a43ba](https://github.com/Alwatr/flux/commit/d7a43bad568d12264482475bddb045467dfe229c))
38
+ * add update method for state transitions based on previous value ([77b3593](https://github.com/Alwatr/flux/commit/77b3593df19e166b0446938104a9795b037b2d3d))
39
+ * call optional onDestroy callback in createDebouncedSignal for improved resource cleanup ([8eef425](https://github.com/Alwatr/flux/commit/8eef4252d193db5809850bd624e739bcc8549077))
40
+ * call optional onDestroy callback in destroy method for resource cleanup ([64a0e3b](https://github.com/Alwatr/flux/commit/64a0e3b6f242e91bccc48fe0cf8d1e214bcc2a5e))
41
+ * enhance createDebouncedSignal with optional signalId and onDestroy callback for improved resource management ([7ce880a](https://github.com/Alwatr/flux/commit/7ce880a40b96a3aaa78297d68cd3e7e9e05b7a20))
42
+ * enhance destroy method in SignalBase and StateSignal for improved memory management ([a81f005](https://github.com/Alwatr/flux/commit/a81f0057803fe1c0c0650d0a2223319064739067))
43
+ * implement createDebouncedSignal function for debouncing updates from a source signal ([42bd6a9](https://github.com/Alwatr/flux/commit/42bd6a915494222171317142bd21e11ff3ef2e25))
44
+ * implement createEffect function for managing reactive side-effects ([730c847](https://github.com/Alwatr/flux/commit/730c847ed6720ca7761dfb5745d957a681352a9c))
45
+ * implement IReadonlySignal interface in ComputedSignal and call optional onDestroy callback in destroy method ([8828230](https://github.com/Alwatr/flux/commit/8828230fa2ea8246d6b08d73dfee863eceea4c82))
46
+ * improve resource cleanup in createDebouncedSignal by checking internalSignal state before destruction ([36b8505](https://github.com/Alwatr/flux/commit/36b850505c0541906038a05f2cf5967baac1b2cb))
47
+ * update createDebouncedSignal to use ComputedSignal type and streamline resource cleanup in onDestroy callback ([bb0908a](https://github.com/Alwatr/flux/commit/bb0908a03ad9a86e432b8bfa17e21ced881c8f41))
48
+
49
+ ### 🐛 Bug Fixes
50
+
51
+ * debounce destroy ([e14a39a](https://github.com/Alwatr/flux/commit/e14a39a6b4729980d5aa7486873b4aae272bec0b))
52
+ * initialize signalId in constructor and call optional onDestroy callback in destroy method ([198f9b3](https://github.com/Alwatr/flux/commit/198f9b3b08a259d118b8645bb144677ea7f24613))
53
+ * remove unused dependency @alwatr/package-tracer from package.json ([9008a40](https://github.com/Alwatr/flux/commit/9008a40b8eb7e996ee8995956ab14d93bf021407))
54
+
55
+ ### 🔨 Code Refactoring
56
+
57
+ * move fundamental signals to core ([5fc4cd9](https://github.com/Alwatr/flux/commit/5fc4cd90cb3463a876bc21f4699510aace7db8f4))
58
+ * remove packageTracer import and related dev mode initialization ([d02276e](https://github.com/Alwatr/flux/commit/d02276eed37337b1f68d2c74cc5ee366add55f35))
59
+ * remove unused IComputedSignal and IEffectSignal imports from computed and effect creators ([bf7d3f2](https://github.com/Alwatr/flux/commit/bf7d3f287ee2db101b6ca0ad30eccf5f1af4bdd1))
60
+ * reorganize exports to use core and creators directories ([cdb5225](https://github.com/Alwatr/flux/commit/cdb5225773c5a909f176bb5550ce4f3a0517f09f))
61
+ * simplify parameter and return type annotations in createComputedSignal, createEffect, and createEventSignal ([024025e](https://github.com/Alwatr/flux/commit/024025e68fb4793ab7ecd97e51ccb5f271002a52))
62
+
63
+ ### 🔗 Dependencies update
64
+
65
+ * bump the npm-dependencies group with 6 updates ([f6ae979](https://github.com/Alwatr/flux/commit/f6ae9795e34ba3913fa208f7f94794b5753b90c9))
66
+ * update @alwatr/debounce dependency to version 1.1.0 ([bce3ffe](https://github.com/Alwatr/flux/commit/bce3ffe6c174c05aef60dc9fdc7e78aa31dcc71b))
67
+ * update @types/node dependency to version 22.18.3 ([6e1a847](https://github.com/Alwatr/flux/commit/6e1a8477095f102d09b020dccfe4e638c1d058ca))
68
+
6
69
  ## [5.0.0](https://github.com/Alwatr/flux/compare/v4.1.1...v5.0.0) (2025-09-12)
7
70
 
8
71
  ### ⚠ BREAKING CHANGES
@@ -1,5 +1,5 @@
1
1
  import { StateSignal } from './state-signal.js';
2
- import type { ComputedSignalConfig, IComputedSignal, SubscribeResult } from './type.js';
2
+ import type { ComputedSignalConfig, IReadonlySignal, SubscribeResult, SubscribeOptions } from '../type.js';
3
3
  /**
4
4
  * A read-only signal that derives its value from a set of dependency signals.
5
5
  *
@@ -11,7 +11,6 @@ import type { ComputedSignalConfig, IComputedSignal, SubscribeResult } from './t
11
11
  * needed to prevent memory leaks from its subscriptions to dependency signals.
12
12
  *
13
13
  * @template T The type of the computed value.
14
- * @implements {IComputedSignal<T>}
15
14
  *
16
15
  * @example
17
16
  * // --- Create dependency signals ---
@@ -39,9 +38,16 @@ import type { ComputedSignalConfig, IComputedSignal, SubscribeResult } from './t
39
38
  * // --- IMPORTANT: Clean up when done ---
40
39
  * fullName.destroy();
41
40
  */
42
- export declare class ComputedSignal<T> implements IComputedSignal<T> {
41
+ export declare class ComputedSignal<T> implements IReadonlySignal<T> {
43
42
  protected config_: ComputedSignalConfig<T>;
43
+ /**
44
+ * The unique identifier for this signal instance.
45
+ */
44
46
  readonly signalId: string;
47
+ /**
48
+ * The logger instance for this signal.
49
+ * @protected
50
+ */
45
51
  protected readonly logger_: import("@alwatr/logger").AlwatrLogger;
46
52
  /**
47
53
  * The internal `StateSignal` that holds the computed value.
@@ -49,12 +55,16 @@ export declare class ComputedSignal<T> implements IComputedSignal<T> {
49
55
  * @protected
50
56
  */
51
57
  protected readonly internalSignal_: StateSignal<T>;
52
- private readonly subscriptionList__;
53
- private isRecalculating__;
54
58
  /**
55
- * Initializes a new `ComputedSignal`.
56
- * @param config The configuration, including dependencies (`deps`) and the getter function (`get`).
59
+ * A list of subscriptions to dependency signals.
60
+ * @private
61
+ */
62
+ private readonly dependencySubscriptions__;
63
+ /**
64
+ * A flag to prevent concurrent recalculations.
65
+ * @private
57
66
  */
67
+ private isRecalculating__;
58
68
  constructor(config_: ComputedSignalConfig<T>);
59
69
  /**
60
70
  * The current value of the computed signal.
@@ -70,8 +80,21 @@ export declare class ComputedSignal<T> implements IComputedSignal<T> {
70
80
  * @returns `true` if the signal is destroyed, `false` otherwise.
71
81
  */
72
82
  get isDestroyed(): boolean;
73
- readonly subscribe: (callback: import("./type.js").ListenerCallback<T>, options?: import("./type.js").SubscribeOptions) => SubscribeResult;
74
- readonly untilNext: () => Promise<T>;
83
+ /**
84
+ * Subscribes a listener to this signal.
85
+ * The listener will be called whenever the computed value changes.
86
+ *
87
+ * @param callback The function to be called with the new value.
88
+ * @param options Subscription options.
89
+ * @returns A `SubscribeResult` object with an `unsubscribe` method.
90
+ */
91
+ subscribe(callback: (value: T) => void, options?: SubscribeOptions): SubscribeResult;
92
+ /**
93
+ * Returns a Promise that resolves with the next computed value.
94
+ *
95
+ * @returns A Promise that resolves with the next value.
96
+ */
97
+ untilNext(): Promise<T>;
75
98
  /**
76
99
  * Permanently disposes of the computed signal.
77
100
  *
@@ -0,0 +1 @@
1
+ {"version":3,"file":"computed-signal.d.ts","sourceRoot":"","sources":["../../src/core/computed-signal.ts"],"names":[],"mappings":"AAGA,OAAO,EAAC,WAAW,EAAC,MAAM,mBAAmB,CAAC;AAE9C,OAAO,KAAK,EAAC,oBAAoB,EAAE,eAAe,EAAE,eAAe,EAAE,gBAAgB,EAAC,MAAM,YAAY,CAAC;AAEzG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,qBAAa,cAAc,CAAC,CAAC,CAAE,YAAW,eAAe,CAAC,CAAC,CAAC;IAmCvC,SAAS,CAAC,OAAO,EAAE,oBAAoB,CAAC,CAAC,CAAC;IAlC7D;;OAEG;IACH,SAAgB,QAAQ,SAAyB;IAEjD;;;OAGG;IACH,SAAS,CAAC,QAAQ,CAAC,OAAO,wCAAqD;IAE/E;;;;OAIG;IACH,SAAS,CAAC,QAAQ,CAAC,eAAe,iBAG/B;IAEH;;;OAGG;IAEH,OAAO,CAAC,QAAQ,CAAC,yBAAyB,CAAyB;IAEnE;;;OAGG;IACH,OAAO,CAAC,iBAAiB,CAAS;gBAEL,OAAO,EAAE,oBAAoB,CAAC,CAAC,CAAC;IAU7D;;;;;;OAMG;IACH,IAAW,KAAK,IAAI,CAAC,CAEpB;IAED;;;;OAIG;IACH,IAAW,WAAW,IAAI,OAAO,CAEhC;IAED;;;;;;;OAOG;IACI,SAAS,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,EAAE,OAAO,CAAC,EAAE,gBAAgB,GAAG,eAAe;IAI3F;;;;OAIG;IACI,SAAS,IAAI,OAAO,CAAC,CAAC,CAAC;IAI9B;;;;;;;;OAQG;IACI,OAAO,IAAI,IAAI;IAqBtB;;;;;;;OAOG;cACa,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;CAwC9C"}
@@ -1,4 +1,4 @@
1
- import type { EffectSignalConfig, IEffectSignal } from './type.js';
1
+ import type { EffectSignalConfig, IEffectSignal } from '../type.js';
2
2
  /**
3
3
  * Manages a side-effect that runs in response to changes in dependency signals.
4
4
  *
@@ -19,6 +19,7 @@ import type { EffectSignalConfig, IEffectSignal } from './type.js';
19
19
  *
20
20
  * // --- Create an effect ---
21
21
  * const analyticsEffect = new EffectSignal({
22
+ * signalId: 'analytics-effect',
22
23
  * deps: [counter, user],
23
24
  * run: () => {
24
25
  * console.log(`Analytics: User '${user.value}' clicked ${counter.value} times.`);
@@ -39,20 +40,37 @@ import type { EffectSignalConfig, IEffectSignal } from './type.js';
39
40
  */
40
41
  export declare class EffectSignal implements IEffectSignal {
41
42
  protected config_: EffectSignalConfig;
43
+ /**
44
+ * The unique identifier for this signal instance.
45
+ */
46
+ readonly signalId: string;
47
+ /**
48
+ * The logger instance for this signal.
49
+ * @protected
50
+ */
42
51
  protected readonly logger_: import("@alwatr/logger").AlwatrLogger;
43
- private readonly subscriptionList__;
52
+ /**
53
+ * A list of subscriptions to dependency signals.
54
+ * @private
55
+ */
56
+ private readonly dependencySubscriptions__;
57
+ /**
58
+ * A flag to prevent concurrent executions of the effect.
59
+ * @private
60
+ */
44
61
  private isRunning__;
62
+ /**
63
+ * A flag indicating whether the effect has been destroyed.
64
+ * @private
65
+ */
45
66
  private isDestroyed__;
46
67
  /**
47
68
  * Indicates whether the effect signal has been destroyed.
48
- * A destroyed signal cannot be used and will throw an error if interacted with.
69
+ * A destroyed signal will no longer execute its effect and cannot be reused.
70
+ *
49
71
  * @returns `true` if the signal is destroyed, `false` otherwise.
50
72
  */
51
73
  get isDestroyed(): boolean;
52
- /**
53
- * Initializes a new `EffectSignal`.
54
- * @param config The configuration, including dependencies (`deps`) and the `run` function.
55
- */
56
74
  constructor(config_: EffectSignalConfig);
57
75
  /**
58
76
  * Schedules the execution of the effect's `run` function.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"effect-signal.d.ts","sourceRoot":"","sources":["../../src/core/effect-signal.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAC,kBAAkB,EAAE,aAAa,EAAkB,MAAM,YAAY,CAAC;AAEnF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,qBAAa,YAAa,YAAW,aAAa;IAwC7B,SAAS,CAAC,OAAO,EAAE,kBAAkB;IAvCxD;;OAEG;IACH,SAAgB,QAAQ,SAAkH;IAE1I;;;OAGG;IACH,SAAS,CAAC,QAAQ,CAAC,OAAO,wCAAmD;IAE7E;;;OAGG;IACH,OAAO,CAAC,QAAQ,CAAC,yBAAyB,CAAyB;IAEnE;;;OAGG;IACH,OAAO,CAAC,WAAW,CAAS;IAE5B;;;OAGG;IACH,OAAO,CAAC,aAAa,CAAS;IAE9B;;;;;OAKG;IACH,IAAW,WAAW,IAAI,OAAO,CAEhC;gBAE4B,OAAO,EAAE,kBAAkB;IAiBxD;;;;;;;OAOG;cACa,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAmCrC;;;;;;OAMG;IACI,OAAO,IAAI,IAAI;CAmBvB"}
@@ -1,5 +1,5 @@
1
1
  import { SignalBase } from './signal-base.js';
2
- import type { SignalConfig } from './type.js';
2
+ import type { SignalConfig } from '../type.js';
3
3
  /**
4
4
  * A stateless signal for dispatching transient events.
5
5
  *
@@ -28,11 +28,11 @@ import type { SignalConfig } from './type.js';
28
28
  * onAppReady.dispatch(); // Notifies the listener.
29
29
  */
30
30
  export declare class EventSignal<T = void> extends SignalBase<T> {
31
- protected logger_: import("@alwatr/logger").AlwatrLogger;
32
31
  /**
33
- * Initializes a new `EventSignal`.
34
- * @param config The configuration for the signal, containing its `signalId`.
32
+ * The logger instance for this signal.
33
+ * @protected
35
34
  */
35
+ protected logger_: import("@alwatr/logger").AlwatrLogger;
36
36
  constructor(config: SignalConfig);
37
37
  /**
38
38
  * Dispatches an event with an optional payload to all active listeners.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event-signal.d.ts","sourceRoot":"","sources":["../../src/core/event-signal.ts"],"names":[],"mappings":"AAGA,OAAO,EAAC,UAAU,EAAC,MAAM,kBAAkB,CAAC;AAE5C,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,YAAY,CAAC;AAE7C;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,qBAAa,WAAW,CAAC,CAAC,GAAG,IAAI,CAAE,SAAQ,UAAU,CAAC,CAAC,CAAC;IACtD;;;OAGG;IACH,SAAS,CAAC,OAAO,wCAAkD;gBAEhD,MAAM,EAAE,YAAY;IAKvC;;;;;;OAMG;IACI,QAAQ,CAAC,OAAO,EAAE,CAAC,GAAG,IAAI;CAMlC"}
@@ -1,39 +1,44 @@
1
- import type { Observer_, SubscribeOptions, SubscribeResult, ListenerCallback, SignalConfig } from './type.js';
1
+ import type { Observer_, SubscribeOptions, SubscribeResult, ListenerCallback, SignalConfig } from '../type.js';
2
2
  import type { AlwatrLogger } from '@alwatr/logger';
3
3
  /**
4
4
  * An abstract base class for signal implementations.
5
+ * It provides the core functionality for managing subscriptions (observers).
5
6
  *
6
- * `SignalBase` provides the core functionality for managing subscriptions (observers).
7
- * It handles adding, removing, and notifying listeners. The responsibility of *when* to notify
8
- * is left to the concrete subclasses (`StateSignal`, `EventSignal`, etc.).
9
- *
10
- * @template T The type of data the signal will handle.
7
+ * @template T The type of data that the signal holds or dispatches.
11
8
  */
12
9
  export declare abstract class SignalBase<T> {
10
+ protected config_: SignalConfig;
13
11
  /**
14
- * The unique identifier for this signal instance. Useful for debugging.
12
+ * The unique identifier for this signal instance.
13
+ * Useful for debugging and logging.
15
14
  */
16
15
  readonly signalId: string;
16
+ /**
17
+ * The logger instance for this signal.
18
+ * @protected
19
+ */
17
20
  protected abstract logger_: AlwatrLogger;
18
21
  /**
19
22
  * The list of observers (listeners) subscribed to this signal.
20
23
  * @protected
21
24
  */
22
25
  protected readonly observers_: Observer_<T>[];
23
- protected isDestroyed_: boolean;
26
+ /**
27
+ * A flag indicating whether the signal has been destroyed.
28
+ * @private
29
+ */
30
+ private isDestroyed__;
24
31
  /**
25
32
  * Indicates whether the signal has been destroyed.
26
33
  * A destroyed signal cannot be used and will throw an error if interacted with.
34
+ *
27
35
  * @returns `true` if the signal is destroyed, `false` otherwise.
28
36
  */
29
37
  get isDestroyed(): boolean;
30
- /**
31
- * Initializes a new `SignalBase`.
32
- * @param config The configuration for the signal, containing its `signalId`.
33
- */
34
- constructor(config: SignalConfig);
38
+ constructor(config_: SignalConfig);
35
39
  /**
36
40
  * Removes a specific observer from the observers list.
41
+ *
37
42
  * @param observer The observer instance to remove.
38
43
  * @protected
39
44
  */
@@ -85,6 +90,6 @@ export declare abstract class SignalBase<T> {
85
90
  * This is a safeguard to prevent interaction with a defunct signal.
86
91
  * @protected
87
92
  */
88
- protected checkDestroyed_: () => void;
93
+ protected checkDestroyed_(): void;
89
94
  }
90
95
  //# sourceMappingURL=signal-base.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signal-base.d.ts","sourceRoot":"","sources":["../../src/core/signal-base.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,SAAS,EAAE,gBAAgB,EAAE,eAAe,EAAE,gBAAgB,EAAE,YAAY,EAAC,MAAM,YAAY,CAAC;AAC7G,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,gBAAgB,CAAC;AAGjD;;;;;GAKG;AACH,8BAAsB,UAAU,CAAC,CAAC;IAmCb,SAAS,CAAC,OAAO,EAAE,YAAY;IAlClD;;;OAGG;IACH,SAAgB,QAAQ,SAAyB;IAEjD;;;OAGG;IACH,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,YAAY,CAAC;IAEzC;;;OAGG;IACH,SAAS,CAAC,QAAQ,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC,CAAC,EAAE,CAAM;IAEnD;;;OAGG;IACH,OAAO,CAAC,aAAa,CAAS;IAE9B;;;;;OAKG;IACH,IAAW,WAAW,IAAI,OAAO,CAEhC;gBAE4B,OAAO,EAAE,YAAY;IAElD;;;;;OAKG;IACH,SAAS,CAAC,eAAe,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC,CAAC,GAAG,IAAI;IAcvD;;;;;;;;OAQG;IACI,SAAS,CAAC,QAAQ,EAAE,gBAAgB,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,gBAAgB,GAAG,eAAe;IAoB5F;;;;;;;;OAQG;IACH,SAAS,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC,GAAG,IAAI;IA6BjC;;;;;;;;;;;;OAYG;IACI,SAAS,IAAI,OAAO,CAAC,CAAC,CAAC;IAY9B;;;;;;OAMG;IACI,OAAO,IAAI,IAAI;IAYtB;;;;OAIG;IACH,SAAS,CAAC,eAAe,IAAI,IAAI;CAMlC"}
@@ -1,5 +1,5 @@
1
1
  import { SignalBase } from './signal-base.js';
2
- import type { StateSignalConfig, ListenerCallback, SubscribeOptions, SubscribeResult, IReadonlySignal } from './type.js';
2
+ import type { StateSignalConfig, ListenerCallback, SubscribeOptions, SubscribeResult, IReadonlySignal } from '../type.js';
3
3
  /**
4
4
  * A stateful signal that holds a value and notifies listeners when the value changes.
5
5
  *
@@ -27,16 +27,23 @@ import type { StateSignalConfig, ListenerCallback, SubscribeOptions, SubscribeRe
27
27
  * // Set a new value, which triggers the notification.
28
28
  * counter.set(1); // Outputs: "Counter changed to: 1"
29
29
  *
30
+ * // Update value based on the previous value.
31
+ * counter.update(current => current + 1); // Outputs: "Counter changed to: 2"
32
+ *
30
33
  * // Unsubscribe when no longer needed.
31
34
  * subscription.unsubscribe();
32
35
  */
33
36
  export declare class StateSignal<T> extends SignalBase<T> implements IReadonlySignal<T> {
37
+ /**
38
+ * The current value of the signal.
39
+ * @private
40
+ */
34
41
  private value__;
35
- protected logger_: import("@alwatr/logger").AlwatrLogger;
36
42
  /**
37
- * Initializes a new `StateSignal`.
38
- * @param config The configuration for the state signal, including `signalId` and `initialValue`.
43
+ * The logger instance for this signal.
44
+ * @protected
39
45
  */
46
+ protected logger_: import("@alwatr/logger").AlwatrLogger;
40
47
  constructor(config: StateSignalConfig<T>);
41
48
  /**
42
49
  * Retrieves the current value of the signal.
@@ -63,6 +70,22 @@ export declare class StateSignal<T> extends SignalBase<T> implements IReadonlySi
63
70
  * mySignal.set({ ...mySignal.value, property: 'new-value' });
64
71
  */
65
72
  set(newValue: T): void;
73
+ /**
74
+ * Updates the signal's value based on its previous value.
75
+ *
76
+ * This method is particularly useful for state transitions that depend on the current value,
77
+ * especially for objects or arrays, as it promotes an immutable update pattern.
78
+ *
79
+ * @param updater A function that receives the current value and returns the new value.
80
+ *
81
+ * @example
82
+ * // For a counter
83
+ * counterSignal.update(current => current + 1);
84
+ *
85
+ * // For an object state
86
+ * userSignal.update(currentUser => ({ ...currentUser, loggedIn: true }));
87
+ */
88
+ update(updater: (previousValue: T) => T): void;
66
89
  /**
67
90
  * Subscribes a listener to this signal.
68
91
  *
@@ -0,0 +1 @@
1
+ {"version":3,"file":"state-signal.d.ts","sourceRoot":"","sources":["../../src/core/state-signal.ts"],"names":[],"mappings":"AAGA,OAAO,EAAC,UAAU,EAAC,MAAM,kBAAkB,CAAC;AAE5C,OAAO,KAAK,EAAC,iBAAiB,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,eAAe,EAAE,eAAe,EAAC,MAAM,YAAY,CAAC;AAExH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,qBAAa,WAAW,CAAC,CAAC,CAAE,SAAQ,UAAU,CAAC,CAAC,CAAE,YAAW,eAAe,CAAC,CAAC,CAAC;IAC7E;;;OAGG;IACH,OAAO,CAAC,OAAO,CAAI;IAEnB;;;OAGG;IACH,SAAS,CAAC,OAAO,wCAAkD;gBAEhD,MAAM,EAAE,iBAAiB,CAAC,CAAC,CAAC;IAM/C;;;;;;;OAOG;IACH,IAAW,KAAK,IAAI,CAAC,CAGpB;IAED;;;;;;;;;;;;;;OAcG;IACI,GAAG,CAAC,QAAQ,EAAE,CAAC,GAAG,IAAI;IAe7B;;;;;;;;;;;;;;OAcG;IACI,MAAM,CAAC,OAAO,EAAE,CAAC,aAAa,EAAE,CAAC,KAAK,CAAC,GAAG,IAAI;IAQrD;;;;;;;;;OASG;IACa,SAAS,CAAC,QAAQ,EAAE,gBAAgB,CAAC,CAAC,CAAC,EAAE,OAAO,GAAE,gBAAqB,GAAG,eAAe;IAwBzG;;;OAGG;IACa,OAAO,IAAI,IAAI;CAIhC"}
@@ -0,0 +1,34 @@
1
+ import { ComputedSignal } from '../core/computed-signal.js';
2
+ import type { ComputedSignalConfig } from '../type.js';
3
+ /**
4
+ * Creates a read-only signal that derives its value from a set of dependency signals.
5
+ *
6
+ * `ComputedSignal` is a powerful tool for creating values that reactively update when their underlying
7
+ * data sources change. Its value is memoized, meaning the `get` function is only re-evaluated when
8
+ * one of its dependencies has actually changed.
9
+ *
10
+ * A key feature is its lifecycle management: a `ComputedSignal` **must** be destroyed when no longer
11
+ * needed to prevent memory leaks from its subscriptions to dependency signals.
12
+ *
13
+ * @template T The type of the computed value.
14
+ *
15
+ * @param config The configuration for the computed signal.
16
+ * @returns A new, read-only computed signal.
17
+ *
18
+ * @example
19
+ * const firstName = createStateSignal({ signalId: 'firstName', initialValue: 'John' });
20
+ * const lastName = createStateSignal({ signalId: 'lastName', initialValue: 'Doe' });
21
+ *
22
+ * const fullName = createComputedSignal({
23
+ * signalId: 'fullName',
24
+ * deps: [firstName, lastName],
25
+ * get: () => `${firstName.value} ${lastName.value}`,
26
+ * });
27
+ *
28
+ * console.log(fullName.value); // "John Doe"
29
+ *
30
+ * // IMPORTANT: Always destroy a computed signal when no longer needed.
31
+ * // fullName.destroy();
32
+ */
33
+ export declare function createComputedSignal<T>(config: ComputedSignalConfig<T>): ComputedSignal<T>;
34
+ //# sourceMappingURL=computed.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"computed.d.ts","sourceRoot":"","sources":["../../src/creators/computed.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,cAAc,EAAC,MAAM,4BAA4B,CAAC;AAE1D,OAAO,KAAK,EAAC,oBAAoB,EAAC,MAAM,YAAY,CAAC;AAErD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,EAAE,MAAM,EAAE,oBAAoB,CAAC,CAAC,CAAC,GAAG,cAAc,CAAC,CAAC,CAAC,CAE1F"}
@@ -0,0 +1,43 @@
1
+ import { EffectSignal } from '../core/effect-signal.js';
2
+ import type { EffectSignalConfig } from '../type.js';
3
+ /**
4
+ * Creates a side-effect that runs in response to changes in dependency signals.
5
+ *
6
+ * `EffectSignal` is designed for running logic that interacts with the "outside world"—such as
7
+ * logging, network requests, or DOM manipulation—whenever its dependencies are updated.
8
+ * It encapsulates the subscription and cleanup logic, providing a robust and memory-safe
9
+ * way to handle reactive side-effects.
10
+ *
11
+ * A key feature is its lifecycle management: an `EffectSignal` **must** be destroyed when no longer
12
+ * needed to prevent memory leaks and stop the effect from running unnecessarily.
13
+ *
14
+ * @param config The configuration for the effect.
15
+ * @returns An object with a `destroy` method to stop the effect.
16
+ *
17
+ * @example
18
+ * // --- Create dependency signals ---
19
+ * const counter = createStateSignal({ initialValue: 0, signalId: 'counter' });
20
+ * const user = createStateSignal({ initialValue: 'guest', signalId: 'user' });
21
+ *
22
+ * // --- Create an effect ---
23
+ * const analyticsEffect = createEffect({
24
+ * deps: [counter, user],
25
+ * run: () => {
26
+ * console.log(`Analytics: User '${user.value}' clicked ${counter.value} times.`);
27
+ * },
28
+ * runImmediately: true, // Optional: run once on creation
29
+ * });
30
+ * // Immediately logs: "Analytics: User 'guest' clicked 0 times."
31
+ *
32
+ * // --- Trigger the effect by updating a dependency ---
33
+ * counter.set(1);
34
+ * // After a macrotask, logs: "Analytics: User 'guest' clicked 1 times."
35
+ *
36
+ * // --- IMPORTANT: Clean up when the effect is no longer needed ---
37
+ * analyticsEffect.destroy();
38
+ *
39
+ * // Further updates will not trigger the effect.
40
+ * counter.set(2); // Nothing is logged.
41
+ */
42
+ export declare function createEffect(config: EffectSignalConfig): EffectSignal;
43
+ //# sourceMappingURL=effect.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"effect.d.ts","sourceRoot":"","sources":["../../src/creators/effect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,0BAA0B,CAAC;AAEtD,OAAO,KAAK,EAAC,kBAAkB,EAAC,MAAM,YAAY,CAAC;AAEnD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,kBAAkB,GAAG,YAAY,CAErE"}
@@ -0,0 +1,28 @@
1
+ import { EventSignal } from '../core/event-signal.js';
2
+ import type { SignalConfig } from '../type.js';
3
+ /**
4
+ * Creates a stateless signal for dispatching transient events.
5
+ *
6
+ * `EventSignal` is ideal for broadcasting events that do not have a persistent state.
7
+ * Unlike `StateSignal`, it does not hold a value. Listeners are only notified of new
8
+ * events as they are dispatched. This makes it suitable for modeling user interactions,
9
+ * system notifications, or any one-off message.
10
+ *
11
+ * @template T The type of the payload for the events.
12
+ *
13
+ * @param config The configuration for the event signal.
14
+ * @returns A new instance of EventSignal.
15
+ *
16
+ * @example
17
+ * const onUserClick = createEventSignal<{ x: number, y: number }>({
18
+ * signalId: 'on-user-click'
19
+ * });
20
+ *
21
+ * onUserClick.subscribe(pos => {
22
+ * console.log(`User clicked at: ${pos.x}, ${pos.y}`);
23
+ * });
24
+ *
25
+ * onUserClick.dispatch({ x: 100, y: 250 });
26
+ */
27
+ export declare function createEventSignal<T = void>(config: SignalConfig): EventSignal<T>;
28
+ //# sourceMappingURL=event.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event.d.ts","sourceRoot":"","sources":["../../src/creators/event.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,WAAW,EAAC,MAAM,yBAAyB,CAAC;AAEpD,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,YAAY,CAAC;AAE7C;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,GAAG,IAAI,EAAE,MAAM,EAAE,YAAY,GAAG,WAAW,CAAC,CAAC,CAAC,CAEhF"}
@@ -0,0 +1,25 @@
1
+ import { StateSignal } from '../core/state-signal.js';
2
+ import type { StateSignalConfig } from '../type.js';
3
+ /**
4
+ * Creates a stateful signal that holds a value and notifies listeners when the value changes.
5
+ *
6
+ * `StateSignal` is the core of the signal library, representing a piece of mutable state.
7
+ * It always has a value, and new subscribers immediately receive the current value by default.
8
+ *
9
+ * @template T The type of the state it holds.
10
+ *
11
+ * @param config The configuration for the state signal.
12
+ * @returns A new instance of StateSignal.
13
+ *
14
+ * @example
15
+ * const counter = createStateSignal({
16
+ * signalId: 'counter-signal',
17
+ * initialValue: 0,
18
+ * });
19
+ *
20
+ * console.log(counter.value); // Outputs: 0
21
+ * counter.set(1);
22
+ * console.log(counter.value); // Outputs: 1
23
+ */
24
+ export declare function createStateSignal<T>(config: StateSignalConfig<T>): StateSignal<T>;
25
+ //# sourceMappingURL=state.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../src/creators/state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,WAAW,EAAC,MAAM,yBAAyB,CAAC;AAEpD,OAAO,KAAK,EAAC,iBAAiB,EAAC,MAAM,YAAY,CAAC;AAElD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,MAAM,EAAE,iBAAiB,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,CAEjF"}