@alwatr/signal 5.1.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.
- package/CHANGELOG.md +21 -0
- package/dist/core/computed-signal.d.ts +32 -5
- package/dist/core/computed-signal.d.ts.map +1 -1
- package/dist/core/effect-signal.d.ts +24 -2
- 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 +8 -0
- package/dist/core/state-signal.d.ts.map +1 -1
- package/dist/main.cjs +128 -62
- package/dist/main.cjs.map +2 -2
- package/dist/main.mjs +128 -62
- package/dist/main.mjs.map +2 -2
- package/dist/type.d.ts +29 -5
- package/dist/type.d.ts.map +1 -1
- package/package.json +2 -2
package/dist/main.mjs
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
/* @alwatr/signal v5.
|
|
1
|
+
/* @alwatr/signal v5.2.0 */
|
|
2
2
|
|
|
3
3
|
// src/core/signal-base.ts
|
|
4
4
|
var SignalBase = class {
|
|
5
5
|
constructor(config_) {
|
|
6
6
|
this.config_ = config_;
|
|
7
7
|
/**
|
|
8
|
-
* The unique identifier for this signal instance.
|
|
8
|
+
* The unique identifier for this signal instance.
|
|
9
|
+
* Useful for debugging and logging.
|
|
9
10
|
*/
|
|
10
11
|
this.signalId = this.config_.signalId;
|
|
11
12
|
/**
|
|
@@ -13,38 +14,33 @@ var SignalBase = class {
|
|
|
13
14
|
* @protected
|
|
14
15
|
*/
|
|
15
16
|
this.observers_ = [];
|
|
16
|
-
this.isDestroyed_ = false;
|
|
17
17
|
/**
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* @protected
|
|
18
|
+
* A flag indicating whether the signal has been destroyed.
|
|
19
|
+
* @private
|
|
21
20
|
*/
|
|
22
|
-
this.
|
|
23
|
-
if (this.isDestroyed_) {
|
|
24
|
-
this.logger_.accident("checkDestroyed_", "attempt_to_use_destroyed_signal");
|
|
25
|
-
throw new Error(`Cannot interact with a destroyed signal (id: ${this.signalId})`);
|
|
26
|
-
}
|
|
27
|
-
};
|
|
21
|
+
this.isDestroyed__ = false;
|
|
28
22
|
}
|
|
29
23
|
/**
|
|
30
24
|
* Indicates whether the signal has been destroyed.
|
|
31
25
|
* A destroyed signal cannot be used and will throw an error if interacted with.
|
|
26
|
+
*
|
|
32
27
|
* @returns `true` if the signal is destroyed, `false` otherwise.
|
|
33
28
|
*/
|
|
34
29
|
get isDestroyed() {
|
|
35
|
-
return this.
|
|
30
|
+
return this.isDestroyed__;
|
|
36
31
|
}
|
|
37
32
|
/**
|
|
38
33
|
* Removes a specific observer from the observers list.
|
|
34
|
+
*
|
|
39
35
|
* @param observer The observer instance to remove.
|
|
40
36
|
* @protected
|
|
41
37
|
*/
|
|
42
38
|
removeObserver_(observer) {
|
|
43
|
-
|
|
39
|
+
this.logger_.logMethod?.("removeObserver_");
|
|
40
|
+
if (this.isDestroyed__) {
|
|
44
41
|
this.logger_.incident?.("removeObserver_", "remove_observer_on_destroyed_signal");
|
|
45
42
|
return;
|
|
46
43
|
}
|
|
47
|
-
this.logger_.logMethod?.("removeObserver_");
|
|
48
44
|
const index = this.observers_.indexOf(observer);
|
|
49
45
|
if (index !== -1) {
|
|
50
46
|
this.observers_.splice(index, 1);
|
|
@@ -68,8 +64,9 @@ var SignalBase = class {
|
|
|
68
64
|
} else {
|
|
69
65
|
this.observers_.push(observer);
|
|
70
66
|
}
|
|
71
|
-
|
|
72
|
-
|
|
67
|
+
return {
|
|
68
|
+
unsubscribe: () => this.removeObserver_(observer)
|
|
69
|
+
};
|
|
73
70
|
}
|
|
74
71
|
/**
|
|
75
72
|
* Notifies all registered observers about a new value.
|
|
@@ -81,11 +78,11 @@ var SignalBase = class {
|
|
|
81
78
|
* @protected
|
|
82
79
|
*/
|
|
83
80
|
notify_(value) {
|
|
84
|
-
|
|
81
|
+
this.logger_.logMethodArgs?.("notify_", value);
|
|
82
|
+
if (this.isDestroyed__) {
|
|
85
83
|
this.logger_.incident?.("notify_", "notify_on_destroyed_signal");
|
|
86
84
|
return;
|
|
87
85
|
}
|
|
88
|
-
this.logger_.logMethodArgs?.("notify_", value);
|
|
89
86
|
const currentObservers = [...this.observers_];
|
|
90
87
|
for (const observer of currentObservers) {
|
|
91
88
|
if (observer.options?.once) {
|
|
@@ -94,9 +91,7 @@ var SignalBase = class {
|
|
|
94
91
|
try {
|
|
95
92
|
const result = observer.callback(value);
|
|
96
93
|
if (result instanceof Promise) {
|
|
97
|
-
result.catch((err) => {
|
|
98
|
-
this.logger_.error("notify_", "async_callback_failed", err, { observer });
|
|
99
|
-
});
|
|
94
|
+
result.catch((err) => this.logger_.error("notify_", "async_callback_failed", err, { observer }));
|
|
100
95
|
}
|
|
101
96
|
} catch (err) {
|
|
102
97
|
this.logger_.error("notify_", "sync_callback_failed", err);
|
|
@@ -138,12 +133,26 @@ var SignalBase = class {
|
|
|
138
133
|
*/
|
|
139
134
|
destroy() {
|
|
140
135
|
this.logger_.logMethod?.("destroy");
|
|
141
|
-
if (this.
|
|
142
|
-
|
|
136
|
+
if (this.isDestroyed__) {
|
|
137
|
+
this.logger_.incident?.("destroy_", "double_destroy_attempt");
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
this.isDestroyed__ = true;
|
|
143
141
|
this.observers_.length = 0;
|
|
144
142
|
this.config_.onDestroy?.();
|
|
145
143
|
this.config_ = null;
|
|
146
144
|
}
|
|
145
|
+
/**
|
|
146
|
+
* Throws an error if the signal has been destroyed.
|
|
147
|
+
* This is a safeguard to prevent interaction with a defunct signal.
|
|
148
|
+
* @protected
|
|
149
|
+
*/
|
|
150
|
+
checkDestroyed_() {
|
|
151
|
+
if (this.isDestroyed__) {
|
|
152
|
+
this.logger_.accident("checkDestroyed_", "attempt_to_use_destroyed_signal");
|
|
153
|
+
throw new Error(`Cannot interact with a destroyed signal (id: ${this.signalId})`);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
147
156
|
};
|
|
148
157
|
|
|
149
158
|
// src/core/event-signal.ts
|
|
@@ -152,6 +161,10 @@ import { createLogger } from "@alwatr/logger";
|
|
|
152
161
|
var EventSignal = class extends SignalBase {
|
|
153
162
|
constructor(config) {
|
|
154
163
|
super(config);
|
|
164
|
+
/**
|
|
165
|
+
* The logger instance for this signal.
|
|
166
|
+
* @protected
|
|
167
|
+
*/
|
|
155
168
|
this.logger_ = createLogger(`event-signal: ${this.signalId}`);
|
|
156
169
|
this.logger_.logMethod?.("constructor");
|
|
157
170
|
}
|
|
@@ -163,11 +176,9 @@ var EventSignal = class extends SignalBase {
|
|
|
163
176
|
* @param payload The data to send with the event.
|
|
164
177
|
*/
|
|
165
178
|
dispatch(payload) {
|
|
166
|
-
this.logger_.logMethodArgs?.("dispatch", payload);
|
|
179
|
+
this.logger_.logMethodArgs?.("dispatch", { payload });
|
|
167
180
|
this.checkDestroyed_();
|
|
168
|
-
delay.nextMicrotask().then(() =>
|
|
169
|
-
this.notify_(payload);
|
|
170
|
-
});
|
|
181
|
+
delay.nextMicrotask().then(() => this.notify_(payload));
|
|
171
182
|
}
|
|
172
183
|
};
|
|
173
184
|
|
|
@@ -177,6 +188,10 @@ import { createLogger as createLogger2 } from "@alwatr/logger";
|
|
|
177
188
|
var StateSignal = class extends SignalBase {
|
|
178
189
|
constructor(config) {
|
|
179
190
|
super(config);
|
|
191
|
+
/**
|
|
192
|
+
* The logger instance for this signal.
|
|
193
|
+
* @protected
|
|
194
|
+
*/
|
|
180
195
|
this.logger_ = createLogger2(`state-signal: ${this.signalId}`);
|
|
181
196
|
this.value__ = config.initialValue;
|
|
182
197
|
this.logger_.logMethodArgs?.("constructor", { initialValue: this.value__ });
|
|
@@ -211,11 +226,11 @@ var StateSignal = class extends SignalBase {
|
|
|
211
226
|
set(newValue) {
|
|
212
227
|
this.logger_.logMethodArgs?.("set", { newValue });
|
|
213
228
|
this.checkDestroyed_();
|
|
214
|
-
if (Object.is(this.value__, newValue) && (typeof newValue !== "object" || newValue === null))
|
|
229
|
+
if (Object.is(this.value__, newValue) && (typeof newValue !== "object" || newValue === null)) {
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
215
232
|
this.value__ = newValue;
|
|
216
|
-
delay2.nextMicrotask().then(() =>
|
|
217
|
-
this.notify_(newValue);
|
|
218
|
-
});
|
|
233
|
+
delay2.nextMicrotask().then(() => this.notify_(newValue));
|
|
219
234
|
}
|
|
220
235
|
/**
|
|
221
236
|
* Updates the signal's value based on its previous value.
|
|
@@ -250,11 +265,8 @@ var StateSignal = class extends SignalBase {
|
|
|
250
265
|
subscribe(callback, options = {}) {
|
|
251
266
|
this.logger_.logMethodArgs?.("subscribe", { options });
|
|
252
267
|
this.checkDestroyed_();
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
delay2.nextMicrotask().then(() => callback(this.value__)).catch((err) => {
|
|
256
|
-
this.logger_.error("subscribe", "run_callback_immediate_failed", err);
|
|
257
|
-
});
|
|
268
|
+
if (options.receivePrevious !== false) {
|
|
269
|
+
delay2.nextMicrotask().then(() => callback(this.value__)).catch((err) => this.logger_.error("subscribe", "immediate_callback_failed", err));
|
|
258
270
|
if (options.once) {
|
|
259
271
|
return { unsubscribe: () => {
|
|
260
272
|
} };
|
|
@@ -278,7 +290,14 @@ import { createLogger as createLogger3 } from "@alwatr/logger";
|
|
|
278
290
|
var ComputedSignal = class {
|
|
279
291
|
constructor(config_) {
|
|
280
292
|
this.config_ = config_;
|
|
293
|
+
/**
|
|
294
|
+
* The unique identifier for this signal instance.
|
|
295
|
+
*/
|
|
281
296
|
this.signalId = this.config_.signalId;
|
|
297
|
+
/**
|
|
298
|
+
* The logger instance for this signal.
|
|
299
|
+
* @protected
|
|
300
|
+
*/
|
|
282
301
|
this.logger_ = createLogger3(`computed-signal: ${this.signalId}`);
|
|
283
302
|
/**
|
|
284
303
|
* The internal `StateSignal` that holds the computed value.
|
|
@@ -286,17 +305,23 @@ var ComputedSignal = class {
|
|
|
286
305
|
* @protected
|
|
287
306
|
*/
|
|
288
307
|
this.internalSignal_ = new StateSignal({
|
|
289
|
-
signalId: this.signalId
|
|
308
|
+
signalId: `${this.signalId}-internal`,
|
|
290
309
|
initialValue: this.config_.get()
|
|
291
310
|
});
|
|
292
|
-
|
|
311
|
+
/**
|
|
312
|
+
* A list of subscriptions to dependency signals.
|
|
313
|
+
* @private
|
|
314
|
+
*/
|
|
315
|
+
this.dependencySubscriptions__ = [];
|
|
316
|
+
/**
|
|
317
|
+
* A flag to prevent concurrent recalculations.
|
|
318
|
+
* @private
|
|
319
|
+
*/
|
|
293
320
|
this.isRecalculating__ = false;
|
|
294
|
-
this.subscribe = this.internalSignal_.subscribe.bind(this.internalSignal_);
|
|
295
|
-
this.untilNext = this.internalSignal_.untilNext.bind(this.internalSignal_);
|
|
296
321
|
this.logger_.logMethod?.("constructor");
|
|
297
322
|
this.recalculate_ = this.recalculate_.bind(this);
|
|
298
323
|
for (const signal of config_.deps) {
|
|
299
|
-
this.
|
|
324
|
+
this.dependencySubscriptions__.push(signal.subscribe(this.recalculate_, { receivePrevious: false }));
|
|
300
325
|
}
|
|
301
326
|
}
|
|
302
327
|
/**
|
|
@@ -317,6 +342,25 @@ var ComputedSignal = class {
|
|
|
317
342
|
get isDestroyed() {
|
|
318
343
|
return this.internalSignal_.isDestroyed;
|
|
319
344
|
}
|
|
345
|
+
/**
|
|
346
|
+
* Subscribes a listener to this signal.
|
|
347
|
+
* The listener will be called whenever the computed value changes.
|
|
348
|
+
*
|
|
349
|
+
* @param callback The function to be called with the new value.
|
|
350
|
+
* @param options Subscription options.
|
|
351
|
+
* @returns A `SubscribeResult` object with an `unsubscribe` method.
|
|
352
|
+
*/
|
|
353
|
+
subscribe(callback, options) {
|
|
354
|
+
return this.internalSignal_.subscribe(callback, options);
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* Returns a Promise that resolves with the next computed value.
|
|
358
|
+
*
|
|
359
|
+
* @returns A Promise that resolves with the next value.
|
|
360
|
+
*/
|
|
361
|
+
untilNext() {
|
|
362
|
+
return this.internalSignal_.untilNext();
|
|
363
|
+
}
|
|
320
364
|
/**
|
|
321
365
|
* Permanently disposes of the computed signal.
|
|
322
366
|
*
|
|
@@ -328,14 +372,14 @@ var ComputedSignal = class {
|
|
|
328
372
|
*/
|
|
329
373
|
destroy() {
|
|
330
374
|
this.logger_.logMethod?.("destroy");
|
|
331
|
-
if (this.
|
|
375
|
+
if (this.isDestroyed) {
|
|
332
376
|
this.logger_.incident?.("destroy", "already_destroyed");
|
|
333
377
|
return;
|
|
334
378
|
}
|
|
335
|
-
for (const subscription of this.
|
|
379
|
+
for (const subscription of this.dependencySubscriptions__) {
|
|
336
380
|
subscription.unsubscribe();
|
|
337
381
|
}
|
|
338
|
-
this.
|
|
382
|
+
this.dependencySubscriptions__.length = 0;
|
|
339
383
|
this.internalSignal_.destroy();
|
|
340
384
|
this.config_.onDestroy?.();
|
|
341
385
|
this.config_ = null;
|
|
@@ -349,23 +393,24 @@ var ComputedSignal = class {
|
|
|
349
393
|
* @protected
|
|
350
394
|
*/
|
|
351
395
|
async recalculate_() {
|
|
396
|
+
this.logger_.logMethod?.("recalculate_");
|
|
352
397
|
if (this.internalSignal_.isDestroyed) {
|
|
353
|
-
this.logger_.incident?.("
|
|
398
|
+
this.logger_.incident?.("recalculate_", "recalculate_on_destroyed_signal");
|
|
354
399
|
return;
|
|
355
400
|
}
|
|
356
401
|
if (this.isRecalculating__) {
|
|
357
|
-
this.logger_.
|
|
402
|
+
this.logger_.logStep?.("recalculate_", "skipping_recalculation_already_scheduled");
|
|
358
403
|
return;
|
|
359
404
|
}
|
|
360
|
-
this.logger_.logMethod?.("recalculate_//scheduled");
|
|
361
405
|
this.isRecalculating__ = true;
|
|
362
406
|
try {
|
|
363
407
|
await delay3.nextMacrotask();
|
|
364
|
-
if (this.
|
|
365
|
-
this.logger_.incident?.("
|
|
408
|
+
if (this.isDestroyed) {
|
|
409
|
+
this.logger_.incident?.("recalculate_", "destroyed_during_delay");
|
|
410
|
+
this.isRecalculating__ = false;
|
|
366
411
|
return;
|
|
367
412
|
}
|
|
368
|
-
this.logger_.
|
|
413
|
+
this.logger_.logStep?.("recalculate_", "recalculating_value");
|
|
369
414
|
this.internalSignal_.set(this.config_.get());
|
|
370
415
|
} catch (err) {
|
|
371
416
|
this.logger_.error("recalculate_", "recalculation_failed", err);
|
|
@@ -380,14 +425,34 @@ import { createLogger as createLogger4 } from "@alwatr/logger";
|
|
|
380
425
|
var EffectSignal = class {
|
|
381
426
|
constructor(config_) {
|
|
382
427
|
this.config_ = config_;
|
|
383
|
-
|
|
384
|
-
|
|
428
|
+
/**
|
|
429
|
+
* The unique identifier for this signal instance.
|
|
430
|
+
*/
|
|
431
|
+
this.signalId = this.config_.signalId ? this.config_.signalId : `[${this.config_.deps.map((dep) => dep.signalId).join(", ")}]`;
|
|
432
|
+
/**
|
|
433
|
+
* The logger instance for this signal.
|
|
434
|
+
* @protected
|
|
435
|
+
*/
|
|
436
|
+
this.logger_ = createLogger4(`effect-signal: ${this.signalId}`);
|
|
437
|
+
/**
|
|
438
|
+
* A list of subscriptions to dependency signals.
|
|
439
|
+
* @private
|
|
440
|
+
*/
|
|
441
|
+
this.dependencySubscriptions__ = [];
|
|
442
|
+
/**
|
|
443
|
+
* A flag to prevent concurrent executions of the effect.
|
|
444
|
+
* @private
|
|
445
|
+
*/
|
|
385
446
|
this.isRunning__ = false;
|
|
447
|
+
/**
|
|
448
|
+
* A flag indicating whether the effect has been destroyed.
|
|
449
|
+
* @private
|
|
450
|
+
*/
|
|
386
451
|
this.isDestroyed__ = false;
|
|
387
452
|
this.logger_.logMethod?.("constructor");
|
|
388
453
|
this.run_ = this.run_.bind(this);
|
|
389
454
|
for (const signal of config_.deps) {
|
|
390
|
-
this.
|
|
455
|
+
this.dependencySubscriptions__.push(signal.subscribe(this.run_, { receivePrevious: false }));
|
|
391
456
|
}
|
|
392
457
|
if (config_.runImmediately === true) {
|
|
393
458
|
void this.run_();
|
|
@@ -395,7 +460,8 @@ var EffectSignal = class {
|
|
|
395
460
|
}
|
|
396
461
|
/**
|
|
397
462
|
* Indicates whether the effect signal has been destroyed.
|
|
398
|
-
* A destroyed signal
|
|
463
|
+
* A destroyed signal will no longer execute its effect and cannot be reused.
|
|
464
|
+
*
|
|
399
465
|
* @returns `true` if the signal is destroyed, `false` otherwise.
|
|
400
466
|
*/
|
|
401
467
|
get isDestroyed() {
|
|
@@ -410,29 +476,29 @@ var EffectSignal = class {
|
|
|
410
476
|
* @protected
|
|
411
477
|
*/
|
|
412
478
|
async run_() {
|
|
479
|
+
this.logger_.logMethod?.("run_");
|
|
413
480
|
if (this.isDestroyed__) {
|
|
414
481
|
this.logger_.incident?.("run_", "run_on_destroyed_signal");
|
|
415
482
|
return;
|
|
416
483
|
}
|
|
417
484
|
if (this.isRunning__) {
|
|
418
|
-
this.logger_.
|
|
485
|
+
this.logger_.logStep?.("run_", "skipped_because_already_running");
|
|
419
486
|
return;
|
|
420
487
|
}
|
|
421
|
-
this.logger_.logMethod?.("run_//scheduled");
|
|
422
488
|
this.isRunning__ = true;
|
|
423
489
|
try {
|
|
424
490
|
await delay4.nextMacrotask();
|
|
425
491
|
if (this.isDestroyed__) {
|
|
426
492
|
this.logger_.incident?.("run_", "destroyed_during_delay");
|
|
493
|
+
this.isRunning__ = false;
|
|
427
494
|
return;
|
|
428
495
|
}
|
|
429
|
-
this.logger_.
|
|
496
|
+
this.logger_.logStep?.("run_", "executing_effect");
|
|
430
497
|
await this.config_.run();
|
|
431
498
|
} catch (err) {
|
|
432
499
|
this.logger_.error("run_", "effect_failed", err);
|
|
433
|
-
} finally {
|
|
434
|
-
this.isRunning__ = false;
|
|
435
500
|
}
|
|
501
|
+
this.isRunning__ = false;
|
|
436
502
|
}
|
|
437
503
|
/**
|
|
438
504
|
* Permanently disposes of the effect signal.
|
|
@@ -448,10 +514,10 @@ var EffectSignal = class {
|
|
|
448
514
|
return;
|
|
449
515
|
}
|
|
450
516
|
this.isDestroyed__ = true;
|
|
451
|
-
for (const subscription of this.
|
|
517
|
+
for (const subscription of this.dependencySubscriptions__) {
|
|
452
518
|
subscription.unsubscribe();
|
|
453
519
|
}
|
|
454
|
-
this.
|
|
520
|
+
this.dependencySubscriptions__.length = 0;
|
|
455
521
|
this.config_.onDestroy?.();
|
|
456
522
|
this.config_ = null;
|
|
457
523
|
}
|
package/dist/main.mjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/core/signal-base.ts", "../src/core/event-signal.ts", "../src/core/state-signal.ts", "../src/core/computed-signal.ts", "../src/core/effect-signal.ts", "../src/creators/event.ts", "../src/creators/state.ts", "../src/creators/computed.ts", "../src/creators/effect.ts", "../src/operators/debounce.ts"],
|
|
4
|
-
"sourcesContent": ["import type {Observer_, SubscribeOptions, SubscribeResult, ListenerCallback, SignalConfig} from '../type.js';\nimport type {AlwatrLogger} from '@alwatr/logger';\nimport type {} from '@alwatr/nano-build';\n\n/**\n * An abstract base class for signal implementations.\n *\n * `SignalBase` provides the core functionality for managing subscriptions (observers).\n * It handles adding, removing, and notifying listeners. The responsibility of *when* to notify\n * is left to the concrete subclasses (`StateSignal`, `EventSignal`, etc.).\n *\n * @template T The type of data the signal will handle.\n */\nexport abstract class SignalBase<T> {\n /**\n * The unique identifier for this signal instance. Useful for debugging.\n */\n public readonly signalId: string = this.config_.signalId;\n\n protected abstract logger_: AlwatrLogger;\n\n /**\n * The list of observers (listeners) subscribed to this signal.\n * @protected\n */\n protected readonly observers_: Observer_<T>[] = [];\n\n protected isDestroyed_ = false;\n\n /**\n * Indicates whether the signal has been destroyed.\n * A destroyed signal cannot be used and will throw an error if interacted with.\n * @returns `true` if the signal is destroyed, `false` otherwise.\n */\n public get isDestroyed(): boolean {\n return this.isDestroyed_;\n }\n\n public constructor(protected config_: SignalConfig) {}\n\n /**\n * Removes a specific observer from the observers list.\n * @param observer The observer instance to remove.\n * @protected\n */\n protected removeObserver_(observer: Observer_<T>): void {\n if (this.isDestroyed_) {\n this.logger_.incident?.('removeObserver_', 'remove_observer_on_destroyed_signal');\n return;\n }\n this.logger_.logMethod?.('removeObserver_');\n const index = this.observers_.indexOf(observer);\n if (index !== -1) {\n this.observers_.splice(index, 1);\n }\n }\n\n /**\n * Subscribes a listener function to this signal.\n *\n * The listener will be called whenever the signal is notified (e.g., when `dispatch` or `set` is called).\n *\n * @param callback The function to be called when the signal is dispatched.\n * @param options Subscription options to customize the behavior (e.g., `once`, `priority`).\n * @returns A `SubscribeResult` object with an `unsubscribe` method to remove the listener.\n */\n public subscribe(callback: ListenerCallback<T>, options?: SubscribeOptions): SubscribeResult {\n this.logger_.logMethodArgs?.('subscribe.base', {options});\n this.checkDestroyed_();\n\n const observer: Observer_<T> = {callback, options};\n\n if (options?.priority) {\n // High-priority observers are added to the front of the queue.\n this.observers_.unshift(observer);\n }\n else {\n this.observers_.push(observer);\n }\n\n // The returned unsubscribe function is a closure that calls the internal removal method.\n const unsubscribe = (): void => this.removeObserver_(observer);\n\n return {unsubscribe};\n }\n\n /**\n * Notifies all registered observers about a new value.\n *\n * This method iterates through a snapshot of the current observers to prevent issues\n * with subscriptions changing during notification (e.g., an observer unsubscribing itself).\n *\n * @param value The new value to notify observers about.\n * @protected\n */\n protected notify_(value: T): void {\n if (this.isDestroyed_) {\n this.logger_.incident?.('notify_', 'notify_on_destroyed_signal');\n return;\n }\n\n this.logger_.logMethodArgs?.('notify_', value);\n\n // Create a snapshot of the observers array to iterate over.\n // This prevents issues if the observers_ array is modified during the loop.\n const currentObservers = [...this.observers_];\n\n for (const observer of currentObservers) {\n if (observer.options?.once) {\n this.removeObserver_(observer);\n }\n\n try {\n // Fire the callback, but don't await it.\n // If the callback returns a promise, it's up to the callback's author to handle it.\n const result = observer.callback(value);\n if (result instanceof Promise) {\n // Log unhandled promise rejections from listeners.\n result.catch((err) => {\n this.logger_.error('notify_', 'async_callback_failed', err, {observer});\n });\n }\n }\n catch (err) {\n this.logger_.error('notify_', 'sync_callback_failed', err);\n }\n }\n }\n\n /**\n * Returns a Promise that resolves with the next value dispatched by the signal.\n * This provides an elegant way to wait for a single, future event using `async/await`.\n *\n * @returns A Promise that resolves with the next dispatched value.\n *\n * @example\n * async function onButtonClick() {\n * console.log('Waiting for the next signal...');\n * const nextValue = await mySignal.untilNext();\n * console.log('Signal received:', nextValue);\n * }\n */\n public untilNext(): Promise<T> {\n this.logger_.logMethod?.('untilNext');\n this.checkDestroyed_();\n return new Promise((resolve) => {\n this.subscribe(resolve, {\n once: true,\n priority: true, // Resolve the promise before other listeners are called.\n receivePrevious: false, // We only want the *next* value, not the current one.\n });\n });\n }\n\n /**\n * Destroys the signal, clearing all its listeners and making it inactive.\n *\n * After destruction, any interaction with the signal (like `subscribe` or `untilNext`)\n * will throw an error. This is crucial for preventing memory leaks by allowing\n * garbage collection of the signal and its observers.\n */\n public destroy(): void {\n this.logger_.logMethod?.('destroy');\n if (this.isDestroyed_) return;\n this.isDestroyed_ = true;\n this.observers_.length = 0; // Clear all observers.\n this.config_.onDestroy?.(); // Call the optional onDestroy callback.\n this.config_ = null as unknown as SignalConfig; // Help GC by breaking references.\n }\n\n /**\n * Throws an error if the signal has been destroyed.\n * This is a safeguard to prevent interaction with a defunct signal.\n * @protected\n */\n protected checkDestroyed_ = (): void => {\n if (this.isDestroyed_) {\n this.logger_.accident('checkDestroyed_', 'attempt_to_use_destroyed_signal');\n throw new Error(`Cannot interact with a destroyed signal (id: ${this.signalId})`);\n }\n };\n}\n", "import {delay} from '@alwatr/delay';\nimport {createLogger} from '@alwatr/logger';\n\nimport {SignalBase} from './signal-base.js';\n\nimport type {SignalConfig} from '../type.js';\n\n/**\n * A stateless signal for dispatching transient events.\n *\n * `EventSignal` is ideal for broadcasting events that do not have a persistent state.\n * Unlike `StateSignal`, it does not hold a value. Listeners are only notified of new\n * events as they are dispatched. This makes it suitable for modeling user interactions,\n * system notifications, or any one-off message.\n *\n * @template T The type of the payload for the events. Defaults to `void` for events without a payload.\n *\n * @example\n * // Create a signal for user click events.\n * const onUserClick = new EventSignal<{ x: number, y: number }>({ signalId: 'on-user-click' });\n *\n * // Subscribe to the event.\n * onUserClick.subscribe(clickPosition => {\n * console.log(`User clicked at: ${clickPosition.x}, ${clickPosition.y}`);\n * });\n *\n * // Dispatch an event.\n * onUserClick.dispatch({ x: 100, y: 250 }); // Notifies the listener.\n *\n * // --- Example with no payload ---\n * const onAppReady = new EventSignal({ signalId: 'on-app-ready' });\n * onAppReady.subscribe(() => console.log('Application is ready!'));\n * onAppReady.dispatch(); // Notifies the listener.\n */\nexport class EventSignal<T = void> extends SignalBase<T> {\n protected logger_ = createLogger(`event-signal: ${this.signalId}`);\n\n public constructor(config: SignalConfig) {\n super(config);\n this.logger_.logMethod?.('constructor');\n }\n\n /**\n * Dispatches an event with an optional payload to all active listeners.\n * The notification is scheduled as a microtask to prevent blocking and ensure\n * a consistent, non-blocking flow.\n *\n * @param payload The data to send with the event.\n */\n public dispatch(payload: T): void {\n this.logger_.logMethodArgs?.('dispatch', payload);\n this.checkDestroyed_();\n // Dispatch as a microtask to ensure consistent, non-blocking behavior.\n delay.nextMicrotask().then(() => {\n this.notify_(payload);\n });\n }\n}\n", "import {delay} from '@alwatr/delay';\nimport {createLogger} from '@alwatr/logger';\n\nimport {SignalBase} from './signal-base.js';\n\nimport type {StateSignalConfig, ListenerCallback, SubscribeOptions, SubscribeResult, IReadonlySignal} from '../type.js';\n\n/**\n * A stateful signal that holds a value and notifies listeners when the value changes.\n *\n * `StateSignal` is the core of the signal library, representing a piece of mutable state.\n * It always has a value, and new subscribers immediately receive the current value by default.\n *\n * @template T The type of the state it holds.\n * @implements {IReadonlySignal<T>}\n *\n * @example\n * // Create a new state signal with an initial value.\n * const counter = new StateSignal<number>({\n * signalId: 'counter-signal',\n * initialValue: 0,\n * });\n *\n * // Get the current value.\n * console.log(counter.value); // Outputs: 0\n *\n * // Subscribe to changes.\n * const subscription = counter.subscribe(newValue => {\n * console.log(`Counter changed to: ${newValue}`);\n * });\n *\n * // Set a new value, which triggers the notification.\n * counter.set(1); // Outputs: \"Counter changed to: 1\"\n *\n * // Update value based on the previous value.\n * counter.update(current => current + 1); // Outputs: \"Counter changed to: 2\"\n *\n * // Unsubscribe when no longer needed.\n * subscription.unsubscribe();\n */\nexport class StateSignal<T> extends SignalBase<T> implements IReadonlySignal<T> {\n private value__: T;\n protected logger_ = createLogger(`state-signal: ${this.signalId}`);\n\n public constructor(config: StateSignalConfig<T>) {\n super(config);\n this.value__ = config.initialValue;\n this.logger_.logMethodArgs?.('constructor', {initialValue: this.value__});\n }\n\n /**\n * Retrieves the current value of the signal.\n *\n * @returns The current value.\n *\n * @example\n * console.log(mySignal.value);\n */\n public get value(): T {\n this.checkDestroyed_();\n return this.value__;\n }\n\n /**\n * Updates the signal's value and notifies all active listeners.\n *\n * The notification is scheduled as a microtask, which means the update is deferred\n * slightly to batch multiple synchronous changes.\n *\n * @param newValue The new value to set.\n *\n * @example\n * // For primitive types\n * mySignal.set(42);\n *\n * // For object types, it's best practice to set an immutable new object.\n * mySignal.set({ ...mySignal.value, property: 'new-value' });\n */\n public set(newValue: T): void {\n this.logger_.logMethodArgs?.('set', {newValue});\n this.checkDestroyed_();\n\n // For primitives (including null), do not notify if the value is the same.\n if (Object.is(this.value__, newValue) && (typeof newValue !== 'object' || newValue === null)) return;\n\n this.value__ = newValue;\n\n // Dispatch as a microtask to ensure consistent, non-blocking behavior.\n delay.nextMicrotask().then(() => {\n this.notify_(newValue);\n });\n }\n\n /**\n * Updates the signal's value based on its previous value.\n *\n * This method is particularly useful for state transitions that depend on the current value,\n * especially for objects or arrays, as it promotes an immutable update pattern.\n *\n * @param updater A function that receives the current value and returns the new value.\n *\n * @example\n * // For a counter\n * counterSignal.update(current => current + 1);\n *\n * // For an object state\n * userSignal.update(currentUser => ({ ...currentUser, loggedIn: true }));\n */\n public update(updater: (previousValue: T) => T): void {\n this.logger_.logMethod?.('update');\n this.checkDestroyed_();\n // The updater function is called with the current value to compute the new value,\n // which is then passed to the `set` method.\n this.set(updater(this.value__));\n }\n\n /**\n * Subscribes a listener to this signal.\n *\n * By default, the listener is immediately called with the signal's current value (`receivePrevious: true`).\n * This behavior can be customized via the `options` parameter.\n *\n * @param callback The function to be called when the signal's value changes.\n * @param options Subscription options, including `receivePrevious` and `once`.\n * @returns An object with an `unsubscribe` method to remove the listener.\n */\n public override subscribe(callback: ListenerCallback<T>, options: SubscribeOptions = {}): SubscribeResult {\n this.logger_.logMethodArgs?.('subscribe', {options});\n this.checkDestroyed_();\n\n // By default, new subscribers to a StateSignal should receive the current value.\n const receivePrevious = options.receivePrevious !== false;\n\n if (receivePrevious) {\n // Immediately (but asynchronously) call the listener with the current value.\n // This is done in a microtask to ensure it happens after the subscription is fully registered.\n delay\n .nextMicrotask()\n .then(() => callback(this.value__))\n .catch((err) => {\n this.logger_.error('subscribe', 'run_callback_immediate_failed', err);\n });\n\n // If it's a 'once' subscription that receives the previous value, it's now fulfilled.\n // We don't need to add it to the observers list for future updates.\n if (options.once) {\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n return {unsubscribe: () => {}};\n }\n }\n\n return super.subscribe(callback, options);\n }\n\n /**\n * Destroys the signal, clearing its value and all listeners.\n * This is crucial for memory management to prevent leaks.\n */\n public override destroy(): void {\n // Clear the value to allow for garbage collection.\n this.value__ = null as T;\n super.destroy();\n }\n}\n", "import {delay} from '@alwatr/delay';\nimport {createLogger} from '@alwatr/logger';\n\nimport {StateSignal} from './state-signal.js';\n\nimport type {ComputedSignalConfig, IReadonlySignal, SubscribeResult} from '../type.js';\n\n/**\n * A read-only signal that derives its value from a set of dependency signals.\n *\n * `ComputedSignal` is a powerful tool for creating values that reactively update when their underlying\n * data sources change. Its value is memoized, meaning the `get` function is only re-evaluated when\n * one of its dependencies has actually changed.\n *\n * A key feature is its lifecycle management: a `ComputedSignal` **must** be destroyed when no longer\n * needed to prevent memory leaks from its subscriptions to dependency signals.\n *\n * @template T The type of the computed value.\n * @implements {IComputedSignal<T>}\n *\n * @example\n * // --- Create dependency signals ---\n * const firstName = new StateSignal({ signalId: 'firstName', initialValue: 'John' });\n * const lastName = new StateSignal({ signalId: 'lastName', initialValue: 'Doe' });\n *\n * // --- Create a computed signal ---\n * const fullName = new ComputedSignal({\n * signalId: 'fullName',\n * deps: [firstName, lastName],\n * get: () => `${firstName.value} ${lastName.value}`,\n * });\n *\n * console.log(fullName.value); // Outputs: \"John Doe\"\n *\n * // --- Subscribe to the computed value ---\n * fullName.subscribe(newFullName => {\n * console.log(`Name changed to: ${newFullName}`);\n * });\n *\n * // --- Update a dependency ---\n * lastName.set('Smith'); // Recalculates and logs: \"Name changed to: John Smith\"\n * console.log(fullName.value); // Outputs: \"John Smith\"\n *\n * // --- IMPORTANT: Clean up when done ---\n * fullName.destroy();\n */\nexport class ComputedSignal<T> implements IReadonlySignal<T> {\n public readonly signalId = this.config_.signalId;\n\n protected readonly logger_ = createLogger(`computed-signal: ${this.signalId}`);\n\n /**\n * The internal `StateSignal` that holds the computed value.\n * This is how the computed signal provides `.value` and `.subscribe()` methods.\n * @protected\n */\n protected readonly internalSignal_ = new StateSignal<T>({\n signalId: this.signalId + '-internal',\n initialValue: this.config_.get(),\n });\n\n private readonly subscriptionList__: SubscribeResult[] = [];\n private isRecalculating__ = false;\n\n public constructor(protected config_: ComputedSignalConfig<T>) {\n this.logger_.logMethod?.('constructor');\n this.recalculate_ = this.recalculate_.bind(this);\n\n // Subscribe to all dependencies to trigger recalculation on change.\n for (const signal of config_.deps) {\n this.subscriptionList__.push(signal.subscribe(this.recalculate_, {receivePrevious: false}));\n }\n }\n\n /**\n * The current value of the computed signal.\n * Accessing this property returns the memoized value and does not trigger a recalculation.\n *\n * @returns The current computed value.\n * @throws {Error} If accessed after the signal has been destroyed.\n */\n public get value(): T {\n return this.internalSignal_.value;\n }\n\n /**\n * Indicates whether the computed signal has been destroyed.\n * A destroyed signal cannot be used and will throw an error if interacted with.\n * @returns `true` if the signal is destroyed, `false` otherwise.\n */\n public get isDestroyed(): boolean {\n return this.internalSignal_.isDestroyed;\n }\n\n public readonly subscribe = this.internalSignal_.subscribe.bind(this.internalSignal_);\n\n public readonly untilNext = this.internalSignal_.untilNext.bind(this.internalSignal_);\n\n /**\n * Permanently disposes of the computed signal.\n *\n * This is a critical cleanup step. It unsubscribes from all dependency signals,\n * stopping future recalculations and allowing the signal to be garbage collected.\n * Failure to call `destroy()` will result in memory leaks.\n *\n * After `destroy()` is called, any attempt to access `.value` or `.subscribe()` will throw an error.\n */\n public destroy(): void {\n this.logger_.logMethod?.('destroy');\n\n if (this.internalSignal_.isDestroyed) {\n this.logger_.incident?.('destroy', 'already_destroyed');\n return;\n }\n\n // Unsubscribe from all upstream dependencies.\n for (const subscription of this.subscriptionList__) {\n subscription.unsubscribe();\n }\n this.subscriptionList__.length = 0; // Clear the array of subscriptions.\n\n // Destroy the internal signal to clean up its resources and mark it as destroyed.\n this.internalSignal_.destroy();\n\n this.config_.onDestroy?.(); // Call the optional onDestroy callback.\n\n this.config_ = null as unknown as ComputedSignalConfig<T>; // Release config closure.\n }\n\n /**\n * Schedules a recalculation of the signal's value.\n *\n * This method batches updates using a macrotask (`delay.nextMacrotask`) to ensure the\n * `get` function runs only once per event loop tick, even if multiple dependencies\n * change in the same synchronous block of code.\n * @protected\n */\n protected async recalculate_(): Promise<void> {\n if (this.internalSignal_.isDestroyed) {\n // This check is important in case a dependency fires after this signal is destroyed.\n this.logger_.incident?.('recalculate', 'recalculate_on_destroyed_signal');\n return;\n }\n\n if (this.isRecalculating__) {\n // If a recalculation is already scheduled, do nothing.\n this.logger_.logMethod?.('recalculate_//skipped');\n return;\n }\n\n this.logger_.logMethod?.('recalculate_//scheduled');\n this.isRecalculating__ = true;\n\n try {\n // Wait for the next macrotask to start the recalculation.\n // This batches all synchronous dependency updates in the current event loop.\n await delay.nextMacrotask();\n\n if (this.internalSignal_.isDestroyed) {\n this.logger_.incident?.('recalculate', 'destroyed_during_delay');\n return;\n }\n\n this.logger_.logMethod?.('recalculate_//executing');\n // Set the new value on the internal signal, which will notify our subscribers.\n this.internalSignal_.set(this.config_.get());\n }\n catch (err) {\n this.logger_.error('recalculate_', 'recalculation_failed', err);\n }\n\n // Allow the next recalculation to be scheduled.\n this.isRecalculating__ = false;\n }\n}\n", "import {delay} from '@alwatr/delay';\nimport {createLogger} from '@alwatr/logger';\n\nimport type {EffectSignalConfig, IEffectSignal, SubscribeResult} from '../type.js';\n\n/**\n * Manages a side-effect that runs in response to changes in dependency signals.\n *\n * `EffectSignal` is designed for running logic that interacts with the \"outside world\"—such as\n * logging, network requests, or DOM manipulation—whenever its dependencies are updated.\n * It encapsulates the subscription and cleanup logic, providing a robust and memory-safe\n * way to handle reactive side-effects.\n *\n * A key feature is its lifecycle management: an `EffectSignal` **must** be destroyed when no longer\n * needed to prevent memory leaks and stop the effect from running unnecessarily.\n *\n * @implements {IEffectSignal}\n *\n * @example\n * // --- Create dependency signals ---\n * const counter = new StateSignal({ initialValue: 0, signalId: 'counter' });\n * const user = new StateSignal({ initialValue: 'guest', signalId: 'user' });\n *\n * // --- Create an effect ---\n * const analyticsEffect = new EffectSignal({\n * deps: [counter, user],\n * run: () => {\n * console.log(`Analytics: User '${user.value}' clicked ${counter.value} times.`);\n * },\n * runImmediately: true, // Optional: run once on creation\n * });\n * // Immediately logs: \"Analytics: User 'guest' clicked 0 times.\"\n *\n * // --- Trigger the effect by updating a dependency ---\n * counter.set(1);\n * // After a macrotask, logs: \"Analytics: User 'guest' clicked 1 times.\"\n *\n * // --- IMPORTANT: Clean up when the effect is no longer needed ---\n * analyticsEffect.destroy();\n *\n * // Further updates will not trigger the effect.\n * counter.set(2); // Nothing is logged.\n */\nexport class EffectSignal implements IEffectSignal {\n protected readonly logger_ = createLogger(`effect-signal`);\n\n private readonly subscriptionList__: SubscribeResult[] = [];\n private isRunning__ = false;\n private isDestroyed__ = false;\n\n /**\n * Indicates whether the effect signal has been destroyed.\n * A destroyed signal cannot be used and will throw an error if interacted with.\n * @returns `true` if the signal is destroyed, `false` otherwise.\n */\n public get isDestroyed(): boolean {\n return this.isDestroyed__;\n }\n\n public constructor(protected config_: EffectSignalConfig) {\n this.logger_.logMethod?.('constructor');\n this.run_ = this.run_.bind(this);\n\n // Subscribe to all dependencies. We don't need the previous value,\n // as the `runImmediately` option controls the initial execution.\n for (const signal of config_.deps) {\n this.subscriptionList__.push(signal.subscribe(this.run_, {receivePrevious: false}));\n }\n\n // Run the effect immediately if requested.\n if (config_.runImmediately === true) {\n // We don't need to await this, let it run in the background.\n void this.run_();\n }\n }\n\n /**\n * Schedules the execution of the effect's `run` function.\n *\n * This method batches updates using a macrotask (`delay.nextMacrotask`) to ensure the\n * `run` function executes only once per event loop tick, even if multiple\n * dependencies change simultaneously.\n * @protected\n */\n protected async run_(): Promise<void> {\n if (this.isDestroyed__) {\n this.logger_.incident?.('run_', 'run_on_destroyed_signal');\n return;\n }\n if (this.isRunning__) {\n // If an execution is already scheduled, do nothing.\n this.logger_.logMethod?.('run_//skipped');\n return;\n }\n\n this.logger_.logMethod?.('run_//scheduled');\n this.isRunning__ = true;\n\n try {\n // Wait for the next macrotask to batch simultaneous updates.\n await delay.nextMacrotask();\n\n if (this.isDestroyed__) {\n this.logger_.incident?.('run_', 'destroyed_during_delay');\n return;\n }\n\n this.logger_.logMethod?.('run_//executing');\n await this.config_.run();\n }\n catch (err) {\n this.logger_.error('run_', 'effect_failed', err);\n }\n finally {\n // Reset the flag after the current execution is complete.\n this.isRunning__ = false;\n }\n }\n\n /**\n * Permanently disposes of the effect signal.\n *\n * This is a critical cleanup step. It unsubscribes from all dependency signals,\n * stopping any future executions of the effect and allowing it to be garbage collected.\n * Failure to call `destroy()` will result in memory leaks and potentially unwanted side effects.\n */\n public destroy(): void {\n this.logger_.logMethod?.('destroy');\n\n if (this.isDestroyed__) {\n this.logger_.incident?.('destroy', 'already_destroyed');\n return;\n }\n this.isDestroyed__ = true;\n\n // Unsubscribe from all upstream dependencies.\n for (const subscription of this.subscriptionList__) {\n subscription.unsubscribe();\n }\n this.subscriptionList__.length = 0; // Clear the array of subscriptions.\n\n this.config_.onDestroy?.(); // Call the optional onDestroy callback.\n\n this.config_ = null as unknown as EffectSignalConfig; // Release config closure.\n }\n}\n", "import {EventSignal} from '../core/event-signal.js';\n\nimport type {SignalConfig} from '../type.js';\n\n/**\n * Creates a stateless signal for dispatching transient events.\n *\n * `EventSignal` is ideal for broadcasting events that do not have a persistent state.\n * Unlike `StateSignal`, it does not hold a value. Listeners are only notified of new\n * events as they are dispatched. This makes it suitable for modeling user interactions,\n * system notifications, or any one-off message.\n *\n * @template T The type of the payload for the events.\n *\n * @param config The configuration for the event signal.\n * @returns A new instance of EventSignal.\n *\n * @example\n * const onUserClick = createEventSignal<{ x: number, y: number }>({\n * signalId: 'on-user-click'\n * });\n *\n * onUserClick.subscribe(pos => {\n * console.log(`User clicked at: ${pos.x}, ${pos.y}`);\n * });\n *\n * onUserClick.dispatch({ x: 100, y: 250 });\n */\nexport function createEventSignal<T = void>(config: SignalConfig): EventSignal<T> {\n return new EventSignal<T>(config);\n}\n", "import {StateSignal} from '../core/state-signal.js';\n\nimport type {StateSignalConfig} from '../type.js';\n\n/**\n * Creates a stateful signal that holds a value and notifies listeners when the value changes.\n *\n * `StateSignal` is the core of the signal library, representing a piece of mutable state.\n * It always has a value, and new subscribers immediately receive the current value by default.\n *\n * @template T The type of the state it holds.\n *\n * @param config The configuration for the state signal.\n * @returns A new instance of StateSignal.\n *\n * @example\n * const counter = createStateSignal({\n * signalId: 'counter-signal',\n * initialValue: 0,\n * });\n *\n * console.log(counter.value); // Outputs: 0\n * counter.set(1);\n * console.log(counter.value); // Outputs: 1\n */\nexport function createStateSignal<T>(config: StateSignalConfig<T>): StateSignal<T> {\n return new StateSignal(config);\n}\n", "import {ComputedSignal} from '../core/computed-signal.js';\n\nimport type {ComputedSignalConfig} from '../type.js';\n\n/**\n * Creates a read-only signal that derives its value from a set of dependency signals.\n *\n * `ComputedSignal` is a powerful tool for creating values that reactively update when their underlying\n * data sources change. Its value is memoized, meaning the `get` function is only re-evaluated when\n * one of its dependencies has actually changed.\n *\n * A key feature is its lifecycle management: a `ComputedSignal` **must** be destroyed when no longer\n * needed to prevent memory leaks from its subscriptions to dependency signals.\n *\n * @template T The type of the computed value.\n *\n * @param config The configuration for the computed signal.\n * @returns A new, read-only computed signal.\n *\n * @example\n * const firstName = createStateSignal({ signalId: 'firstName', initialValue: 'John' });\n * const lastName = createStateSignal({ signalId: 'lastName', initialValue: 'Doe' });\n *\n * const fullName = createComputedSignal({\n * signalId: 'fullName',\n * deps: [firstName, lastName],\n * get: () => `${firstName.value} ${lastName.value}`,\n * });\n *\n * console.log(fullName.value); // \"John Doe\"\n *\n * // IMPORTANT: Always destroy a computed signal when no longer needed.\n * // fullName.destroy();\n */\nexport function createComputedSignal<T>(config: ComputedSignalConfig<T>): ComputedSignal<T> {\n return new ComputedSignal(config);\n}\n", "import {EffectSignal} from '../core/effect-signal.js';\n\nimport type {EffectSignalConfig} from '../type.js';\n\n/**\n * Creates a side-effect that runs in response to changes in dependency signals.\n *\n * `EffectSignal` is designed for running logic that interacts with the \"outside world\"—such as\n * logging, network requests, or DOM manipulation—whenever its dependencies are updated.\n * It encapsulates the subscription and cleanup logic, providing a robust and memory-safe\n * way to handle reactive side-effects.\n *\n * A key feature is its lifecycle management: an `EffectSignal` **must** be destroyed when no longer\n * needed to prevent memory leaks and stop the effect from running unnecessarily.\n *\n * @param config The configuration for the effect.\n * @returns An object with a `destroy` method to stop the effect.\n *\n * @example\n * // --- Create dependency signals ---\n * const counter = createStateSignal({ initialValue: 0, signalId: 'counter' });\n * const user = createStateSignal({ initialValue: 'guest', signalId: 'user' });\n *\n * // --- Create an effect ---\n * const analyticsEffect = createEffect({\n * deps: [counter, user],\n * run: () => {\n * console.log(`Analytics: User '${user.value}' clicked ${counter.value} times.`);\n * },\n * runImmediately: true, // Optional: run once on creation\n * });\n * // Immediately logs: \"Analytics: User 'guest' clicked 0 times.\"\n *\n * // --- Trigger the effect by updating a dependency ---\n * counter.set(1);\n * // After a macrotask, logs: \"Analytics: User 'guest' clicked 1 times.\"\n *\n * // --- IMPORTANT: Clean up when the effect is no longer needed ---\n * analyticsEffect.destroy();\n *\n * // Further updates will not trigger the effect.\n * counter.set(2); // Nothing is logged.\n */\nexport function createEffect(config: EffectSignalConfig): EffectSignal {\n return new EffectSignal(config);\n}\n", "import {createDebouncer} from '@alwatr/debounce';\n\nimport {StateSignal} from '../core/state-signal.js';\nimport {createComputedSignal} from '../creators/computed.js';\n\nimport type {ComputedSignal} from '../core/computed-signal.js';\nimport type {IReadonlySignal, DebounceSignalConfig} from '../type.js';\n\n/**\n * Creates a new computed signal that debounces updates from a source signal.\n *\n * The returned signal is a `ComputedSignal`, meaning it is read-only and its value is\n * derived from the source. It only updates its value after a specified period of\n * inactivity from the source signal.\n *\n * This operator is essential for handling high-frequency events, such as user input\n * in a search box, resizing a window, or any other event that fires rapidly.\n * By debouncing, you can ensure that expensive operations (like API calls or heavy\n * computations) are only executed once the events have settled.\n *\n * @template T The type of the signal's value.\n *\n * @param {IReadonlySignal<T>} sourceSignal The original signal to debounce.\n * It can be a `StateSignal`, `ComputedSignal`, or any signal implementing `IReadonlySignal`.\n * @param {DebounceSignalConfig} config Configuration object for the debouncer,\n * including `delay`, `leading`, and `trailing` options from `@alwatr/debounce`.\n *\n * @returns {IComputedSignal<T>} A new, read-only computed signal that emits debounced values.\n * Crucially, you **must** call `.destroy()` on this signal when it's no longer\n * needed to prevent memory leaks by cleaning up internal subscriptions and timers.\n *\n * @example\n * ```typescript\n * // Create a source signal for user input.\n * const searchInput = createStateSignal({\n * signalId: 'search-input',\n * initialValue: '',\n * });\n *\n * // Create a debounced signal that waits 300ms after the user stops typing.\n * const debouncedSearch = createDebouncedSignal(searchInput, { delay: 300 });\n *\n * // Use an effect to react to the debounced value.\n * createEffect({\n * deps: [debouncedSearch],\n * run: () => {\n * if (debouncedSearch.value) {\n * console.log(`🚀 Sending API request for: \"${debouncedSearch.value}\"`);\n * }\n * },\n * });\n *\n * searchInput.set('Alwatr');\n * searchInput.set('Alwatr Signal');\n * // (after 300ms of inactivity)\n * // Logs: \"🚀 Sending API request for: \"Alwatr Signal\"\"\n *\n * // IMPORTANT: Clean up when the component unmounts.\n * // debouncedSearch.destroy();\n * ```\n */\nexport function createDebouncedSignal<T>(sourceSignal: IReadonlySignal<T>, config: DebounceSignalConfig): ComputedSignal<T> {\n const signalId = config.signalId ?? `${sourceSignal.signalId}-debounced`;\n\n const internalSignal = new StateSignal<T>({\n signalId: `${signalId}-internal`,\n initialValue: sourceSignal.value,\n });\n\n const debouncer = createDebouncer({\n ...config,\n func: (value: T): void => {\n internalSignal.set(value);\n },\n });\n\n const subscription = sourceSignal.subscribe(debouncer.trigger);\n\n return createComputedSignal({\n signalId,\n deps: [internalSignal],\n get: () => internalSignal.value,\n onDestroy: () => {\n if (internalSignal.isDestroyed) return;\n subscription.unsubscribe();\n debouncer.cancel();\n internalSignal.destroy();\n config.onDestroy?.();\n config = null as unknown as DebounceSignalConfig;\n },\n });\n}\n"],
|
|
5
|
-
"mappings": ";;;
|
|
4
|
+
"sourcesContent": ["import type {Observer_, SubscribeOptions, SubscribeResult, ListenerCallback, SignalConfig} from '../type.js';\nimport type {AlwatrLogger} from '@alwatr/logger';\nimport type {} from '@alwatr/nano-build';\n\n/**\n * An abstract base class for signal implementations.\n * It provides the core functionality for managing subscriptions (observers).\n *\n * @template T The type of data that the signal holds or dispatches.\n */\nexport abstract class SignalBase<T> {\n /**\n * The unique identifier for this signal instance.\n * Useful for debugging and logging.\n */\n public readonly signalId = this.config_.signalId;\n\n /**\n * The logger instance for this signal.\n * @protected\n */\n protected abstract logger_: AlwatrLogger;\n\n /**\n * The list of observers (listeners) subscribed to this signal.\n * @protected\n */\n protected readonly observers_: Observer_<T>[] = [];\n\n /**\n * A flag indicating whether the signal has been destroyed.\n * @private\n */\n private isDestroyed__ = false;\n\n /**\n * Indicates whether the signal has been destroyed.\n * A destroyed signal cannot be used and will throw an error if interacted with.\n *\n * @returns `true` if the signal is destroyed, `false` otherwise.\n */\n public get isDestroyed(): boolean {\n return this.isDestroyed__;\n }\n\n public constructor(protected config_: SignalConfig) {}\n\n /**\n * Removes a specific observer from the observers list.\n *\n * @param observer The observer instance to remove.\n * @protected\n */\n protected removeObserver_(observer: Observer_<T>): void {\n this.logger_.logMethod?.('removeObserver_');\n\n if (this.isDestroyed__) {\n this.logger_.incident?.('removeObserver_', 'remove_observer_on_destroyed_signal');\n return;\n }\n\n const index = this.observers_.indexOf(observer);\n if (index !== -1) {\n this.observers_.splice(index, 1);\n }\n }\n\n /**\n * Subscribes a listener function to this signal.\n *\n * The listener will be called whenever the signal is notified (e.g., when `dispatch` or `set` is called).\n *\n * @param callback The function to be called when the signal is dispatched.\n * @param options Subscription options to customize the behavior (e.g., `once`, `priority`).\n * @returns A `SubscribeResult` object with an `unsubscribe` method to remove the listener.\n */\n public subscribe(callback: ListenerCallback<T>, options?: SubscribeOptions): SubscribeResult {\n this.logger_.logMethodArgs?.('subscribe.base', {options});\n this.checkDestroyed_();\n\n const observer: Observer_<T> = {callback, options};\n\n if (options?.priority) {\n // High-priority observers are added to the front of the queue.\n this.observers_.unshift(observer);\n }\n else {\n this.observers_.push(observer);\n }\n\n // The returned unsubscribe function is a closure that calls the internal removal method.\n return {\n unsubscribe: (): void => this.removeObserver_(observer),\n };\n }\n\n /**\n * Notifies all registered observers about a new value.\n *\n * This method iterates through a snapshot of the current observers to prevent issues\n * with subscriptions changing during notification (e.g., an observer unsubscribing itself).\n *\n * @param value The new value to notify observers about.\n * @protected\n */\n protected notify_(value: T): void {\n this.logger_.logMethodArgs?.('notify_', value);\n\n if (this.isDestroyed__) {\n this.logger_.incident?.('notify_', 'notify_on_destroyed_signal');\n return;\n }\n\n // Create a snapshot of the observers array to iterate over.\n // This prevents issues if the observers_ array is modified during the loop.\n const currentObservers = [...this.observers_];\n\n for (const observer of currentObservers) {\n if (observer.options?.once) {\n this.removeObserver_(observer);\n }\n\n try {\n const result = observer.callback(value);\n if (result instanceof Promise) {\n result.catch((err) => this.logger_.error('notify_', 'async_callback_failed', err, {observer}));\n }\n }\n catch (err) {\n this.logger_.error('notify_', 'sync_callback_failed', err);\n }\n }\n }\n\n /**\n * Returns a Promise that resolves with the next value dispatched by the signal.\n * This provides an elegant way to wait for a single, future event using `async/await`.\n *\n * @returns A Promise that resolves with the next dispatched value.\n *\n * @example\n * async function onButtonClick() {\n * console.log('Waiting for the next signal...');\n * const nextValue = await mySignal.untilNext();\n * console.log('Signal received:', nextValue);\n * }\n */\n public untilNext(): Promise<T> {\n this.logger_.logMethod?.('untilNext');\n this.checkDestroyed_();\n return new Promise((resolve) => {\n this.subscribe(resolve, {\n once: true,\n priority: true, // Resolve the promise before other listeners are called.\n receivePrevious: false, // We only want the *next* value, not the current one.\n });\n });\n }\n\n /**\n * Destroys the signal, clearing all its listeners and making it inactive.\n *\n * After destruction, any interaction with the signal (like `subscribe` or `untilNext`)\n * will throw an error. This is crucial for preventing memory leaks by allowing\n * garbage collection of the signal and its observers.\n */\n public destroy(): void {\n this.logger_.logMethod?.('destroy');\n if (this.isDestroyed__) {\n this.logger_.incident?.('destroy_', 'double_destroy_attempt');\n return;\n }\n this.isDestroyed__ = true;\n this.observers_.length = 0; // Clear all observers.\n this.config_.onDestroy?.(); // Call the optional onDestroy callback.\n this.config_ = null as unknown as SignalConfig; // Help GC by breaking references.\n }\n\n /**\n * Throws an error if the signal has been destroyed.\n * This is a safeguard to prevent interaction with a defunct signal.\n * @protected\n */\n protected checkDestroyed_(): void {\n if (this.isDestroyed__) {\n this.logger_.accident('checkDestroyed_', 'attempt_to_use_destroyed_signal');\n throw new Error(`Cannot interact with a destroyed signal (id: ${this.signalId})`);\n }\n }\n}\n", "import {delay} from '@alwatr/delay';\nimport {createLogger} from '@alwatr/logger';\n\nimport {SignalBase} from './signal-base.js';\n\nimport type {SignalConfig} from '../type.js';\n\n/**\n * A stateless signal for dispatching transient events.\n *\n * `EventSignal` is ideal for broadcasting events that do not have a persistent state.\n * Unlike `StateSignal`, it does not hold a value. Listeners are only notified of new\n * events as they are dispatched. This makes it suitable for modeling user interactions,\n * system notifications, or any one-off message.\n *\n * @template T The type of the payload for the events. Defaults to `void` for events without a payload.\n *\n * @example\n * // Create a signal for user click events.\n * const onUserClick = new EventSignal<{ x: number, y: number }>({ signalId: 'on-user-click' });\n *\n * // Subscribe to the event.\n * onUserClick.subscribe(clickPosition => {\n * console.log(`User clicked at: ${clickPosition.x}, ${clickPosition.y}`);\n * });\n *\n * // Dispatch an event.\n * onUserClick.dispatch({ x: 100, y: 250 }); // Notifies the listener.\n *\n * // --- Example with no payload ---\n * const onAppReady = new EventSignal({ signalId: 'on-app-ready' });\n * onAppReady.subscribe(() => console.log('Application is ready!'));\n * onAppReady.dispatch(); // Notifies the listener.\n */\nexport class EventSignal<T = void> extends SignalBase<T> {\n /**\n * The logger instance for this signal.\n * @protected\n */\n protected logger_ = createLogger(`event-signal: ${this.signalId}`);\n\n public constructor(config: SignalConfig) {\n super(config);\n this.logger_.logMethod?.('constructor');\n }\n\n /**\n * Dispatches an event with an optional payload to all active listeners.\n * The notification is scheduled as a microtask to prevent blocking and ensure\n * a consistent, non-blocking flow.\n *\n * @param payload The data to send with the event.\n */\n public dispatch(payload: T): void {\n this.logger_.logMethodArgs?.('dispatch', {payload});\n this.checkDestroyed_();\n // Dispatch as a microtask to ensure consistent, non-blocking behavior.\n delay.nextMicrotask().then(() => this.notify_(payload));\n }\n}\n", "import {delay} from '@alwatr/delay';\nimport {createLogger} from '@alwatr/logger';\n\nimport {SignalBase} from './signal-base.js';\n\nimport type {StateSignalConfig, ListenerCallback, SubscribeOptions, SubscribeResult, IReadonlySignal} from '../type.js';\n\n/**\n * A stateful signal that holds a value and notifies listeners when the value changes.\n *\n * `StateSignal` is the core of the signal library, representing a piece of mutable state.\n * It always has a value, and new subscribers immediately receive the current value by default.\n *\n * @template T The type of the state it holds.\n * @implements {IReadonlySignal<T>}\n *\n * @example\n * // Create a new state signal with an initial value.\n * const counter = new StateSignal<number>({\n * signalId: 'counter-signal',\n * initialValue: 0,\n * });\n *\n * // Get the current value.\n * console.log(counter.value); // Outputs: 0\n *\n * // Subscribe to changes.\n * const subscription = counter.subscribe(newValue => {\n * console.log(`Counter changed to: ${newValue}`);\n * });\n *\n * // Set a new value, which triggers the notification.\n * counter.set(1); // Outputs: \"Counter changed to: 1\"\n *\n * // Update value based on the previous value.\n * counter.update(current => current + 1); // Outputs: \"Counter changed to: 2\"\n *\n * // Unsubscribe when no longer needed.\n * subscription.unsubscribe();\n */\nexport class StateSignal<T> extends SignalBase<T> implements IReadonlySignal<T> {\n /**\n * The current value of the signal.\n * @private\n */\n private value__: T;\n\n /**\n * The logger instance for this signal.\n * @protected\n */\n protected logger_ = createLogger(`state-signal: ${this.signalId}`);\n\n public constructor(config: StateSignalConfig<T>) {\n super(config);\n this.value__ = config.initialValue;\n this.logger_.logMethodArgs?.('constructor', {initialValue: this.value__});\n }\n\n /**\n * Retrieves the current value of the signal.\n *\n * @returns The current value.\n *\n * @example\n * console.log(mySignal.value);\n */\n public get value(): T {\n this.checkDestroyed_();\n return this.value__;\n }\n\n /**\n * Updates the signal's value and notifies all active listeners.\n *\n * The notification is scheduled as a microtask, which means the update is deferred\n * slightly to batch multiple synchronous changes.\n *\n * @param newValue The new value to set.\n *\n * @example\n * // For primitive types\n * mySignal.set(42);\n *\n * // For object types, it's best practice to set an immutable new object.\n * mySignal.set({ ...mySignal.value, property: 'new-value' });\n */\n public set(newValue: T): void {\n this.logger_.logMethodArgs?.('set', {newValue});\n this.checkDestroyed_();\n\n // For primitives (including null), do not notify if the value is the same.\n if (Object.is(this.value__, newValue) && (typeof newValue !== 'object' || newValue === null)) {\n return;\n }\n\n this.value__ = newValue;\n\n // Dispatch as a microtask to ensure consistent, non-blocking behavior.\n delay.nextMicrotask().then(() => this.notify_(newValue));\n }\n\n /**\n * Updates the signal's value based on its previous value.\n *\n * This method is particularly useful for state transitions that depend on the current value,\n * especially for objects or arrays, as it promotes an immutable update pattern.\n *\n * @param updater A function that receives the current value and returns the new value.\n *\n * @example\n * // For a counter\n * counterSignal.update(current => current + 1);\n *\n * // For an object state\n * userSignal.update(currentUser => ({ ...currentUser, loggedIn: true }));\n */\n public update(updater: (previousValue: T) => T): void {\n this.logger_.logMethod?.('update');\n this.checkDestroyed_();\n // The updater function is called with the current value to compute the new value,\n // which is then passed to the `set` method.\n this.set(updater(this.value__));\n }\n\n /**\n * Subscribes a listener to this signal.\n *\n * By default, the listener is immediately called with the signal's current value (`receivePrevious: true`).\n * This behavior can be customized via the `options` parameter.\n *\n * @param callback The function to be called when the signal's value changes.\n * @param options Subscription options, including `receivePrevious` and `once`.\n * @returns An object with an `unsubscribe` method to remove the listener.\n */\n public override subscribe(callback: ListenerCallback<T>, options: SubscribeOptions = {}): SubscribeResult {\n this.logger_.logMethodArgs?.('subscribe', {options});\n this.checkDestroyed_();\n\n // By default, new subscribers to a StateSignal should receive the current value.\n if (options.receivePrevious !== false) {\n // Immediately (but asynchronously) call the listener with the current value.\n // This is done in a microtask to ensure it happens after the subscription is fully registered.\n delay\n .nextMicrotask()\n .then(() => callback(this.value__))\n .catch((err) => this.logger_.error('subscribe', 'immediate_callback_failed', err));\n\n // If it's a 'once' subscription that receives the previous value, it's now fulfilled.\n // We don't need to add it to the observers list for future updates.\n if (options.once) {\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n return {unsubscribe: () => {}};\n }\n }\n\n return super.subscribe(callback, options);\n }\n\n /**\n * Destroys the signal, clearing its value and all listeners.\n * This is crucial for memory management to prevent leaks.\n */\n public override destroy(): void {\n this.value__ = null as T; // Clear the value to allow for garbage collection.\n super.destroy();\n }\n}\n", "import {delay} from '@alwatr/delay';\nimport {createLogger} from '@alwatr/logger';\n\nimport {StateSignal} from './state-signal.js';\n\nimport type {ComputedSignalConfig, IReadonlySignal, SubscribeResult, SubscribeOptions} from '../type.js';\n\n/**\n * A read-only signal that derives its value from a set of dependency signals.\n *\n * `ComputedSignal` is a powerful tool for creating values that reactively update when their underlying\n * data sources change. Its value is memoized, meaning the `get` function is only re-evaluated when\n * one of its dependencies has actually changed.\n *\n * A key feature is its lifecycle management: a `ComputedSignal` **must** be destroyed when no longer\n * needed to prevent memory leaks from its subscriptions to dependency signals.\n *\n * @template T The type of the computed value.\n *\n * @example\n * // --- Create dependency signals ---\n * const firstName = new StateSignal({ signalId: 'firstName', initialValue: 'John' });\n * const lastName = new StateSignal({ signalId: 'lastName', initialValue: 'Doe' });\n *\n * // --- Create a computed signal ---\n * const fullName = new ComputedSignal({\n * signalId: 'fullName',\n * deps: [firstName, lastName],\n * get: () => `${firstName.value} ${lastName.value}`,\n * });\n *\n * console.log(fullName.value); // Outputs: \"John Doe\"\n *\n * // --- Subscribe to the computed value ---\n * fullName.subscribe(newFullName => {\n * console.log(`Name changed to: ${newFullName}`);\n * });\n *\n * // --- Update a dependency ---\n * lastName.set('Smith'); // Recalculates and logs: \"Name changed to: John Smith\"\n * console.log(fullName.value); // Outputs: \"John Smith\"\n *\n * // --- IMPORTANT: Clean up when done ---\n * fullName.destroy();\n */\nexport class ComputedSignal<T> implements IReadonlySignal<T> {\n /**\n * The unique identifier for this signal instance.\n */\n public readonly signalId = this.config_.signalId;\n\n /**\n * The logger instance for this signal.\n * @protected\n */\n protected readonly logger_ = createLogger(`computed-signal: ${this.signalId}`);\n\n /**\n * The internal `StateSignal` that holds the computed value.\n * This is how the computed signal provides `.value` and `.subscribe()` methods.\n * @protected\n */\n protected readonly internalSignal_ = new StateSignal<T>({\n signalId: `${this.signalId}-internal`,\n initialValue: this.config_.get(),\n });\n\n /**\n * A list of subscriptions to dependency signals.\n * @private\n */\n\n private readonly dependencySubscriptions__: SubscribeResult[] = [];\n\n /**\n * A flag to prevent concurrent recalculations.\n * @private\n */\n private isRecalculating__ = false;\n\n public constructor(protected config_: ComputedSignalConfig<T>) {\n this.logger_.logMethod?.('constructor');\n this.recalculate_ = this.recalculate_.bind(this);\n\n // Subscribe to all dependencies to trigger recalculation on change.\n for (const signal of config_.deps) {\n this.dependencySubscriptions__.push(signal.subscribe(this.recalculate_, {receivePrevious: false}));\n }\n }\n\n /**\n * The current value of the computed signal.\n * Accessing this property returns the memoized value and does not trigger a recalculation.\n *\n * @returns The current computed value.\n * @throws {Error} If accessed after the signal has been destroyed.\n */\n public get value(): T {\n return this.internalSignal_.value;\n }\n\n /**\n * Indicates whether the computed signal has been destroyed.\n * A destroyed signal cannot be used and will throw an error if interacted with.\n * @returns `true` if the signal is destroyed, `false` otherwise.\n */\n public get isDestroyed(): boolean {\n return this.internalSignal_.isDestroyed;\n }\n\n /**\n * Subscribes a listener to this signal.\n * The listener will be called whenever the computed value changes.\n *\n * @param callback The function to be called with the new value.\n * @param options Subscription options.\n * @returns A `SubscribeResult` object with an `unsubscribe` method.\n */\n public subscribe(callback: (value: T) => void, options?: SubscribeOptions): SubscribeResult {\n return this.internalSignal_.subscribe(callback, options);\n }\n\n /**\n * Returns a Promise that resolves with the next computed value.\n *\n * @returns A Promise that resolves with the next value.\n */\n public untilNext(): Promise<T> {\n return this.internalSignal_.untilNext();\n }\n\n /**\n * Permanently disposes of the computed signal.\n *\n * This is a critical cleanup step. It unsubscribes from all dependency signals,\n * stopping future recalculations and allowing the signal to be garbage collected.\n * Failure to call `destroy()` will result in memory leaks.\n *\n * After `destroy()` is called, any attempt to access `.value` or `.subscribe()` will throw an error.\n */\n public destroy(): void {\n this.logger_.logMethod?.('destroy');\n /**\n * If already destroyed, log an incident and return early.\n */\n if (this.isDestroyed) {\n this.logger_.incident?.('destroy', 'already_destroyed');\n return;\n }\n\n // Unsubscribe from all upstream dependencies.\n for (const subscription of this.dependencySubscriptions__) {\n subscription.unsubscribe();\n }\n this.dependencySubscriptions__.length = 0; // Clear the array of subscriptions.\n\n this.internalSignal_.destroy(); // Destroy the internal signal.\n this.config_.onDestroy?.(); // Call the optional onDestroy callback.\n this.config_ = null as unknown as ComputedSignalConfig<T>; // Release config closure.\n }\n\n /**\n * Schedules a recalculation of the signal's value.\n *\n * This method batches updates using a macrotask (`delay.nextMacrotask`) to ensure the\n * `get` function runs only once per event loop tick, even if multiple dependencies\n * change in the same synchronous block of code.\n * @protected\n */\n protected async recalculate_(): Promise<void> {\n this.logger_.logMethod?.('recalculate_');\n\n if (this.internalSignal_.isDestroyed) {\n // This check is important in case a dependency fires after this signal is destroyed.\n this.logger_.incident?.('recalculate_', 'recalculate_on_destroyed_signal');\n return;\n }\n\n if (this.isRecalculating__) {\n // If a recalculation is already scheduled, do nothing.\n this.logger_.logStep?.('recalculate_', 'skipping_recalculation_already_scheduled');\n return;\n }\n\n this.isRecalculating__ = true;\n\n try {\n // Wait for the next macrotask to start the recalculation.\n // This batches all synchronous dependency updates in the current event loop.\n await delay.nextMacrotask();\n \n if (this.isDestroyed) {\n this.logger_.incident?.('recalculate_', 'destroyed_during_delay');\n this.isRecalculating__ = false;\n return;\n }\n\n this.logger_.logStep?.('recalculate_', 'recalculating_value');\n\n // Set the new value on the internal signal, which will notify our subscribers.\n this.internalSignal_.set(this.config_.get());\n }\n catch (err) {\n this.logger_.error('recalculate_', 'recalculation_failed', err);\n }\n\n // Allow the next recalculation to be scheduled.\n this.isRecalculating__ = false;\n }\n}\n", "import {delay} from '@alwatr/delay';\nimport {createLogger} from '@alwatr/logger';\n\nimport type {EffectSignalConfig, IEffectSignal, SubscribeResult} from '../type.js';\n\n/**\n * Manages a side-effect that runs in response to changes in dependency signals.\n *\n * `EffectSignal` is designed for running logic that interacts with the \"outside world\"—such as\n * logging, network requests, or DOM manipulation—whenever its dependencies are updated.\n * It encapsulates the subscription and cleanup logic, providing a robust and memory-safe\n * way to handle reactive side-effects.\n *\n * A key feature is its lifecycle management: an `EffectSignal` **must** be destroyed when no longer\n * needed to prevent memory leaks and stop the effect from running unnecessarily.\n *\n * @implements {IEffectSignal}\n *\n * @example\n * // --- Create dependency signals ---\n * const counter = new StateSignal({ initialValue: 0, signalId: 'counter' });\n * const user = new StateSignal({ initialValue: 'guest', signalId: 'user' });\n *\n * // --- Create an effect ---\n * const analyticsEffect = new EffectSignal({\n * signalId: 'analytics-effect',\n * deps: [counter, user],\n * run: () => {\n * console.log(`Analytics: User '${user.value}' clicked ${counter.value} times.`);\n * },\n * runImmediately: true, // Optional: run once on creation\n * });\n * // Immediately logs: \"Analytics: User 'guest' clicked 0 times.\"\n *\n * // --- Trigger the effect by updating a dependency ---\n * counter.set(1);\n * // After a macrotask, logs: \"Analytics: User 'guest' clicked 1 times.\"\n *\n * // --- IMPORTANT: Clean up when the effect is no longer needed ---\n * analyticsEffect.destroy();\n *\n * // Further updates will not trigger the effect.\n * counter.set(2); // Nothing is logged.\n */\nexport class EffectSignal implements IEffectSignal {\n /**\n * The unique identifier for this signal instance.\n */\n public readonly signalId = this.config_.signalId ? this.config_.signalId : `[${this.config_.deps.map((dep) => dep.signalId).join(', ')}]`;\n\n /**\n * The logger instance for this signal.\n * @protected\n */\n protected readonly logger_ = createLogger(`effect-signal: ${this.signalId}`);\n\n /**\n * A list of subscriptions to dependency signals.\n * @private\n */\n private readonly dependencySubscriptions__: SubscribeResult[] = [];\n\n /**\n * A flag to prevent concurrent executions of the effect.\n * @private\n */\n private isRunning__ = false;\n\n /**\n * A flag indicating whether the effect has been destroyed.\n * @private\n */\n private isDestroyed__ = false;\n\n /**\n * Indicates whether the effect signal has been destroyed.\n * A destroyed signal will no longer execute its effect and cannot be reused.\n *\n * @returns `true` if the signal is destroyed, `false` otherwise.\n */\n public get isDestroyed(): boolean {\n return this.isDestroyed__;\n }\n\n public constructor(protected config_: EffectSignalConfig) {\n this.logger_.logMethod?.('constructor');\n this.run_ = this.run_.bind(this);\n\n // Subscribe to all dependencies. We don't need the previous value,\n // as the `runImmediately` option controls the initial execution.\n for (const signal of config_.deps) {\n this.dependencySubscriptions__.push(signal.subscribe(this.run_, {receivePrevious: false}));\n }\n\n // Run the effect immediately if requested.\n if (config_.runImmediately === true) {\n // We don't need to await this, let it run in the background.\n void this.run_();\n }\n }\n\n /**\n * Schedules the execution of the effect's `run` function.\n *\n * This method batches updates using a macrotask (`delay.nextMacrotask`) to ensure the\n * `run` function executes only once per event loop tick, even if multiple\n * dependencies change simultaneously.\n * @protected\n */\n protected async run_(): Promise<void> {\n this.logger_.logMethod?.('run_');\n\n if (this.isDestroyed__) {\n this.logger_.incident?.('run_', 'run_on_destroyed_signal');\n return;\n }\n if (this.isRunning__) {\n // If an execution is already scheduled, do nothing.\n this.logger_.logStep?.('run_', 'skipped_because_already_running');\n return;\n }\n\n this.isRunning__ = true;\n\n try {\n // Wait for the next macrotask to batch simultaneous updates.\n await delay.nextMacrotask();\n if (this.isDestroyed__) {\n this.logger_.incident?.('run_', 'destroyed_during_delay');\n this.isRunning__ = false;\n return;\n }\n\n this.logger_.logStep?.('run_', 'executing_effect');\n await this.config_.run();\n }\n catch (err) {\n this.logger_.error('run_', 'effect_failed', err);\n }\n\n // Reset the flag after the current execution is complete.\n this.isRunning__ = false;\n }\n\n /**\n * Permanently disposes of the effect signal.\n *\n * This is a critical cleanup step. It unsubscribes from all dependency signals,\n * stopping any future executions of the effect and allowing it to be garbage collected.\n * Failure to call `destroy()` will result in memory leaks and potentially unwanted side effects.\n */\n public destroy(): void {\n this.logger_.logMethod?.('destroy');\n\n if (this.isDestroyed__) {\n this.logger_.incident?.('destroy', 'already_destroyed');\n return;\n }\n\n this.isDestroyed__ = true;\n\n // Unsubscribe from all upstream dependencies.\n for (const subscription of this.dependencySubscriptions__) {\n subscription.unsubscribe();\n }\n this.dependencySubscriptions__.length = 0; // Clear the array of subscriptions.\n\n this.config_.onDestroy?.(); // Call the optional onDestroy callback.\n this.config_ = null as unknown as EffectSignalConfig; // Release config closure.\n }\n}\n", "import {EventSignal} from '../core/event-signal.js';\n\nimport type {SignalConfig} from '../type.js';\n\n/**\n * Creates a stateless signal for dispatching transient events.\n *\n * `EventSignal` is ideal for broadcasting events that do not have a persistent state.\n * Unlike `StateSignal`, it does not hold a value. Listeners are only notified of new\n * events as they are dispatched. This makes it suitable for modeling user interactions,\n * system notifications, or any one-off message.\n *\n * @template T The type of the payload for the events.\n *\n * @param config The configuration for the event signal.\n * @returns A new instance of EventSignal.\n *\n * @example\n * const onUserClick = createEventSignal<{ x: number, y: number }>({\n * signalId: 'on-user-click'\n * });\n *\n * onUserClick.subscribe(pos => {\n * console.log(`User clicked at: ${pos.x}, ${pos.y}`);\n * });\n *\n * onUserClick.dispatch({ x: 100, y: 250 });\n */\nexport function createEventSignal<T = void>(config: SignalConfig): EventSignal<T> {\n return new EventSignal<T>(config);\n}\n", "import {StateSignal} from '../core/state-signal.js';\n\nimport type {StateSignalConfig} from '../type.js';\n\n/**\n * Creates a stateful signal that holds a value and notifies listeners when the value changes.\n *\n * `StateSignal` is the core of the signal library, representing a piece of mutable state.\n * It always has a value, and new subscribers immediately receive the current value by default.\n *\n * @template T The type of the state it holds.\n *\n * @param config The configuration for the state signal.\n * @returns A new instance of StateSignal.\n *\n * @example\n * const counter = createStateSignal({\n * signalId: 'counter-signal',\n * initialValue: 0,\n * });\n *\n * console.log(counter.value); // Outputs: 0\n * counter.set(1);\n * console.log(counter.value); // Outputs: 1\n */\nexport function createStateSignal<T>(config: StateSignalConfig<T>): StateSignal<T> {\n return new StateSignal(config);\n}\n", "import {ComputedSignal} from '../core/computed-signal.js';\n\nimport type {ComputedSignalConfig} from '../type.js';\n\n/**\n * Creates a read-only signal that derives its value from a set of dependency signals.\n *\n * `ComputedSignal` is a powerful tool for creating values that reactively update when their underlying\n * data sources change. Its value is memoized, meaning the `get` function is only re-evaluated when\n * one of its dependencies has actually changed.\n *\n * A key feature is its lifecycle management: a `ComputedSignal` **must** be destroyed when no longer\n * needed to prevent memory leaks from its subscriptions to dependency signals.\n *\n * @template T The type of the computed value.\n *\n * @param config The configuration for the computed signal.\n * @returns A new, read-only computed signal.\n *\n * @example\n * const firstName = createStateSignal({ signalId: 'firstName', initialValue: 'John' });\n * const lastName = createStateSignal({ signalId: 'lastName', initialValue: 'Doe' });\n *\n * const fullName = createComputedSignal({\n * signalId: 'fullName',\n * deps: [firstName, lastName],\n * get: () => `${firstName.value} ${lastName.value}`,\n * });\n *\n * console.log(fullName.value); // \"John Doe\"\n *\n * // IMPORTANT: Always destroy a computed signal when no longer needed.\n * // fullName.destroy();\n */\nexport function createComputedSignal<T>(config: ComputedSignalConfig<T>): ComputedSignal<T> {\n return new ComputedSignal(config);\n}\n", "import {EffectSignal} from '../core/effect-signal.js';\n\nimport type {EffectSignalConfig} from '../type.js';\n\n/**\n * Creates a side-effect that runs in response to changes in dependency signals.\n *\n * `EffectSignal` is designed for running logic that interacts with the \"outside world\"—such as\n * logging, network requests, or DOM manipulation—whenever its dependencies are updated.\n * It encapsulates the subscription and cleanup logic, providing a robust and memory-safe\n * way to handle reactive side-effects.\n *\n * A key feature is its lifecycle management: an `EffectSignal` **must** be destroyed when no longer\n * needed to prevent memory leaks and stop the effect from running unnecessarily.\n *\n * @param config The configuration for the effect.\n * @returns An object with a `destroy` method to stop the effect.\n *\n * @example\n * // --- Create dependency signals ---\n * const counter = createStateSignal({ initialValue: 0, signalId: 'counter' });\n * const user = createStateSignal({ initialValue: 'guest', signalId: 'user' });\n *\n * // --- Create an effect ---\n * const analyticsEffect = createEffect({\n * deps: [counter, user],\n * run: () => {\n * console.log(`Analytics: User '${user.value}' clicked ${counter.value} times.`);\n * },\n * runImmediately: true, // Optional: run once on creation\n * });\n * // Immediately logs: \"Analytics: User 'guest' clicked 0 times.\"\n *\n * // --- Trigger the effect by updating a dependency ---\n * counter.set(1);\n * // After a macrotask, logs: \"Analytics: User 'guest' clicked 1 times.\"\n *\n * // --- IMPORTANT: Clean up when the effect is no longer needed ---\n * analyticsEffect.destroy();\n *\n * // Further updates will not trigger the effect.\n * counter.set(2); // Nothing is logged.\n */\nexport function createEffect(config: EffectSignalConfig): EffectSignal {\n return new EffectSignal(config);\n}\n", "import {createDebouncer} from '@alwatr/debounce';\n\nimport {StateSignal} from '../core/state-signal.js';\nimport {createComputedSignal} from '../creators/computed.js';\n\nimport type {ComputedSignal} from '../core/computed-signal.js';\nimport type {IReadonlySignal, DebounceSignalConfig} from '../type.js';\n\n/**\n * Creates a new computed signal that debounces updates from a source signal.\n *\n * The returned signal is a `ComputedSignal`, meaning it is read-only and its value is\n * derived from the source. It only updates its value after a specified period of\n * inactivity from the source signal.\n *\n * This operator is essential for handling high-frequency events, such as user input\n * in a search box, resizing a window, or any other event that fires rapidly.\n * By debouncing, you can ensure that expensive operations (like API calls or heavy\n * computations) are only executed once the events have settled.\n *\n * @template T The type of the signal's value.\n *\n * @param {IReadonlySignal<T>} sourceSignal The original signal to debounce.\n * It can be a `StateSignal`, `ComputedSignal`, or any signal implementing `IReadonlySignal`.\n * @param {DebounceSignalConfig} config Configuration object for the debouncer,\n * including `delay`, `leading`, and `trailing` options from `@alwatr/debounce`.\n *\n * @returns {IComputedSignal<T>} A new, read-only computed signal that emits debounced values.\n * Crucially, you **must** call `.destroy()` on this signal when it's no longer\n * needed to prevent memory leaks by cleaning up internal subscriptions and timers.\n *\n * @example\n * ```typescript\n * // Create a source signal for user input.\n * const searchInput = createStateSignal({\n * signalId: 'search-input',\n * initialValue: '',\n * });\n *\n * // Create a debounced signal that waits 300ms after the user stops typing.\n * const debouncedSearch = createDebouncedSignal(searchInput, { delay: 300 });\n *\n * // Use an effect to react to the debounced value.\n * createEffect({\n * deps: [debouncedSearch],\n * run: () => {\n * if (debouncedSearch.value) {\n * console.log(`🚀 Sending API request for: \"${debouncedSearch.value}\"`);\n * }\n * },\n * });\n *\n * searchInput.set('Alwatr');\n * searchInput.set('Alwatr Signal');\n * // (after 300ms of inactivity)\n * // Logs: \"🚀 Sending API request for: \"Alwatr Signal\"\"\n *\n * // IMPORTANT: Clean up when the component unmounts.\n * // debouncedSearch.destroy();\n * ```\n */\nexport function createDebouncedSignal<T>(sourceSignal: IReadonlySignal<T>, config: DebounceSignalConfig): ComputedSignal<T> {\n const signalId = config.signalId ?? `${sourceSignal.signalId}-debounced`;\n\n const internalSignal = new StateSignal<T>({\n signalId: `${signalId}-internal`,\n initialValue: sourceSignal.value,\n });\n\n const debouncer = createDebouncer({\n ...config,\n func: (value: T): void => {\n internalSignal.set(value);\n },\n });\n\n const subscription = sourceSignal.subscribe(debouncer.trigger);\n\n return createComputedSignal({\n signalId,\n deps: [internalSignal],\n get: () => internalSignal.value,\n onDestroy: () => {\n if (internalSignal.isDestroyed) return;\n subscription.unsubscribe();\n debouncer.cancel();\n internalSignal.destroy();\n config.onDestroy?.();\n config = null as unknown as DebounceSignalConfig;\n },\n });\n}\n"],
|
|
5
|
+
"mappings": ";;;AAUO,IAAe,aAAf,MAA6B;AAAA,EAmC3B,YAAsB,SAAuB;AAAvB;AA9B7B;AAAA;AAAA;AAAA;AAAA,SAAgB,WAAW,KAAK,QAAQ;AAYxC;AAAA;AAAA;AAAA;AAAA,SAAmB,aAA6B,CAAC;AAMjD;AAAA;AAAA;AAAA;AAAA,SAAQ,gBAAgB;AAAA,EAY6B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAJrD,IAAW,cAAuB;AAChC,WAAO,KAAK;AAAA,EACd;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUU,gBAAgB,UAA8B;AACtD,SAAK,QAAQ,YAAY,iBAAiB;AAE1C,QAAI,KAAK,eAAe;AACtB,WAAK,QAAQ,WAAW,mBAAmB,qCAAqC;AAChF;AAAA,IACF;AAEA,UAAM,QAAQ,KAAK,WAAW,QAAQ,QAAQ;AAC9C,QAAI,UAAU,IAAI;AAChB,WAAK,WAAW,OAAO,OAAO,CAAC;AAAA,IACjC;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWO,UAAU,UAA+B,SAA6C;AAC3F,SAAK,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AAAA,IAC1B,WAAW,MAAM;AACf,UAAI,eAAe,YAAa;AAChC,mBAAa,YAAY;AACzB,gBAAU,OAAO;AACjB,qBAAe,QAAQ;AACvB,aAAO,YAAY;AACnB,eAAS;AAAA,IACX;AAAA,EACF,CAAC;AACH;",
|
|
6
6
|
"names": ["delay", "createLogger", "createLogger", "delay", "delay", "createLogger", "createLogger", "delay", "delay", "createLogger"]
|
|
7
7
|
}
|