@alwatr/signal 6.2.0 → 9.1.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/dist/core/computed-signal.d.ts +2 -1
- package/dist/core/computed-signal.d.ts.map +1 -1
- package/dist/core/effect-signal.d.ts +2 -1
- package/dist/core/effect-signal.d.ts.map +1 -1
- package/dist/core/event-signal.d.ts +2 -1
- package/dist/core/event-signal.d.ts.map +1 -1
- package/dist/core/signal-base.d.ts.map +1 -1
- package/dist/core/state-signal.d.ts +2 -1
- package/dist/core/state-signal.d.ts.map +1 -1
- package/dist/main.js +5 -0
- package/dist/main.js.map +25 -0
- package/dist/operators/debounce.d.ts.map +1 -1
- package/dist/type.d.ts.map +1 -1
- package/package.json +48 -53
- package/src/core/computed-signal.ts +216 -0
- package/src/core/effect-signal.ts +176 -0
- package/src/core/event-signal.ts +61 -0
- package/src/core/persistent-state-signal.ts +98 -0
- package/src/core/session-state-signal.ts +145 -0
- package/src/core/signal-base.ts +191 -0
- package/src/core/state-signal.ts +178 -0
- package/src/creators/computed.ts +37 -0
- package/src/creators/effect.ts +46 -0
- package/src/creators/event.ts +31 -0
- package/src/creators/persistent-state.ts +33 -0
- package/src/creators/session-state.ts +42 -0
- package/src/creators/state.ts +28 -0
- package/src/main.ts +20 -0
- package/src/operators/debounce.ts +91 -0
- package/src/operators/filter.ts +78 -0
- package/src/operators/map.ts +48 -0
- package/src/type.ts +357 -0
- package/CHANGELOG.md +0 -908
- package/dist/main.cjs +0 -4
- package/dist/main.cjs.map +0 -7
- package/dist/main.mjs +0 -4
- package/dist/main.mjs.map +0 -7
- package/src/core/computed-signal.test.js +0 -166
- package/src/core/effect-signal.test.js +0 -150
- package/src/core/event-signal.test.js +0 -210
- package/src/core/state-signal.test.js +0 -251
- package/src/operators/debounce.test.js +0 -206
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type AlwatrLogger } from '@alwatr/logger';
|
|
1
2
|
import { StateSignal } from './state-signal.js';
|
|
2
3
|
import type { ComputedSignalConfig, IReadonlySignal, SubscribeResult, SubscribeOptions } from '../type.js';
|
|
3
4
|
/**
|
|
@@ -48,7 +49,7 @@ export declare class ComputedSignal<T> implements IReadonlySignal<T> {
|
|
|
48
49
|
* The logger instance for this signal.
|
|
49
50
|
* @protected
|
|
50
51
|
*/
|
|
51
|
-
protected readonly logger_:
|
|
52
|
+
protected readonly logger_: AlwatrLogger;
|
|
52
53
|
/**
|
|
53
54
|
* The internal `StateSignal` that holds the computed value.
|
|
54
55
|
* This is how the computed signal provides `.get()` and `.subscribe()` methods.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"computed-signal.d.ts","sourceRoot":"","sources":["../../src/core/computed-signal.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"computed-signal.d.ts","sourceRoot":"","sources":["../../src/core/computed-signal.ts"],"names":[],"mappings":"AACA,OAAO,EAAgB,KAAK,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAEjE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,KAAK,EAAE,oBAAoB,EAAE,eAAe,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAE3G;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,qBAAa,cAAc,CAAC,CAAC,CAAE,YAAW,eAAe,CAAC,CAAC,CAAC;IAgC9C,SAAS,CAAC,OAAO,EAAE,oBAAoB,CAAC,CAAC,CAAC;IA/BtD;;OAEG;IACH,SAAgB,IAAI,EAAE,MAAM,CAAC;IAE7B;;;OAGG;IACH,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,YAAY,CAAC;IAEzC;;;;OAIG;IACH,SAAS,CAAC,QAAQ,CAAC,eAAe,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC;IAEnD;;;OAGG;IAEH,OAAO,CAAC,QAAQ,CAAC,yBAAyB,CAAyB;IAEnE;;;OAGG;IACH,OAAO,CAAC,iBAAiB,CAAS;gBAEZ,OAAO,EAAE,oBAAoB,CAAC,CAAC,CAAC;IAmBtD;;;;;;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"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type AlwatrLogger } from '@alwatr/logger';
|
|
1
2
|
import type { EffectSignalConfig, IEffectSignal } from '../type.js';
|
|
2
3
|
/**
|
|
3
4
|
* Manages a side-effect that runs in response to changes in dependency signals.
|
|
@@ -48,7 +49,7 @@ export declare class EffectSignal implements IEffectSignal {
|
|
|
48
49
|
* The logger instance for this signal.
|
|
49
50
|
* @protected
|
|
50
51
|
*/
|
|
51
|
-
protected readonly logger_:
|
|
52
|
+
protected readonly logger_: AlwatrLogger;
|
|
52
53
|
/**
|
|
53
54
|
* A list of subscriptions to dependency signals.
|
|
54
55
|
* @private
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"effect-signal.d.ts","sourceRoot":"","sources":["../../src/core/effect-signal.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"effect-signal.d.ts","sourceRoot":"","sources":["../../src/core/effect-signal.ts"],"names":[],"mappings":"AACA,OAAO,EAAgB,KAAK,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAEjE,OAAO,KAAK,EAAE,kBAAkB,EAAE,aAAa,EAAmB,MAAM,YAAY,CAAC;AAErF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,qBAAa,YAAa,YAAW,aAAa;IAwCpC,SAAS,CAAC,OAAO,EAAE,kBAAkB;IAvCjD;;OAEG;IACH,SAAgB,IAAI,EAAE,MAAM,CAAC;IAE7B;;;OAGG;IACH,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,YAAY,CAAC;IAEzC;;;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;gBAEqB,OAAO,EAAE,kBAAkB;IAsBjD;;;;;;;OAOG;cACa,kBAAkB,IAAI,OAAO,CAAC,IAAI,CAAC;IAmCnD;;;;;;OAMG;IACI,OAAO,IAAI,IAAI;CAmBvB"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type AlwatrLogger } from '@alwatr/logger';
|
|
1
2
|
import { SignalBase } from './signal-base.js';
|
|
2
3
|
import type { SignalConfig } from '../type.js';
|
|
3
4
|
/**
|
|
@@ -32,7 +33,7 @@ export declare class EventSignal<T = void> extends SignalBase<T> {
|
|
|
32
33
|
* The logger instance for this signal.
|
|
33
34
|
* @protected
|
|
34
35
|
*/
|
|
35
|
-
protected logger_:
|
|
36
|
+
protected logger_: AlwatrLogger;
|
|
36
37
|
constructor(config: SignalConfig);
|
|
37
38
|
/**
|
|
38
39
|
* Dispatches an event with an optional payload to all active listeners.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-signal.d.ts","sourceRoot":"","sources":["../../src/core/event-signal.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"event-signal.d.ts","sourceRoot":"","sources":["../../src/core/event-signal.ts"],"names":[],"mappings":"AACA,OAAO,EAAgB,KAAK,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAEjE,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/C;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,qBAAa,WAAW,CAAC,CAAC,GAAG,IAAI,CAAE,SAAQ,UAAU,CAAC,CAAC,CAAC;IACtD;;;OAGG;IACH,SAAS,CAAC,OAAO,EAAE,YAAY,CAAC;gBAEpB,MAAM,EAAE,YAAY;IAMhC;;;;;;OAMG;IACI,QAAQ,CAAC,OAAO,EAAE,CAAC,GAAG,IAAI;CAMlC"}
|
|
@@ -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;
|
|
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;AAEjD;;;;;GAKG;AACH,8BAAsB,UAAU,CAAC,CAAC;IAmCpB,SAAS,CAAC,OAAO,EAAE,YAAY;IAlC3C;;;OAGG;IACH,SAAgB,IAAI,EAAE,MAAM,CAAC;IAE7B;;;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;gBAEqB,OAAO,EAAE,YAAY;IAI3C;;;;;OAKG;IACH,SAAS,CAAC,eAAe,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC,CAAC,GAAG,IAAI;IAcvD;;;;;;;;OAQG;IACI,SAAS,CAAC,QAAQ,EAAE,gBAAgB,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,gBAAgB,GAAG,eAAe;IAoB5F;;;;;;;;OAQG;IACH,SAAS,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC,GAAG,IAAI;IA6BjC;;;;;;;;;;;;OAYG;IACI,SAAS,IAAI,OAAO,CAAC,CAAC,CAAC;IAY9B;;;;;;OAMG;IACI,OAAO,IAAI,IAAI;IAYtB;;;;OAIG;IACH,SAAS,CAAC,eAAe,IAAI,IAAI;CAMlC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type AlwatrLogger } from '@alwatr/logger';
|
|
1
2
|
import { SignalBase } from './signal-base.js';
|
|
2
3
|
import type { StateSignalConfig, ListenerCallback, SubscribeOptions, SubscribeResult, IReadonlySignal } from '../type.js';
|
|
3
4
|
/**
|
|
@@ -43,7 +44,7 @@ export declare class StateSignal<T> extends SignalBase<T> implements IReadonlySi
|
|
|
43
44
|
* The logger instance for this signal.
|
|
44
45
|
* @protected
|
|
45
46
|
*/
|
|
46
|
-
protected logger_:
|
|
47
|
+
protected logger_: AlwatrLogger;
|
|
47
48
|
constructor(config: StateSignalConfig<T>);
|
|
48
49
|
/**
|
|
49
50
|
* Retrieves the current value of the signal.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"state-signal.d.ts","sourceRoot":"","sources":["../../src/core/state-signal.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"state-signal.d.ts","sourceRoot":"","sources":["../../src/core/state-signal.ts"],"names":[],"mappings":"AACA,OAAO,EAAgB,KAAK,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAEjE,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,OAAO,KAAK,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAE1H;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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,EAAE,YAAY,CAAC;gBAEpB,MAAM,EAAE,iBAAiB,CAAC,CAAC,CAAC;IAUxC;;;;;;;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;IAOrD;;;;;;;;;OASG;IACa,SAAS,CAAC,QAAQ,EAAE,gBAAgB,CAAC,CAAC,CAAC,EAAE,OAAO,GAAE,gBAAqB,GAAG,eAAe;IA2BzG;;;OAGG;IACa,OAAO,IAAI,IAAI;IAKxB,UAAU,IAAI,eAAe,CAAC,CAAC,CAAC;CAGxC"}
|
package/dist/main.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/* 📦 @alwatr/signal v9.1.0 */
|
|
2
|
+
class q{config_;name;observers_=[];isDestroyed__=!1;get isDestroyed(){return this.isDestroyed__}constructor(G){this.config_=G;this.name=G.name}removeObserver_(G){if(this.logger_.logMethod?.("removeObserver_"),this.isDestroyed__){this.logger_.incident?.("removeObserver_","remove_observer_on_destroyed_signal");return}let H=this.observers_.indexOf(G);if(H!==-1)this.observers_.splice(H,1)}subscribe(G,H){this.logger_.logMethodArgs?.("subscribe.base",H),this.checkDestroyed_();let Q={callback:G,options:H};if(H?.priority)this.observers_.unshift(Q);else this.observers_.push(Q);return{unsubscribe:()=>this.removeObserver_(Q)}}notify_(G){if(this.logger_.logMethodArgs?.("notify_",G),this.isDestroyed__){this.logger_.incident?.("notify_","notify_on_destroyed_signal");return}let H=[...this.observers_];for(let Q of H){if(Q.options?.once)this.removeObserver_(Q);try{let X=Q.callback(G);if(X instanceof Promise)X.catch((Z)=>this.logger_.error("notify_","async_callback_failed",Z,{observer:Q}))}catch(X){this.logger_.error("notify_","sync_callback_failed",X)}}}untilNext(){return this.logger_.logMethod?.("untilNext"),this.checkDestroyed_(),new Promise((G)=>{this.subscribe(G,{once:!0,priority:!0,receivePrevious:!1})})}destroy(){if(this.logger_.logMethod?.("destroy"),this.isDestroyed__){this.logger_.incident?.("destroy_","double_destroy_attempt");return}this.isDestroyed__=!0,this.observers_.length=0,this.config_.onDestroy?.(),this.config_=null}checkDestroyed_(){if(this.isDestroyed__)throw this.logger_.accident("checkDestroyed_","attempt_to_use_destroyed_signal"),Error(`Cannot interact with a destroyed signal (id: ${this.name})`)}}import{delay as P}from"@alwatr/delay";import{createLogger as _}from"@alwatr/logger";class J extends q{logger_;constructor(G){super(G);this.logger_=_(`event-signal:${this.name}`),this.logger_.logMethod?.("constructor")}dispatch(G){this.logger_.logMethodArgs?.("dispatch",{payload:G}),this.checkDestroyed_(),P.nextMicrotask().then(()=>this.notify_(G))}}import{delay as $}from"@alwatr/delay";import{createLogger as U}from"@alwatr/logger";class Y extends q{value__;logger_;constructor(G){super({name:G.name,onDestroy:G.onDestroy});this.logger_=U(`state-signal:${this.name}`),this.value__=G.initialValue,this.logger_.logMethodArgs?.("constructor",{initialValue:this.value__})}get(){return this.checkDestroyed_(),this.value__}set(G){if(this.logger_.logMethodArgs?.("set",{newValue:G}),this.checkDestroyed_(),Object.is(this.value__,G)&&(typeof G!=="object"||G===null))return;this.value__=G,$.nextMicrotask().then(()=>this.notify_(G))}update(G){this.checkDestroyed_();let H=G(this.value__);this.logger_.logMethodFull?.("update",this.value__,H),this.set(H)}subscribe(G,H={}){if(this.logger_.logMethodArgs?.("subscribe",H),this.checkDestroyed_(),H.receivePrevious!==!1){if($.nextMicrotask().then(()=>{this.logger_.logStep?.("subscribe","immediate_callback"),G(this.value__)}).catch((Q)=>this.logger_.error("subscribe","immediate_callback_failed",Q)),H.once)return{unsubscribe:()=>{}}}return super.subscribe(G,H)}destroy(){this.value__=null,super.destroy()}asReadonly(){return this}}import{delay as D}from"@alwatr/delay";import{createLogger as E}from"@alwatr/logger";class M{config_;name;logger_;internalSignal_;dependencySubscriptions__=[];isRecalculating__=!1;constructor(G){this.config_=G;this.name=G.name,this.logger_=E(`computed-signal:${this.name}`),this.recalculate_=this.recalculate_.bind(this),this.logger_.logMethod?.("constructor"),this.internalSignal_=new Y({name:`compute-${this.name}_`,initialValue:this.config_.get()});for(let H of G.deps)this.logger_.logStep?.("constructor","subscribing_to_dependency",{signal:H.name}),this.dependencySubscriptions__.push(H.subscribe(this.recalculate_,{receivePrevious:!1}))}get(){return this.internalSignal_.get()}get isDestroyed(){return this.internalSignal_.isDestroyed}subscribe(G,H){return this.internalSignal_.subscribe(G,H)}untilNext(){return this.internalSignal_.untilNext()}destroy(){if(this.logger_.logMethod?.("destroy"),this.isDestroyed){this.logger_.incident?.("destroy","already_destroyed");return}for(let G of this.dependencySubscriptions__)G.unsubscribe();this.dependencySubscriptions__.length=0,this.internalSignal_.destroy(),this.config_.onDestroy?.(),this.config_=null}async recalculate_(){if(this.logger_.logMethod?.("recalculate_"),this.internalSignal_.isDestroyed){this.logger_.incident?.("recalculate_","recalculate_on_destroyed_signal");return}if(this.isRecalculating__){this.logger_.logStep?.("recalculate_","skipping_recalculation_already_scheduled");return}this.isRecalculating__=!0;try{if(await D.nextMacrotask(),this.isDestroyed){this.logger_.incident?.("recalculate_","destroyed_during_delay"),this.isRecalculating__=!1;return}this.logger_.logStep?.("recalculate_","recalculating_value"),this.internalSignal_.set(this.config_.get())}catch(G){this.logger_.error("recalculate_","recalculation_failed",G)}this.isRecalculating__=!1}}import{delay as x}from"@alwatr/delay";import{createLogger as I}from"@alwatr/logger";class R{config_;name;logger_;dependencySubscriptions__=[];isRunning__=!1;isDestroyed__=!1;get isDestroyed(){return this.isDestroyed__}constructor(G){this.config_=G;this.name=G.name??`[${G.deps.map((H)=>H.name).join(", ")}]`,this.logger_=I(`effect-signal:${this.name}`),this.scheduleExecution_=this.scheduleExecution_.bind(this),this.logger_.logMethod?.("constructor");for(let H of G.deps)this.logger_.logStep?.("constructor","subscribing_to_dependency",{signal:H.name}),this.dependencySubscriptions__.push(H.subscribe(this.scheduleExecution_,{receivePrevious:!1}));if(G.runImmediately===!0)this.logger_.logStep?.("constructor","scheduling_initial_execution"),this.scheduleExecution_()}async scheduleExecution_(){if(this.logger_.logMethod?.("scheduleExecution_"),this.isDestroyed__){this.logger_.incident?.("scheduleExecution_","schedule_execution_on_destroyed_signal");return}if(this.isRunning__){this.logger_.logStep?.("scheduleExecution_","skipped_because_already_running");return}this.isRunning__=!0;try{if(await x.nextMacrotask(),this.isDestroyed__){this.logger_.incident?.("scheduleExecution_","destroyed_during_delay"),this.isRunning__=!1;return}this.logger_.logStep?.("scheduleExecution_","executing_effect"),await this.config_.run()}catch(G){this.logger_.error("scheduleExecution_","effect_failed",G)}this.isRunning__=!1}destroy(){if(this.logger_.logMethod?.("destroy"),this.isDestroyed__){this.logger_.incident?.("destroy","already_destroyed");return}this.isDestroyed__=!0;for(let G of this.dependencySubscriptions__)G.unsubscribe();this.dependencySubscriptions__.length=0,this.config_.onDestroy?.(),this.config_=null}}import{createDebouncer as N}from"@alwatr/debounce";import{createLocalStorageProvider as A}from"@alwatr/local-storage";class z extends Y{storageProvider__;storageDebouncer__;storageSyncSubscription__;constructor(G){let{name:H,storageKey:Q=H,saveDebounceDelay:X=500,initialValue:Z,onDestroy:K,schemaVersion:B}=G,F=A({name:Q,schemaVersion:B});super({name:H,initialValue:F.read()??Z,onDestroy:K});this.logger_.logMethodArgs?.("constructor",G),this.storageProvider__=F,this.storageDebouncer__=N({delay:X,leading:!1,trailing:!0,thisContext:this,func:this.syncStorage__}),this.storageSyncSubscription__=this.subscribe(this.storageDebouncer__.trigger,{receivePrevious:!1})}syncStorage__(G){this.logger_.logMethodArgs?.("syncStorage__",G),this.storageProvider__.write(G)}remove(){this.checkDestroyed_(),this.logger_.logMethod?.("remove"),this.storageProvider__.remove()}destroy(){this.logger_.logMethod?.("destroy"),this.storageDebouncer__.flush(),this.storageSyncSubscription__.unsubscribe(),super.destroy()}}import{createDebouncer as j}from"@alwatr/debounce";import{createSessionStorageProvider as C}from"@alwatr/session-storage";class L extends Y{storageProvider__;storageDebouncer__;storageSyncSubscription__;constructor(G){let{name:H,storageKey:Q=H,saveDebounceDelay:X=500,initialValue:Z,onDestroy:K}=G,B=C({name:Q});super({name:H,initialValue:B.read()??Z,onDestroy:K});this.logger_.logMethodArgs?.("constructor",G),this.storageProvider__=B,this.storageDebouncer__=j({delay:X,leading:!1,trailing:!0,thisContext:this,func:this.syncStorage__}),this.storageSyncSubscription__=this.subscribe(this.storageDebouncer__.trigger,{receivePrevious:!1})}syncStorage__(G){this.logger_.logMethodArgs?.("syncStorage__",G),this.storageProvider__.write(G)}remove(){this.checkDestroyed_(),this.logger_.logMethod?.("remove"),this.storageProvider__.remove()}destroy(){this.logger_.logMethod?.("destroy"),this.storageDebouncer__.flush(),this.storageSyncSubscription__.unsubscribe(),super.destroy()}}function HG(G){return new J(G)}function O(G){return new Y(G)}function W(G){return new M(G)}function WG(G){return new R(G)}function JG(G){return new z(G)}function zG(G){return new L(G)}import{createDebouncer as k}from"@alwatr/debounce";function _G(G,H){let Q=H.name??`${G.name}-debounced`,X=new Y({name:`${Q}-internal`,initialValue:G.get()}),Z=k({...H,thisContext:X,func:X.set}),K=G.subscribe(Z.trigger,{receivePrevious:!1});return W({name:Q,deps:[X],get:()=>X.get(),onDestroy:()=>{if(X.isDestroyed)return;K.unsubscribe(),Z.cancel(),X.destroy(),H.onDestroy?.(),H=null}})}function xG(G,H,Q=`${G.name}-filtered`){let X=G.get(),Z=H(X)?X:void 0,K=O({name:`${Q}-internal`,initialValue:Z}),B=G.subscribe((F)=>{if(H(F))K.set(F)});return W({name:Q,deps:[K],get:()=>K.get(),onDestroy:()=>{B.unsubscribe(),K.destroy()}})}function AG(G,H,Q=`${G.name}-mapped`){return W({name:Q,deps:[G],get:()=>H(G.get())})}export{O as createStateSignal,zG as createSessionStateSignal,JG as createPersistentStateSignal,AG as createMappedSignal,xG as createFilteredSignal,HG as createEventSignal,WG as createEffect,_G as createDebouncedSignal,W as createComputedSignal,Y as StateSignal,q as SignalBase,L as SessionStateSignal,z as PersistentStateSignal,J as EventSignal,R as EffectSignal,M as ComputedSignal};
|
|
3
|
+
|
|
4
|
+
//# debugId=5B42801FDC1E351364756E2164756E21
|
|
5
|
+
//# sourceMappingURL=main.js.map
|
package/dist/main.js.map
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 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/core/persistent-state-signal.ts", "../src/core/session-state-signal.ts", "../src/creators/event.ts", "../src/creators/state.ts", "../src/creators/computed.ts", "../src/creators/effect.ts", "../src/creators/persistent-state.ts", "../src/creators/session-state.ts", "../src/operators/debounce.ts", "../src/operators/filter.ts", "../src/operators/map.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"import type {Observer_, SubscribeOptions, SubscribeResult, ListenerCallback, SignalConfig} from '../type.js';\nimport type {AlwatrLogger} from '@alwatr/logger';\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 name: string;\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 constructor(protected config_: SignalConfig) {\n this.name = config_.name;\n }\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.name})`);\n }\n }\n}\n",
|
|
6
|
+
"import { delay } from '@alwatr/delay';\nimport { createLogger, type AlwatrLogger } 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 }>({ name: '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({ name: '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_: AlwatrLogger;\n\n constructor(config: SignalConfig) {\n super(config);\n this.logger_ = createLogger(`event-signal:${this.name}`);\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",
|
|
7
|
+
"import { delay } from '@alwatr/delay';\nimport { createLogger, type AlwatrLogger } 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 * name: 'counter-signal',\n * initialValue: 0,\n * });\n *\n * // Get the current value.\n * console.log(counter.get()); // 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_: AlwatrLogger;\n\n constructor(config: StateSignalConfig<T>) {\n super({\n name: config.name,\n onDestroy: config.onDestroy,\n });\n this.logger_ = createLogger(`state-signal:${this.name}`);\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.get());\n */\n public get(): 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.get(), 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.checkDestroyed_();\n const newValue = updater(this.value__);\n this.logger_.logMethodFull?.('update', this.value__, newValue);\n this.set(newValue);\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(() => {\n this.logger_.logStep?.('subscribe', 'immediate_callback');\n callback(this.value__);\n })\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 public asReadonly(): IReadonlySignal<T> {\n return this;\n }\n}\n",
|
|
8
|
+
"import { delay } from '@alwatr/delay';\nimport { createLogger, type AlwatrLogger } 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({ name: 'firstName', initialValue: 'John' });\n * const lastName = new StateSignal({ name: 'lastName', initialValue: 'Doe' });\n *\n * // --- Create a computed signal ---\n * const fullName = new ComputedSignal({\n * name: 'fullName',\n * deps: [firstName, lastName],\n * get: () => `${firstName.get()} ${lastName.get()}`,\n * });\n *\n * console.log(fullName.get()); // 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.get()); // 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 name: string;\n\n /**\n * The logger instance for this signal.\n * @protected\n */\n protected readonly logger_: AlwatrLogger;\n\n /**\n * The internal `StateSignal` that holds the computed value.\n * This is how the computed signal provides `.get()` and `.subscribe()` methods.\n * @protected\n */\n protected readonly internalSignal_: StateSignal<T>;\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 constructor(protected config_: ComputedSignalConfig<T>) {\n this.name = config_.name;\n this.logger_ = createLogger(`computed-signal:${this.name}`);\n this.recalculate_ = this.recalculate_.bind(this);\n\n this.logger_.logMethod?.('constructor');\n\n this.internalSignal_ = new StateSignal<T>({\n name: `compute-${this.name}_`,\n initialValue: this.config_.get(),\n });\n\n // Subscribe to all dependencies to trigger recalculation on change.\n for (const signal of config_.deps) {\n this.logger_.logStep?.('constructor', 'subscribing_to_dependency', { signal: signal.name });\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(): T {\n return this.internalSignal_.get();\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 `.get()` 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",
|
|
9
|
+
"import { delay } from '@alwatr/delay';\nimport { createLogger, type AlwatrLogger } 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, name: 'counter' });\n * const user = new StateSignal({ initialValue: 'guest', name: 'user' });\n *\n * // --- Create an effect ---\n * const analyticsEffect = new EffectSignal({\n * name: 'analytics-effect',\n * deps: [counter, user],\n * run: () => {\n * console.log(`Analytics: User '${user.get()}' clicked ${counter.get()} 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 name: string;\n\n /**\n * The logger instance for this signal.\n * @protected\n */\n protected readonly logger_: AlwatrLogger;\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 constructor(protected config_: EffectSignalConfig) {\n this.name = config_.name ?? `[${config_.deps.map((dep) => dep.name).join(', ')}]`;\n this.logger_ = createLogger(`effect-signal:${this.name}`);\n this.scheduleExecution_ = this.scheduleExecution_.bind(this);\n\n this.logger_.logMethod?.('constructor');\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.logger_.logStep?.('constructor', 'subscribing_to_dependency', { signal: signal.name });\n this.dependencySubscriptions__.push(signal.subscribe(this.scheduleExecution_, { receivePrevious: false }));\n }\n\n // Run the effect immediately if requested.\n if (config_.runImmediately === true) {\n this.logger_.logStep?.('constructor', 'scheduling_initial_execution');\n // We don't need to await this, let it run in the background.\n void this.scheduleExecution_();\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 scheduleExecution_(): Promise<void> {\n this.logger_.logMethod?.('scheduleExecution_');\n\n if (this.isDestroyed__) {\n this.logger_.incident?.('scheduleExecution_', 'schedule_execution_on_destroyed_signal');\n return;\n }\n if (this.isRunning__) {\n // If an execution is already scheduled, do nothing.\n this.logger_.logStep?.('scheduleExecution_', '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?.('scheduleExecution_', 'destroyed_during_delay');\n this.isRunning__ = false;\n return;\n }\n\n this.logger_.logStep?.('scheduleExecution_', 'executing_effect');\n await this.config_.run();\n }\n catch (err) {\n this.logger_.error('scheduleExecution_', '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",
|
|
10
|
+
"import {createDebouncer} from '@alwatr/debounce';\nimport {createLocalStorageProvider} from '@alwatr/local-storage';\n\nimport {StateSignal} from './state-signal.js';\n\nimport type {PersistentStateSignalConfig} from '../type.js';\nimport type {LocalStorageProvider} from '@alwatr/local-storage';\n\n/**\n * A stateful signal that persists its value in the browser's localStorage.\n *\n * It extends the functionality of a standard `StateSignal` by automatically reading\n * its initial value from localStorage and writing back any subsequent changes.\n *\n * @template T The type of the state it holds.\n */\nexport class PersistentStateSignal<T extends JsonValue> extends StateSignal<T> {\n /**\n * The underlying storage provider instance.\n * @private\n */\n private readonly storageProvider__: LocalStorageProvider<T>;\n\n /**\n * Debouncer to limit how often we write to localStorage.\n * @private\n */\n private readonly storageDebouncer__;\n\n /**\n * The subscription to the signal's own changes to sync with storage.\n * We subscribe to our own signal. When the value is set from anywhere,\n * this listener will trigger and write it to localStorage.\n * @private\n */\n private readonly storageSyncSubscription__;\n\n constructor(config: PersistentStateSignalConfig<T>) {\n const {name, storageKey = name, saveDebounceDelay = 500, initialValue, onDestroy, schemaVersion} = config;\n\n const storageProvider = createLocalStorageProvider<T>({\n name: storageKey,\n schemaVersion,\n });\n\n super({\n name,\n initialValue: storageProvider.read() ?? initialValue,\n onDestroy,\n });\n\n this.logger_.logMethodArgs?.('constructor', config);\n\n this.storageProvider__ = storageProvider;\n\n this.storageDebouncer__ = createDebouncer({\n delay: saveDebounceDelay,\n leading: false,\n trailing: true,\n thisContext: this,\n func: this.syncStorage__,\n });\n\n this.storageSyncSubscription__ = this.subscribe(this.storageDebouncer__.trigger, {receivePrevious: false});\n }\n\n /**\n * Syncs the new value to storage.\n * @param newValue The new value to sync to storage.\n */\n private syncStorage__(newValue: T): void {\n this.logger_.logMethodArgs?.('syncStorage__', newValue);\n this.storageProvider__.write(newValue);\n }\n\n /**\n * Removes the value from localStorage.\n * This provides a clean way to clear persisted data.\n */\n public remove(): void {\n this.checkDestroyed_();\n this.logger_.logMethod?.('remove');\n // Remove from storage.\n this.storageProvider__.remove();\n }\n\n /**\n * Overrides the destroy method to also clean up the storage sync subscription.\n */\n public override destroy(): void {\n this.logger_.logMethod?.('destroy');\n // Flush any pending storage writes before destroying.\n this.storageDebouncer__.flush();\n // Unsubscribe from the sync listener to prevent memory leaks.\n this.storageSyncSubscription__.unsubscribe();\n super.destroy();\n }\n}\n",
|
|
11
|
+
"import { createDebouncer } from '@alwatr/debounce';\nimport { createSessionStorageProvider } from '@alwatr/session-storage';\n\nimport { StateSignal } from './state-signal.js';\n\nimport type { SessionStateSignalConfig } from '../type.js';\nimport type { SessionStorageProvider } from '@alwatr/session-storage';\n\n/**\n * A stateful signal that persists its value in the browser's `sessionStorage`.\n *\n * It extends `StateSignal` by automatically reading its initial value from `sessionStorage`\n * and writing back any subsequent changes. Unlike `PersistentStateSignal`, the data is cleared\n * automatically when the browser tab or window is closed — it does not survive full page reloads\n * in a new session.\n *\n * This is ideal for transient UI state that should survive soft navigations and refreshes\n * within the same browser tab (e.g., wizard steps, unsaved form drafts, scroll position).\n *\n * @template T The type of the state it holds. Must be JSON-serializable.\n *\n * @example\n * ```typescript\n * import {SessionStateSignal} from '@alwatr/signal';\n *\n * interface WizardState {\n * step: number;\n * answers: Record<string, string>;\n * }\n *\n * const wizardSignal = new SessionStateSignal<WizardState>({\n * name: 'checkout-wizard',\n * initialValue: { step: 1, answers: {} },\n * });\n *\n * // On first load: reads from sessionStorage (or uses initialValue if not found).\n * console.log(wizardSignal.get()); // { step: 1, answers: {} }\n *\n * // Update state — written to sessionStorage automatically (debounced).\n * wizardSignal.set({ step: 2, answers: { q1: 'yes' } });\n *\n * // After a soft page reload, the state is restored from sessionStorage.\n *\n * // Clear the persisted session data without destroying the signal.\n * wizardSignal.remove();\n *\n * // Clean up when the component/page is unmounted.\n * wizardSignal.destroy();\n * ```\n */\nexport class SessionStateSignal<T extends JsonValue> extends StateSignal<T> {\n /**\n * The underlying session storage provider instance.\n * @private\n */\n private readonly storageProvider__: SessionStorageProvider<T>;\n\n /**\n * Debouncer to limit how often we write to sessionStorage.\n * @private\n */\n private readonly storageDebouncer__;\n\n /**\n * Subscription to the signal's own changes for sessionStorage sync.\n * @private\n */\n private readonly storageSyncSubscription__;\n\n constructor(config: SessionStateSignalConfig<T>) {\n const { name, storageKey = name, saveDebounceDelay = 500, initialValue, onDestroy } = config;\n\n const storageProvider = createSessionStorageProvider<T>({ name: storageKey });\n\n super({\n name,\n initialValue: storageProvider.read() ?? initialValue,\n onDestroy,\n });\n\n this.logger_.logMethodArgs?.('constructor', config);\n\n this.storageProvider__ = storageProvider;\n\n this.storageDebouncer__ = createDebouncer({\n delay: saveDebounceDelay,\n leading: false,\n trailing: true,\n thisContext: this,\n func: this.syncStorage__,\n });\n\n this.storageSyncSubscription__ = this.subscribe(this.storageDebouncer__.trigger, { receivePrevious: false });\n }\n\n /**\n * Syncs the new value to sessionStorage.\n * Called automatically by the debouncer after each state change.\n *\n * @param newValue The new value to sync.\n */\n private syncStorage__(newValue: T): void {\n this.logger_.logMethodArgs?.('syncStorage__', newValue);\n this.storageProvider__.write(newValue);\n }\n\n /**\n * Removes the stored value from sessionStorage without destroying the signal.\n *\n * After calling this, the signal continues to hold its current in-memory value;\n * only the sessionStorage entry is cleared.\n *\n * @example\n * ```typescript\n * // User logs out — clear transient session data.\n * wizardSignal.remove();\n * ```\n */\n public remove(): void {\n this.checkDestroyed_();\n this.logger_.logMethod?.('remove');\n this.storageProvider__.remove();\n }\n\n /**\n * Destroys the signal, flushing pending writes and cleaning up all resources.\n *\n * Always call this when the signal is no longer needed (e.g., on component unmount)\n * to prevent memory leaks.\n *\n * @example\n * ```typescript\n * // In a component teardown:\n * wizardSignal.destroy();\n * ```\n */\n public override destroy(): void {\n this.logger_.logMethod?.('destroy');\n // Flush any pending debounced writes before destroying.\n this.storageDebouncer__.flush();\n // Unsubscribe the storage sync listener to prevent memory leaks.\n this.storageSyncSubscription__.unsubscribe();\n super.destroy();\n }\n}",
|
|
12
|
+
"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 * name: '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",
|
|
13
|
+
"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 * name: 'counter-signal',\n * initialValue: 0,\n * });\n *\n * console.log(counter.get()); // Outputs: 0\n * counter.set(1);\n * console.log(counter.get()); // Outputs: 1\n */\nexport function createStateSignal<T>(config: StateSignalConfig<T>): StateSignal<T> {\n return new StateSignal(config);\n}\n",
|
|
14
|
+
"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({ name: 'firstName', initialValue: 'John' });\n * const lastName = createStateSignal({ name: 'lastName', initialValue: 'Doe' });\n *\n * const fullName = createComputedSignal({\n * name: 'fullName',\n * deps: [firstName, lastName],\n * get: () => `${firstName.get()} ${lastName.get()}`,\n * });\n *\n * console.log(fullName.get()); // \"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",
|
|
15
|
+
"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, name: 'counter' });\n * const user = createStateSignal({ initialValue: 'guest', name: 'user' });\n *\n * // --- Create an effect ---\n * const analyticsEffect = createEffect({\n * deps: [counter, user],\n * run: () => {\n * console.log(`Analytics: User '${user.get()}' clicked ${counter.get()} 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",
|
|
16
|
+
"import {PersistentStateSignal} from '../core/persistent-state-signal.js';\n\nimport type {PersistentStateSignalConfig} from '../type.js';\n\n/**\n * Creates a stateful signal that persists its value in localStorage.\n *\n * This function provides a clean, declarative API for creating state that\n * survives page reloads. It automatically handles reading the initial state\n * from localStorage and saving subsequent updates.\n *\n * @template T The type of the state it holds.\n *\n * @param {PersistentStateSignalConfig<T>} config The configuration for the persistent state signal.\n * @returns {PersistentStateSignal<T>} A new instance of PersistentStateSignal.\n *\n * @example\n * // Create a signal to store user's preferred theme.\n * const userThemeSignal = createPersistentStateSignal<string>({\n * name: 'user-theme',\n * schemaVersion: 1,\n * initialValue: 'light',\n * });\n *\n * // The initial value is read from localStorage, or 'light' if not present.\n * console.log(userThemeSignal.get());\n *\n * // Setting a new value updates the in-memory state and writes to localStorage.\n * userThemeSignal.set('dark');\n */\nexport function createPersistentStateSignal<T extends JsonValue>(config: PersistentStateSignalConfig<T>): PersistentStateSignal<T> {\n return new PersistentStateSignal(config);\n}\n",
|
|
17
|
+
"import { SessionStateSignal } from '../core/session-state-signal.js';\n\nimport type { SessionStateSignalConfig } from '../type.js';\n\n/**\n * Creates a stateful signal that persists its value in `sessionStorage`.\n *\n * The stored data survives soft navigations and page refreshes within the same browser tab,\n * but is automatically cleared when the tab or window is closed.\n *\n * Use this for transient UI state such as:\n * - Multi-step wizard progress\n * - Unsaved form drafts\n * - Scroll position or active tab indices\n *\n * @template T The type of the state it holds. Must be JSON-serializable.\n *\n * @param {SessionStateSignalConfig<T>} config The configuration for the session state signal.\n * @returns {SessionStateSignal<T>} A new `SessionStateSignal` instance.\n *\n * @example\n * ```typescript\n * import {createSessionStateSignal} from '@alwatr/signal';\n *\n * const checkoutWizard = createSessionStateSignal<{step: number}>({\n * name: 'checkout-wizard',\n * initialValue: {step: 1},\n * });\n *\n * // State is restored from sessionStorage if it exists.\n * console.log(checkoutWizard.get()); // {step: 1} or last saved value\n *\n * // Update state — automatically saved to sessionStorage.\n * checkoutWizard.set({step: 2});\n *\n * // Cleanup when no longer needed.\n * checkoutWizard.destroy();\n * ```\n */\nexport function createSessionStateSignal<T extends JsonValue>(config: SessionStateSignalConfig<T>): SessionStateSignal<T> {\n return new SessionStateSignal(config);\n}",
|
|
18
|
+
"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 * name: '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.get()) {\n * console.log(`🚀 Sending API request for: \"${debouncedSearch.get()}\"`);\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 name = config.name ?? `${sourceSignal.name}-debounced`;\n\n const internalSignal = new StateSignal<T>({\n name: `${name}-internal`,\n initialValue: sourceSignal.get(),\n });\n\n const debouncer = createDebouncer({\n ...config,\n thisContext: internalSignal,\n func: internalSignal.set,\n });\n\n const subscription = sourceSignal.subscribe(debouncer.trigger, {receivePrevious: false});\n\n return createComputedSignal({\n name: name,\n deps: [internalSignal],\n get: () => internalSignal.get(),\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",
|
|
19
|
+
"import {createComputedSignal} from '../creators/computed.js';\nimport {createStateSignal} from '../creators/state.js';\n\nimport type {ComputedSignal} from '../core/computed-signal.js';\nimport type {IReadonlySignal} from '../type.js';\n\n/**\n * Creates a new computed signal that only emits values from a source signal\n * that satisfy a predicate function.\n *\n * This operator is analogous to `Array.prototype.filter`. It is particularly\n * useful for creating effects or other computed signals that should only react\n * to a specific subset of state changes.\n *\n * Note: The resulting signal's value will be `undefined` until the source\n * emits a value that passes the filter.\n *\n * @template T The type of the signal's value.\n *\n * @param sourceSignal The original signal to filter.\n * @param predicate A function that returns `true` if the value should be passed.\n * @param name An optional, unique identifier for the new signal for debugging. default: `${sourceSignal.name}-filtered`\n *\n * @returns A new computed signal that emits filtered values.\n *\n * @example\n * const numberSignal = createStateSignal({ name: 'number', initialValue: 0 });\n *\n * const evenNumberSignal = createFilteredSignal(\n * numberSignal,\n * (num) => num % 2 === 0,\n * );\n *\n * createEffect({\n * deps: [evenNumberSignal],\n * run: () => {\n * // This effect only runs for even numbers.\n * // The value can be `undefined` on the first run if initialValue is not even.\n * if (evenNumberSignal.get() !== undefined) {\n * console.log(`Even number detected: ${evenNumberSignal.get()}`);\n * }\n * },\n * runImmediately: true,\n * });\n * // Logs: \"Even number detected: 0\"\n *\n * numberSignal.set(1); // Effect does not run\n * numberSignal.set(2); // Logs: \"Even number detected: 2\"\n */\nexport function createFilteredSignal<T>(\n sourceSignal: IReadonlySignal<T>,\n predicate: (value: T) => boolean,\n name = `${sourceSignal.name}-filtered`,\n): ComputedSignal<T | undefined> {\n const sourceValue = sourceSignal.get();\n const initialValue = predicate(sourceValue) ? sourceValue : undefined;\n\n const internalSignal = createStateSignal({\n name: `${name}-internal`,\n initialValue,\n });\n\n const subscription = sourceSignal.subscribe((newValue) => {\n if (predicate(newValue)) {\n internalSignal.set(newValue);\n }\n });\n\n return createComputedSignal({\n name: name,\n deps: [internalSignal],\n get: () => internalSignal.get(),\n onDestroy: () => {\n subscription.unsubscribe();\n internalSignal.destroy();\n },\n });\n}\n",
|
|
20
|
+
"import {createComputedSignal} from '../creators/computed.js';\n\nimport type {ComputedSignal} from '../core/computed-signal.js';\nimport type {IReadonlySignal} from '../type.js';\n\n/**\n * Creates a new read-only computed signal that transforms the value of a source\n * signal using a projection function.\n *\n * This operator is analogous to `Array.prototype.map`. It applies a function to\n * each value emitted by the source signal and emits the result.\n *\n * @template T The type of the source signal's value.\n * @template R The type of the projected value.\n *\n * @param sourceSignal The original signal to transform.\n * @param projectFunction A function to apply to each value from the source signal.\n * @param [name] An optional, unique identifier for the new signal for debugging. default: `${sourceSignal.name}-mapped`\n *\n * @returns A new, read-only computed signal with the transformed values.\n *\n * @example\n * const userSignal = createStateSignal({\n * name: 'user',\n * initialValue: { name: 'John', age: 30 },\n * });\n *\n * const userNameSignal = createMappedSignal(\n * userSignal,\n * (user) => user.name,\n * );\n *\n * console.log(userNameSignal.get()); // Outputs: \"John\"\n * // in next macro-task ...\n * userSignal.set({ name: 'Jane', age: 32 });\n * console.log(userNameSignal.get()); // Outputs: \"Jane\"\n */\nexport function createMappedSignal<T, R>(\n sourceSignal: IReadonlySignal<T>,\n projectFunction: (value: T) => R,\n name = `${sourceSignal.name}-mapped`,\n): ComputedSignal<R> {\n return createComputedSignal({\n name: name,\n deps: [sourceSignal],\n get: () => projectFunction(sourceSignal.get()),\n });\n}\n"
|
|
21
|
+
],
|
|
22
|
+
"mappings": ";AASO,MAAe,CAAc,CAmCZ,QA9BN,KAYG,WAA6B,CAAC,EAMzC,cAAgB,MAQb,YAAW,EAAY,CAChC,OAAO,KAAK,cAGd,WAAW,CAAW,EAAuB,CAAvB,eACpB,KAAK,KAAO,EAAQ,KASZ,eAAe,CAAC,EAA8B,CAGtD,GAFA,KAAK,QAAQ,YAAY,iBAAiB,EAEtC,KAAK,cAAe,CACtB,KAAK,QA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ACf,GAAI,EAAe,YAAa,OAChC,EAAa,YAAY,EACzB,EAAU,OAAO,EACjB,EAAe,QAAQ,EACvB,EAAO,YAAY,EACnB,EAAS,KAEb,CAAC,ECxCI,SAAS,EAAuB,CACrC,EACA,EACA,EAAO,GAAG,EAAa,gBACQ,CAC/B,IAAM,EAAc,EAAa,IAAI,EAC/B,EAAe,EAAU,CAAW,EAAI,EAAc,OAEtD,EAAiB,EAAkB,CACvC,KAAM,GAAG,aACT,cACF,CAAC,EAEK,EAAe,EAAa,UAAU,CAAC,IAAa,CACxD,GAAI,EAAU,CAAQ,EACpB,EAAe,IAAI,CAAQ,EAE9B,EAED,OAAO,EAAqB,CAC1B,KAAM,EACN,KAAM,CAAC,CAAc,EACrB,IAAK,IAAM,EAAe,IAAI,EAC9B,UAAW,IAAM,CACf,EAAa,YAAY,EACzB,EAAe,QAAQ,EAE3B,CAAC,ECvCI,SAAS,EAAwB,CACtC,EACA,EACA,EAAO,GAAG,EAAa,cACJ,CACnB,OAAO,EAAqB,CAC1B,KAAM,EACN,KAAM,CAAC,CAAY,EACnB,IAAK,IAAM,EAAgB,EAAa,IAAI,CAAC,CAC/C,CAAC",
|
|
23
|
+
"debugId": "5B42801FDC1E351364756E2164756E21",
|
|
24
|
+
"names": []
|
|
25
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"debounce.d.ts","sourceRoot":"","sources":["../../src/operators/debounce.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAC,cAAc,EAAC,MAAM,4BAA4B,CAAC;AAC/D,OAAO,KAAK,EAAC,eAAe,EAAE,oBAAoB,EAAC,MAAM,YAAY,CAAC;AAEtE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoDG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,EAAE,YAAY,EAAE,eAAe,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,oBAAoB,GAAG,cAAc,CAAC,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"debounce.d.ts","sourceRoot":"","sources":["../../src/operators/debounce.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAC,cAAc,EAAC,MAAM,4BAA4B,CAAC;AAC/D,OAAO,KAAK,EAAC,eAAe,EAAE,oBAAoB,EAAC,MAAM,YAAY,CAAC;AAEtE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoDG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,EAAE,YAAY,EAAE,eAAe,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,oBAAoB,GAAG,cAAc,CAAC,CAAC,CAAC,CA6B1H"}
|
package/dist/type.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../src/type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,eAAe,EAAC,MAAM,kBAAkB,CAAC;AACtD,OAAO,KAAK,EAAC,0BAA0B,EAAC,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../src/type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,eAAe,EAAC,MAAM,kBAAkB,CAAC;AACtD,OAAO,KAAK,EAAC,0BAA0B,EAAC,MAAM,uBAAuB,CAAC;AAEtE;;;;;;;GAOG;AACH,MAAM,MAAM,gBAAgB,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,KAAK,SAAS,CAAC,IAAI,CAAC,CAAC;AAEhE;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;;;;;;;OASG;IACH,IAAI,CAAC,EAAE,OAAO,CAAC;IAEf;;;;;;;;;OASG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB;;;;;;;;;;;;;;OAcG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;AAED;;;GAGG;AACH,MAAM,WAA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C5B"}
|
package/package.json
CHANGED
|
@@ -1,75 +1,70 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alwatr/signal",
|
|
3
|
+
"version": "9.1.0",
|
|
3
4
|
"description": "Alwatr Signal is a powerful, lightweight, and modern reactive programming library. It is inspired by the best concepts from major reactive libraries but engineered to be faster and more efficient than all of them. It provides a robust and elegant way to manage application state through a system of signals, offering fine-grained reactivity, predictability, and excellent performance.",
|
|
4
|
-
"
|
|
5
|
-
"author": "S. Ali Mihandoost <ali.mihandoost@gmail.com>",
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
"@alwatr/logger": "^6.0.17",
|
|
12
|
-
"@alwatr/session-storage": "^1.0.0"
|
|
13
|
-
},
|
|
14
|
-
"devDependencies": {
|
|
15
|
-
"@alwatr/nano-build": "^6.4.1",
|
|
16
|
-
"@alwatr/prettier-config": "^6.0.2",
|
|
17
|
-
"@alwatr/tsconfig-base": "^6.0.4",
|
|
18
|
-
"@alwatr/type-helper": "^7.0.1",
|
|
19
|
-
"@jest/globals": "^30.2.0",
|
|
20
|
-
"@types/node": "^22.19.11",
|
|
21
|
-
"jest": "^30.2.0",
|
|
22
|
-
"typescript": "^5.9.3"
|
|
5
|
+
"license": "MPL-2.0",
|
|
6
|
+
"author": "S. Ali Mihandoost <ali.mihandoost@gmail.com> (https://ali.mihandoost.com)",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/Alwatr/alwatr",
|
|
11
|
+
"directory": "pkg/signal"
|
|
23
12
|
},
|
|
13
|
+
"homepage": "https://github.com/Alwatr/alwatr/tree/main/pkg/signal#readme",
|
|
14
|
+
"bugs": "https://github.com/Alwatr/alwatr/issues",
|
|
24
15
|
"exports": {
|
|
25
16
|
".": {
|
|
26
17
|
"types": "./dist/main.d.ts",
|
|
27
|
-
"import": "./dist/main.
|
|
28
|
-
"
|
|
18
|
+
"import": "./dist/main.js",
|
|
19
|
+
"default": "./dist/main.js"
|
|
29
20
|
}
|
|
30
21
|
},
|
|
31
|
-
"
|
|
32
|
-
|
|
33
|
-
"
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
"alwatr"
|
|
38
|
-
"esm",
|
|
39
|
-
"observable",
|
|
40
|
-
"signal",
|
|
41
|
-
"typescript"
|
|
42
|
-
],
|
|
43
|
-
"license": "MPL-2.0",
|
|
44
|
-
"main": "./dist/main.cjs",
|
|
45
|
-
"module": "./dist/main.mjs",
|
|
46
|
-
"prettier": "@alwatr/prettier-config",
|
|
47
|
-
"publishConfig": {
|
|
48
|
-
"access": "public"
|
|
22
|
+
"sideEffects": false,
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@alwatr/debounce": "9.1.0",
|
|
25
|
+
"@alwatr/delay": "9.1.0",
|
|
26
|
+
"@alwatr/local-storage": "9.1.0",
|
|
27
|
+
"@alwatr/logger": "9.1.0",
|
|
28
|
+
"@alwatr/session-storage": "9.1.0"
|
|
49
29
|
},
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@alwatr/nano-build": "9.1.0",
|
|
32
|
+
"@alwatr/tsconfig-base": "9.1.0",
|
|
33
|
+
"@alwatr/type-helper": "9.1.0",
|
|
34
|
+
"typescript": "^6.0.2"
|
|
54
35
|
},
|
|
55
36
|
"scripts": {
|
|
56
37
|
"b": "bun run build",
|
|
57
|
-
"build": "bun run build:ts
|
|
58
|
-
"build:es": "nano-build --preset=module",
|
|
38
|
+
"build": "bun run build:ts && bun run build:es",
|
|
39
|
+
"build:es": "nano-build --preset=module src/main.ts",
|
|
59
40
|
"build:ts": "tsc --build",
|
|
60
|
-
"
|
|
61
|
-
"cb": "bun run clean && bun run build",
|
|
41
|
+
"cl": "bun run clean",
|
|
62
42
|
"clean": "rm -rfv dist *.tsbuildinfo",
|
|
63
|
-
"
|
|
43
|
+
"format": "prettier --write \"src/**/*.ts\"",
|
|
44
|
+
"lint": "eslint src/ --ext .ts",
|
|
64
45
|
"t": "bun run test",
|
|
65
|
-
"test": "
|
|
46
|
+
"test": "ALWATR_DEBUG=0 bun test",
|
|
66
47
|
"w": "bun run watch",
|
|
67
48
|
"watch": "bun run watch:ts & bun run watch:es",
|
|
68
49
|
"watch:es": "bun run build:es --watch",
|
|
69
50
|
"watch:ts": "bun run build:ts --watch --preserveWatchOutput"
|
|
70
51
|
},
|
|
71
|
-
"
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
52
|
+
"files": [
|
|
53
|
+
"dist",
|
|
54
|
+
"src/**/*.ts",
|
|
55
|
+
"!src/**/*.test.ts",
|
|
56
|
+
"README.md",
|
|
57
|
+
"LICENSE"
|
|
58
|
+
],
|
|
59
|
+
"publishConfig": {
|
|
60
|
+
"access": "public"
|
|
61
|
+
},
|
|
62
|
+
"keywords": [
|
|
63
|
+
"alwatr",
|
|
64
|
+
"esm",
|
|
65
|
+
"observable",
|
|
66
|
+
"signal",
|
|
67
|
+
"typescript"
|
|
68
|
+
],
|
|
69
|
+
"gitHead": "4a25cd3e0499cf61dd761e87d3711abf9b0cd208"
|
|
75
70
|
}
|