@alwatr/signal 5.1.0 → 5.2.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/CHANGELOG.md +32 -0
- package/README.md +12 -12
- package/dist/core/computed-signal.d.ts +38 -11
- package/dist/core/computed-signal.d.ts.map +1 -1
- package/dist/core/effect-signal.d.ts +26 -4
- package/dist/core/effect-signal.d.ts.map +1 -1
- package/dist/core/event-signal.d.ts +4 -0
- package/dist/core/event-signal.d.ts.map +1 -1
- package/dist/core/signal-base.d.ts +16 -8
- package/dist/core/signal-base.d.ts.map +1 -1
- package/dist/core/state-signal.d.ts +12 -4
- package/dist/core/state-signal.d.ts.map +1 -1
- package/dist/creators/computed.d.ts +2 -2
- package/dist/creators/effect.d.ts +1 -1
- package/dist/creators/state.d.ts +2 -2
- package/dist/main.cjs +143 -77
- package/dist/main.cjs.map +2 -2
- package/dist/main.mjs +143 -77
- package/dist/main.mjs.map +2 -2
- package/dist/operators/debounce.d.ts +2 -2
- package/dist/operators/filter.d.ts +2 -2
- package/dist/operators/filter.d.ts.map +1 -1
- package/dist/operators/map.d.ts +2 -2
- package/dist/type.d.ts +32 -8
- package/dist/type.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/core/computed-signal.test.js +6 -6
- package/src/core/state-signal.test.js +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,38 @@
|
|
|
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.1](https://github.com/Alwatr/flux/compare/v5.2.0...v5.2.1) (2025-09-15)
|
|
7
|
+
|
|
8
|
+
### ⚡ Performance Improvements
|
|
9
|
+
|
|
10
|
+
* To improve readability and avoid calling sourceSignal.get() twice, used temporary variable before using it. ([2aaa3bd](https://github.com/Alwatr/flux/commit/2aaa3bdd06745885495ca64a71c4040b9ec57cea))
|
|
11
|
+
|
|
12
|
+
### 🔨 Code Refactoring
|
|
13
|
+
|
|
14
|
+
* change the `signal.value` to `signal.get()` ([fcdcb6c](https://github.com/Alwatr/flux/commit/fcdcb6caf82747b8e6d7ad846d6babead385c603))
|
|
15
|
+
* rename run_ method to scheduleExecution_ for clarity in EffectSignal ([402af2f](https://github.com/Alwatr/flux/commit/402af2f7b84357ade4f79b33611d6968ec6b8efd))
|
|
16
|
+
|
|
17
|
+
## [5.2.0](https://github.com/Alwatr/flux/compare/v5.1.0...v5.2.0) (2025-09-15)
|
|
18
|
+
|
|
19
|
+
### ✨ Features
|
|
20
|
+
|
|
21
|
+
* Add comprehensive documentation to the repository ([d5569e6](https://github.com/Alwatr/flux/commit/d5569e63acd0aa926c34d9a61b2fff5139b9d3cc))
|
|
22
|
+
* Update EffectSignalConfig to allow optional signalId and add documentation ([6aab97e](https://github.com/Alwatr/flux/commit/6aab97e6e223f822f66cacb78c9d194fa5e2df9d))
|
|
23
|
+
|
|
24
|
+
### 🐛 Bug Fixes
|
|
25
|
+
|
|
26
|
+
* Refactor logger initialization and ensure checkDestroyed_ is called in relevant methods ([a17884d](https://github.com/Alwatr/flux/commit/a17884d5df097d62353e5b4110d3a83a5ae093b3))
|
|
27
|
+
|
|
28
|
+
### 🔨 Code Refactoring
|
|
29
|
+
|
|
30
|
+
* Ensure isRunning__ is reset when destroyed during delay in EffectSignal ([ff9a590](https://github.com/Alwatr/flux/commit/ff9a5905f7875e7dcb675cbdbb44869b0743e954))
|
|
31
|
+
* Improve signal management by consolidating destruction checks and enhancing logging ([8765ba2](https://github.com/Alwatr/flux/commit/8765ba2f701f10db89ef11a3045065442360d193))
|
|
32
|
+
* Remove unnecessary binding of notify_ in EventSignal constructor ([eb3be32](https://github.com/Alwatr/flux/commit/eb3be3211b13c21aa4f5c16a37f5c9fc59144951))
|
|
33
|
+
* Simplify ComputedSignal implementation and improve logging for lifecycle methods ([bc35e91](https://github.com/Alwatr/flux/commit/bc35e91d5871669cc22c6c92ee2b83c4d940194e))
|
|
34
|
+
* Simplify EffectSignal implementation and improve logging for lifecycle methods ([a5cad04](https://github.com/Alwatr/flux/commit/a5cad04469efd929e2ce7da42b371d4c054e5eaf))
|
|
35
|
+
* Simplify EventSignal logger initialization and constructor ([b515315](https://github.com/Alwatr/flux/commit/b515315428e8ba0c70a7ef5ede49916e899b6fcd))
|
|
36
|
+
* Update logger step identifiers for recalculation in ComputedSignal ([8de799f](https://github.com/Alwatr/flux/commit/8de799f40d90c2cdc3440d90bc1f2b6ce22f7013))
|
|
37
|
+
|
|
6
38
|
## [5.1.0](https://github.com/Alwatr/flux/compare/v5.0.0...v5.1.0) (2025-09-14)
|
|
7
39
|
|
|
8
40
|
### ✨ Features
|
package/README.md
CHANGED
|
@@ -69,10 +69,10 @@ import {ComputedSignal} from '@alwatr/signal';
|
|
|
69
69
|
const fullName = new ComputedSignal<string>({
|
|
70
70
|
signalId: 'user-fullName',
|
|
71
71
|
deps: [firstName], // This computed signal depends on firstName.
|
|
72
|
-
get: () => `User: ${firstName.
|
|
72
|
+
get: () => `User: ${firstName.get()}`,
|
|
73
73
|
});
|
|
74
74
|
|
|
75
|
-
console.log(fullName.
|
|
75
|
+
console.log(fullName.get()); // Outputs: "User: John"
|
|
76
76
|
```
|
|
77
77
|
|
|
78
78
|
### 4. Create an Effect Signal
|
|
@@ -85,7 +85,7 @@ import {EffectSignal} from '@alwatr/signal';
|
|
|
85
85
|
const loggerEffect = new EffectSignal({
|
|
86
86
|
deps: [fullName, counter], // This effect depends on fullName and counter.
|
|
87
87
|
run: () => {
|
|
88
|
-
console.log(`${fullName.
|
|
88
|
+
console.log(`${fullName.get()} has clicked ${counter.get()} times.`);
|
|
89
89
|
},
|
|
90
90
|
});
|
|
91
91
|
```
|
|
@@ -134,7 +134,7 @@ Signals that depend on other signals (like `ComputedSignal` and `EffectSignal`)
|
|
|
134
134
|
// Create a computed signal
|
|
135
135
|
const isEven = new ComputedSignal({
|
|
136
136
|
deps: [counter],
|
|
137
|
-
get: () => counter.
|
|
137
|
+
get: () => counter.get() % 2 === 0,
|
|
138
138
|
});
|
|
139
139
|
|
|
140
140
|
// ... use it for a while ...
|
|
@@ -167,7 +167,7 @@ The `subscribe` method accepts an optional second argument to customize its beha
|
|
|
167
167
|
- **`constructor(config)`**: Creates a new state signal.
|
|
168
168
|
- `config.signalId`: `string`
|
|
169
169
|
- `config.initialValue`: `T`
|
|
170
|
-
- **`.
|
|
170
|
+
- **`.get()`**: `T` - Gets the current value.
|
|
171
171
|
- **`.set(newValue: T)`**: Sets a new value and notifies listeners.
|
|
172
172
|
|
|
173
173
|
### `ComputedSignal<T>`
|
|
@@ -176,7 +176,7 @@ The `subscribe` method accepts an optional second argument to customize its beha
|
|
|
176
176
|
- `config.signalId`: `string`
|
|
177
177
|
- `config.deps`: `IReadonlySignal<unknown>[]` - Array of dependency signals.
|
|
178
178
|
- `config.get`: `() => T` - The function to compute the value.
|
|
179
|
-
- **`.
|
|
179
|
+
- **`.get()`**: `T` - Gets the current (memoized) value.
|
|
180
180
|
- **`.destroy()`**: Cleans up the signal's subscriptions. **(Important!)**
|
|
181
181
|
|
|
182
182
|
### `EffectSignal`
|
|
@@ -284,10 +284,10 @@ import {ComputedSignal} from '@alwatr/signal';
|
|
|
284
284
|
const fullName = new ComputedSignal<string>({
|
|
285
285
|
signalId: 'user-fullName',
|
|
286
286
|
deps: [firstName], // این سیگنال محاسباتی به firstName وابسته است
|
|
287
|
-
get: () => `User: ${firstName.
|
|
287
|
+
get: () => `User: ${firstName.get()}`,
|
|
288
288
|
});
|
|
289
289
|
|
|
290
|
-
console.log(fullName.
|
|
290
|
+
console.log(fullName.get()); // خروجی: "User: John"
|
|
291
291
|
```
|
|
292
292
|
|
|
293
293
|
### ۴. ایجاد `EffectSignal`
|
|
@@ -300,7 +300,7 @@ import {EffectSignal} from '@alwatr/signal';
|
|
|
300
300
|
const loggerEffect = new EffectSignal({
|
|
301
301
|
deps: [fullName, counter], // این افکت به fullName و counter وابسته است
|
|
302
302
|
run: () => {
|
|
303
|
-
console.log(`${fullName.
|
|
303
|
+
console.log(`${fullName.get()} has clicked ${counter.get()} times.`);
|
|
304
304
|
},
|
|
305
305
|
});
|
|
306
306
|
```
|
|
@@ -349,7 +349,7 @@ User: Jane has clicked 1 times.
|
|
|
349
349
|
// یک سیگنال محاسباتی ایجاد کنید
|
|
350
350
|
const isEven = new ComputedSignal({
|
|
351
351
|
deps: [counter],
|
|
352
|
-
get: () => counter.
|
|
352
|
+
get: () => counter.get() % 2 === 0,
|
|
353
353
|
});
|
|
354
354
|
|
|
355
355
|
// ... مدتی از آن استفاده کنید ...
|
|
@@ -382,7 +382,7 @@ Alwatr Signal از یک مدل ناهمزمان قابل پیشبینی بر
|
|
|
382
382
|
- **`constructor(config)`**: یک سیگنال وضعیت جدید ایجاد میکند.
|
|
383
383
|
- `config.signalId`: `string`
|
|
384
384
|
- `config.initialValue`: `T`
|
|
385
|
-
- **`.
|
|
385
|
+
- **`.get()`**: `T` - مقدار فعلی را دریافت میکند.
|
|
386
386
|
- **`.set(newValue: T)`**: مقدار جدیدی را تنظیم کرده و شنوندگان را مطلع میکند.
|
|
387
387
|
|
|
388
388
|
### `ComputedSignal<T>`
|
|
@@ -391,7 +391,7 @@ Alwatr Signal از یک مدل ناهمزمان قابل پیشبینی بر
|
|
|
391
391
|
- `config.signalId`: `string`
|
|
392
392
|
- `config.deps`: `IReadonlySignal<unknown>[]` - آرایهای از سیگنالهای وابسته.
|
|
393
393
|
- `config.get`: `() => T` - تابعی برای محاسبه مقدار.
|
|
394
|
-
- **`.
|
|
394
|
+
- **`.get()`**: `T` - مقدار فعلی (کش شده) را دریافت میکند.
|
|
395
395
|
- **`.destroy()`**: اشتراکهای سیگنال را پاکسازی میکند. **(مهم!)**
|
|
396
396
|
|
|
397
397
|
### `EffectSignal`
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { StateSignal } from './state-signal.js';
|
|
2
|
-
import type { ComputedSignalConfig, IReadonlySignal, 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, IReadonlySignal, SubscribeResult } from '../
|
|
|
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 ---
|
|
@@ -22,10 +21,10 @@ import type { ComputedSignalConfig, IReadonlySignal, SubscribeResult } from '../
|
|
|
22
21
|
* const fullName = new ComputedSignal({
|
|
23
22
|
* signalId: 'fullName',
|
|
24
23
|
* deps: [firstName, lastName],
|
|
25
|
-
* get: () => `${firstName.
|
|
24
|
+
* get: () => `${firstName.get()} ${lastName.get()}`,
|
|
26
25
|
* });
|
|
27
26
|
*
|
|
28
|
-
* console.log(fullName.
|
|
27
|
+
* console.log(fullName.get()); // Outputs: "John Doe"
|
|
29
28
|
*
|
|
30
29
|
* // --- Subscribe to the computed value ---
|
|
31
30
|
* fullName.subscribe(newFullName => {
|
|
@@ -34,22 +33,37 @@ import type { ComputedSignalConfig, IReadonlySignal, SubscribeResult } from '../
|
|
|
34
33
|
*
|
|
35
34
|
* // --- Update a dependency ---
|
|
36
35
|
* lastName.set('Smith'); // Recalculates and logs: "Name changed to: John Smith"
|
|
37
|
-
* console.log(fullName.
|
|
36
|
+
* console.log(fullName.get()); // Outputs: "John Smith"
|
|
38
37
|
*
|
|
39
38
|
* // --- IMPORTANT: Clean up when done ---
|
|
40
39
|
* fullName.destroy();
|
|
41
40
|
*/
|
|
42
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.
|
|
48
|
-
* This is how the computed signal provides `.
|
|
54
|
+
* This is how the computed signal provides `.get()` and `.subscribe()` methods.
|
|
49
55
|
* @protected
|
|
50
56
|
*/
|
|
51
57
|
protected readonly internalSignal_: StateSignal<T>;
|
|
52
|
-
|
|
58
|
+
/**
|
|
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
|
|
66
|
+
*/
|
|
53
67
|
private isRecalculating__;
|
|
54
68
|
constructor(config_: ComputedSignalConfig<T>);
|
|
55
69
|
/**
|
|
@@ -59,15 +73,28 @@ export declare class ComputedSignal<T> implements IReadonlySignal<T> {
|
|
|
59
73
|
* @returns The current computed value.
|
|
60
74
|
* @throws {Error} If accessed after the signal has been destroyed.
|
|
61
75
|
*/
|
|
62
|
-
get
|
|
76
|
+
get(): T;
|
|
63
77
|
/**
|
|
64
78
|
* Indicates whether the computed signal has been destroyed.
|
|
65
79
|
* A destroyed signal cannot be used and will throw an error if interacted with.
|
|
66
80
|
* @returns `true` if the signal is destroyed, `false` otherwise.
|
|
67
81
|
*/
|
|
68
82
|
get isDestroyed(): boolean;
|
|
69
|
-
|
|
70
|
-
|
|
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>;
|
|
71
98
|
/**
|
|
72
99
|
* Permanently disposes of the computed signal.
|
|
73
100
|
*
|
|
@@ -75,7 +102,7 @@ export declare class ComputedSignal<T> implements IReadonlySignal<T> {
|
|
|
75
102
|
* stopping future recalculations and allowing the signal to be garbage collected.
|
|
76
103
|
* Failure to call `destroy()` will result in memory leaks.
|
|
77
104
|
*
|
|
78
|
-
* After `destroy()` is called, any attempt to access `.
|
|
105
|
+
* After `destroy()` is called, any attempt to access `.get()` or `.subscribe()` will throw an error.
|
|
79
106
|
*/
|
|
80
107
|
destroy(): void;
|
|
81
108
|
/**
|
|
@@ -1 +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,EAAC,MAAM,YAAY,CAAC;
|
|
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;IACI,GAAG,IAAI,CAAC;IAIf;;;;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"}
|
|
@@ -19,9 +19,10 @@ 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
|
-
* console.log(`Analytics: User '${user.
|
|
25
|
+
* console.log(`Analytics: User '${user.get()}' clicked ${counter.get()} times.`);
|
|
25
26
|
* },
|
|
26
27
|
* runImmediately: true, // Optional: run once on creation
|
|
27
28
|
* });
|
|
@@ -39,13 +40,34 @@ 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
|
-
|
|
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
|
|
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;
|
|
@@ -58,7 +80,7 @@ export declare class EffectSignal implements IEffectSignal {
|
|
|
58
80
|
* dependencies change simultaneously.
|
|
59
81
|
* @protected
|
|
60
82
|
*/
|
|
61
|
-
protected
|
|
83
|
+
protected scheduleExecution_(): Promise<void>;
|
|
62
84
|
/**
|
|
63
85
|
* Permanently disposes of the effect signal.
|
|
64
86
|
*
|
|
@@ -1 +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
|
|
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,kBAAkB,IAAI,OAAO,CAAC,IAAI,CAAC;IAmCnD;;;;;;OAMG;IACI,OAAO,IAAI,IAAI;CAmBvB"}
|
|
@@ -28,6 +28,10 @@ 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
|
+
/**
|
|
32
|
+
* The logger instance for this signal.
|
|
33
|
+
* @protected
|
|
34
|
+
*/
|
|
31
35
|
protected logger_: import("@alwatr/logger").AlwatrLogger;
|
|
32
36
|
constructor(config: SignalConfig);
|
|
33
37
|
/**
|
|
@@ -1 +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,SAAS,CAAC,OAAO,wCAAkD;gBAEhD,MAAM,EAAE,YAAY;IAKvC;;;;;;OAMG;IACI,QAAQ,CAAC,OAAO,EAAE,CAAC,GAAG,IAAI;
|
|
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"}
|
|
@@ -2,35 +2,43 @@ import type { Observer_, SubscribeOptions, SubscribeResult, ListenerCallback, Si
|
|
|
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
|
-
*
|
|
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> {
|
|
13
10
|
protected config_: SignalConfig;
|
|
14
11
|
/**
|
|
15
|
-
* The unique identifier for this signal instance.
|
|
12
|
+
* The unique identifier for this signal instance.
|
|
13
|
+
* Useful for debugging and logging.
|
|
16
14
|
*/
|
|
17
15
|
readonly signalId: string;
|
|
16
|
+
/**
|
|
17
|
+
* The logger instance for this signal.
|
|
18
|
+
* @protected
|
|
19
|
+
*/
|
|
18
20
|
protected abstract logger_: AlwatrLogger;
|
|
19
21
|
/**
|
|
20
22
|
* The list of observers (listeners) subscribed to this signal.
|
|
21
23
|
* @protected
|
|
22
24
|
*/
|
|
23
25
|
protected readonly observers_: Observer_<T>[];
|
|
24
|
-
|
|
26
|
+
/**
|
|
27
|
+
* A flag indicating whether the signal has been destroyed.
|
|
28
|
+
* @private
|
|
29
|
+
*/
|
|
30
|
+
private isDestroyed__;
|
|
25
31
|
/**
|
|
26
32
|
* Indicates whether the signal has been destroyed.
|
|
27
33
|
* A destroyed signal cannot be used and will throw an error if interacted with.
|
|
34
|
+
*
|
|
28
35
|
* @returns `true` if the signal is destroyed, `false` otherwise.
|
|
29
36
|
*/
|
|
30
37
|
get isDestroyed(): boolean;
|
|
31
38
|
constructor(config_: SignalConfig);
|
|
32
39
|
/**
|
|
33
40
|
* Removes a specific observer from the observers list.
|
|
41
|
+
*
|
|
34
42
|
* @param observer The observer instance to remove.
|
|
35
43
|
* @protected
|
|
36
44
|
*/
|
|
@@ -82,6 +90,6 @@ export declare abstract class SignalBase<T> {
|
|
|
82
90
|
* This is a safeguard to prevent interaction with a defunct signal.
|
|
83
91
|
* @protected
|
|
84
92
|
*/
|
|
85
|
-
protected checkDestroyed_
|
|
93
|
+
protected checkDestroyed_(): void;
|
|
86
94
|
}
|
|
87
95
|
//# sourceMappingURL=signal-base.d.ts.map
|
|
@@ -1 +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
|
|
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"}
|
|
@@ -17,7 +17,7 @@ import type { StateSignalConfig, ListenerCallback, SubscribeOptions, SubscribeRe
|
|
|
17
17
|
* });
|
|
18
18
|
*
|
|
19
19
|
* // Get the current value.
|
|
20
|
-
* console.log(counter.
|
|
20
|
+
* console.log(counter.get()); // Outputs: 0
|
|
21
21
|
*
|
|
22
22
|
* // Subscribe to changes.
|
|
23
23
|
* const subscription = counter.subscribe(newValue => {
|
|
@@ -34,7 +34,15 @@ import type { StateSignalConfig, ListenerCallback, SubscribeOptions, SubscribeRe
|
|
|
34
34
|
* subscription.unsubscribe();
|
|
35
35
|
*/
|
|
36
36
|
export declare class StateSignal<T> extends SignalBase<T> implements IReadonlySignal<T> {
|
|
37
|
+
/**
|
|
38
|
+
* The current value of the signal.
|
|
39
|
+
* @private
|
|
40
|
+
*/
|
|
37
41
|
private value__;
|
|
42
|
+
/**
|
|
43
|
+
* The logger instance for this signal.
|
|
44
|
+
* @protected
|
|
45
|
+
*/
|
|
38
46
|
protected logger_: import("@alwatr/logger").AlwatrLogger;
|
|
39
47
|
constructor(config: StateSignalConfig<T>);
|
|
40
48
|
/**
|
|
@@ -43,9 +51,9 @@ export declare class StateSignal<T> extends SignalBase<T> implements IReadonlySi
|
|
|
43
51
|
* @returns The current value.
|
|
44
52
|
*
|
|
45
53
|
* @example
|
|
46
|
-
* console.log(mySignal.
|
|
54
|
+
* console.log(mySignal.get());
|
|
47
55
|
*/
|
|
48
|
-
get
|
|
56
|
+
get(): T;
|
|
49
57
|
/**
|
|
50
58
|
* Updates the signal's value and notifies all active listeners.
|
|
51
59
|
*
|
|
@@ -59,7 +67,7 @@ export declare class StateSignal<T> extends SignalBase<T> implements IReadonlySi
|
|
|
59
67
|
* mySignal.set(42);
|
|
60
68
|
*
|
|
61
69
|
* // For object types, it's best practice to set an immutable new object.
|
|
62
|
-
* mySignal.set({ ...mySignal.
|
|
70
|
+
* mySignal.set({ ...mySignal.get(), property: 'new-value' });
|
|
63
71
|
*/
|
|
64
72
|
set(newValue: T): void;
|
|
65
73
|
/**
|
|
@@ -1 +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,OAAO,CAAC,OAAO,CAAI;
|
|
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;IACI,GAAG,IAAI,CAAC;IAKf;;;;;;;;;;;;;;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"}
|
|
@@ -22,10 +22,10 @@ import type { ComputedSignalConfig } from '../type.js';
|
|
|
22
22
|
* const fullName = createComputedSignal({
|
|
23
23
|
* signalId: 'fullName',
|
|
24
24
|
* deps: [firstName, lastName],
|
|
25
|
-
* get: () => `${firstName.
|
|
25
|
+
* get: () => `${firstName.get()} ${lastName.get()}`,
|
|
26
26
|
* });
|
|
27
27
|
*
|
|
28
|
-
* console.log(fullName.
|
|
28
|
+
* console.log(fullName.get()); // "John Doe"
|
|
29
29
|
*
|
|
30
30
|
* // IMPORTANT: Always destroy a computed signal when no longer needed.
|
|
31
31
|
* // fullName.destroy();
|
|
@@ -23,7 +23,7 @@ import type { EffectSignalConfig } from '../type.js';
|
|
|
23
23
|
* const analyticsEffect = createEffect({
|
|
24
24
|
* deps: [counter, user],
|
|
25
25
|
* run: () => {
|
|
26
|
-
* console.log(`Analytics: User '${user.
|
|
26
|
+
* console.log(`Analytics: User '${user.get()}' clicked ${counter.get()} times.`);
|
|
27
27
|
* },
|
|
28
28
|
* runImmediately: true, // Optional: run once on creation
|
|
29
29
|
* });
|
package/dist/creators/state.d.ts
CHANGED
|
@@ -17,9 +17,9 @@ import type { StateSignalConfig } from '../type.js';
|
|
|
17
17
|
* initialValue: 0,
|
|
18
18
|
* });
|
|
19
19
|
*
|
|
20
|
-
* console.log(counter.
|
|
20
|
+
* console.log(counter.get()); // Outputs: 0
|
|
21
21
|
* counter.set(1);
|
|
22
|
-
* console.log(counter.
|
|
22
|
+
* console.log(counter.get()); // Outputs: 1
|
|
23
23
|
*/
|
|
24
24
|
export declare function createStateSignal<T>(config: StateSignalConfig<T>): StateSignal<T>;
|
|
25
25
|
//# sourceMappingURL=state.d.ts.map
|