@juulsgaard/signal-tools 21.0.0 → 22.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +136 -122
- package/dist/index.mjs +4 -3
- package/dist/operators.mjs +7 -2
- package/package.json +15 -15
package/dist/index.d.ts
CHANGED
|
@@ -1,128 +1,9 @@
|
|
|
1
1
|
import * as _angular_core from '@angular/core';
|
|
2
|
-
import { Signal, Injector } from '@angular/core';
|
|
2
|
+
import { Signal, Injector, WritableSignal } from '@angular/core';
|
|
3
3
|
import * as rxjs from 'rxjs';
|
|
4
|
-
import {
|
|
4
|
+
import { Subscribable, Observable, Observer, Unsubscribable, BehaviorSubject, Subject } from 'rxjs';
|
|
5
5
|
import { IValueLoadingState } from '@juulsgaard/rxjs-tools';
|
|
6
6
|
|
|
7
|
-
/**
|
|
8
|
-
* Create a signal where values are only emitted after the values have settled for `delay` ms
|
|
9
|
-
* @category Async Signals
|
|
10
|
-
* @param inputSignal - The input value to debounce
|
|
11
|
-
* @param delay - The required delay between values
|
|
12
|
-
* @param options - Additional options
|
|
13
|
-
*/
|
|
14
|
-
declare function debouncedSignal<T>(inputSignal: Signal<T>, delay?: number, options?: {
|
|
15
|
-
injector?: Injector;
|
|
16
|
-
}): Signal<T>;
|
|
17
|
-
/**
|
|
18
|
-
* Create a signal where values are throttled
|
|
19
|
-
* @category Async Signals
|
|
20
|
-
* @param inputSignal - The input value to throttle
|
|
21
|
-
* @param delay - The delay between values
|
|
22
|
-
* @param options - Additional options
|
|
23
|
-
*/
|
|
24
|
-
declare function throttledSignal<T>(inputSignal: Signal<T>, delay?: number, options?: {
|
|
25
|
-
injector?: Injector;
|
|
26
|
-
emitLeading?: boolean;
|
|
27
|
-
}): Signal<T>;
|
|
28
|
-
/**
|
|
29
|
-
* Create a signal where values are throttled and debounced
|
|
30
|
-
* @category Async Signals
|
|
31
|
-
* @param inputSignal - The input value to throttle and debounce
|
|
32
|
-
* @param throttleDelay - The delay between value emissions during continual input
|
|
33
|
-
* @param debounceDelay - The amount of time the input needs to settle before a value is emitted
|
|
34
|
-
* @param options - Additional options
|
|
35
|
-
*/
|
|
36
|
-
declare function debouncedThrottledSignal<T extends string | undefined>(inputSignal: Signal<T>, throttleDelay?: number, debounceDelay?: number, options?: {
|
|
37
|
-
injector?: Injector;
|
|
38
|
-
}): Signal<T>;
|
|
39
|
-
/**
|
|
40
|
-
* Create a signal where values are throttled and debounced, but where empty strings skip the delay
|
|
41
|
-
* @category Async Signals
|
|
42
|
-
* @param inputSignal - The input value to throttle and debounce
|
|
43
|
-
* @param throttleDelay - The delay between value emissions during continual input
|
|
44
|
-
* @param debounceDelay - The amount of time the input needs to settle before a value is emitted
|
|
45
|
-
* @param options - Additional options
|
|
46
|
-
*/
|
|
47
|
-
declare function searchSignal<T extends string | undefined>(inputSignal: Signal<T>, throttleDelay?: number, debounceDelay?: number, options?: {
|
|
48
|
-
injector?: Injector;
|
|
49
|
-
}): Signal<T>;
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* A simple conversion of Behaviour Subject to signal.
|
|
53
|
-
* This will not handle unsubscription, and should only be used when the subject itself is closed / unloaded properly.
|
|
54
|
-
* @category Interop
|
|
55
|
-
* @param subject
|
|
56
|
-
*/
|
|
57
|
-
declare function subjectToSignal<T>(subject: BehaviorSubject<T>): Signal<T>;
|
|
58
|
-
/**
|
|
59
|
-
* A simple conversion of Subject to signal.
|
|
60
|
-
* This will not handle unsubscription, and should only be used when the subject itself is closed / unloaded properly.
|
|
61
|
-
* @category Interop
|
|
62
|
-
* @param subject
|
|
63
|
-
* @param initial - An initial value for the signal.
|
|
64
|
-
*/
|
|
65
|
-
declare function subjectToSignal<T>(subject: Subject<T>, initial: T): Signal<T>;
|
|
66
|
-
|
|
67
|
-
interface LoadingSignalProps {
|
|
68
|
-
/** The current error state */
|
|
69
|
-
readonly error: Signal<Error | undefined>;
|
|
70
|
-
/** The current loading state */
|
|
71
|
-
readonly loading: Signal<boolean>;
|
|
72
|
-
/** Dispose the underlying request / action */
|
|
73
|
-
readonly dispose: () => void;
|
|
74
|
-
}
|
|
75
|
-
/** @category Loading Signal */
|
|
76
|
-
type LoadingSignal<T> = Signal<T | undefined> & LoadingSignalProps;
|
|
77
|
-
/**
|
|
78
|
-
* Options for creating a LoadingSignal
|
|
79
|
-
* @category Loading Signal
|
|
80
|
-
*/
|
|
81
|
-
interface CreateLoadingSignalOptions {
|
|
82
|
-
/** The loading state */
|
|
83
|
-
loading?: Signal<boolean>;
|
|
84
|
-
/** The error state */
|
|
85
|
-
error?: Signal<Error | undefined>;
|
|
86
|
-
/** An optional disposal method */
|
|
87
|
-
dispose?: () => void;
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Create a Loading Signal
|
|
91
|
-
* @param value - The value signal
|
|
92
|
-
* @param options - Optional state data
|
|
93
|
-
* @category Loading Signal
|
|
94
|
-
* @constructor
|
|
95
|
-
*/
|
|
96
|
-
declare function loadingSignal<T>(value: Signal<T | undefined>, options?: CreateLoadingSignalOptions): LoadingSignal<T>;
|
|
97
|
-
/** @category Loading Signal */
|
|
98
|
-
interface LoadingSignalOptions {
|
|
99
|
-
/** Dispose the loading signal on destroy */
|
|
100
|
-
autoDispose?: boolean;
|
|
101
|
-
/** Pass an injector for running outside of injection context */
|
|
102
|
-
injector?: Injector;
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Convert a LoadingState to a LoadingSignal
|
|
106
|
-
* @param loadingState
|
|
107
|
-
* @param options
|
|
108
|
-
* @category Loading Signal
|
|
109
|
-
*/
|
|
110
|
-
declare function toLoadingSignal<T>(loadingState: IValueLoadingState<T>, options?: LoadingSignalOptions): LoadingSignal<T>;
|
|
111
|
-
/**
|
|
112
|
-
* Convert a Subscribable to a LoadingSignal
|
|
113
|
-
* @param observable
|
|
114
|
-
* @param options
|
|
115
|
-
* @category Loading Signal
|
|
116
|
-
*/
|
|
117
|
-
declare function toLoadingSignal<T>(observable: Subscribable<T>, options?: LoadingSignalOptions): LoadingSignal<T>;
|
|
118
|
-
/**
|
|
119
|
-
* Convert a promise to a LoadingSignal
|
|
120
|
-
* @param promise
|
|
121
|
-
* @param options
|
|
122
|
-
* @category Loading Signal
|
|
123
|
-
*/
|
|
124
|
-
declare function toLoadingSignal<T>(promise: Promise<T>, options?: LoadingSignalOptions): LoadingSignal<T>;
|
|
125
|
-
|
|
126
7
|
/**
|
|
127
8
|
* A Map where the state and values are accessible as signals
|
|
128
9
|
* @category Signal Collections
|
|
@@ -817,5 +698,138 @@ declare function requestTracker<T>(request: IValueRequestState<T>): ValueRequest
|
|
|
817
698
|
*/
|
|
818
699
|
declare function requestTracker(request: IRequestState): RequestTracker;
|
|
819
700
|
|
|
820
|
-
|
|
701
|
+
/**
|
|
702
|
+
* Create a signal where values are only emitted after the values have settled for `delay` ms
|
|
703
|
+
* @category Async Signals
|
|
704
|
+
* @param inputSignal - The input value to debounce
|
|
705
|
+
* @param delay - The required delay between values
|
|
706
|
+
* @param options - Additional options
|
|
707
|
+
*/
|
|
708
|
+
declare function debouncedSignal<T>(inputSignal: Signal<T>, delay?: number, options?: {
|
|
709
|
+
injector?: Injector;
|
|
710
|
+
}): Signal<T>;
|
|
711
|
+
/**
|
|
712
|
+
* Create a signal where values are throttled
|
|
713
|
+
* @category Async Signals
|
|
714
|
+
* @param inputSignal - The input value to throttle
|
|
715
|
+
* @param delay - The delay between values
|
|
716
|
+
* @param options - Additional options
|
|
717
|
+
*/
|
|
718
|
+
declare function throttledSignal<T>(inputSignal: Signal<T>, delay?: number, options?: {
|
|
719
|
+
injector?: Injector;
|
|
720
|
+
emitLeading?: boolean;
|
|
721
|
+
}): Signal<T>;
|
|
722
|
+
/**
|
|
723
|
+
* Create a signal where values are throttled and debounced
|
|
724
|
+
* @category Async Signals
|
|
725
|
+
* @param inputSignal - The input value to throttle and debounce
|
|
726
|
+
* @param throttleDelay - The delay between value emissions during continual input
|
|
727
|
+
* @param debounceDelay - The amount of time the input needs to settle before a value is emitted
|
|
728
|
+
* @param options - Additional options
|
|
729
|
+
*/
|
|
730
|
+
declare function debouncedThrottledSignal<T extends string | undefined>(inputSignal: Signal<T>, throttleDelay?: number, debounceDelay?: number, options?: {
|
|
731
|
+
injector?: Injector;
|
|
732
|
+
}): Signal<T>;
|
|
733
|
+
/**
|
|
734
|
+
* Create a signal where values are throttled and debounced, but where empty strings skip the delay
|
|
735
|
+
* @category Async Signals
|
|
736
|
+
* @param inputSignal - The input value to throttle and debounce
|
|
737
|
+
* @param throttleDelay - The delay between value emissions during continual input
|
|
738
|
+
* @param debounceDelay - The amount of time the input needs to settle before a value is emitted
|
|
739
|
+
* @param options - Additional options
|
|
740
|
+
*/
|
|
741
|
+
declare function searchSignal<T extends string | undefined>(inputSignal: Signal<T>, throttleDelay?: number, debounceDelay?: number, options?: {
|
|
742
|
+
injector?: Injector;
|
|
743
|
+
}): Signal<T>;
|
|
744
|
+
|
|
745
|
+
/**
|
|
746
|
+
* A simple conversion of Behaviour Subject to signal.
|
|
747
|
+
* This will not handle unsubscription, and should only be used when the subject itself is closed / unloaded properly.
|
|
748
|
+
* @category Interop
|
|
749
|
+
* @param subject
|
|
750
|
+
*/
|
|
751
|
+
declare function subjectToSignal<T>(subject: BehaviorSubject<T>): Signal<T>;
|
|
752
|
+
/**
|
|
753
|
+
* A simple conversion of Subject to signal.
|
|
754
|
+
* This will not handle unsubscription, and should only be used when the subject itself is closed / unloaded properly.
|
|
755
|
+
* @category Interop
|
|
756
|
+
* @param subject
|
|
757
|
+
* @param initial - An initial value for the signal.
|
|
758
|
+
*/
|
|
759
|
+
declare function subjectToSignal<T>(subject: Subject<T>, initial: T): Signal<T>;
|
|
760
|
+
|
|
761
|
+
interface LoadingSignalProps {
|
|
762
|
+
/** The current error state */
|
|
763
|
+
readonly error: Signal<Error | undefined>;
|
|
764
|
+
/** The current loading state */
|
|
765
|
+
readonly loading: Signal<boolean>;
|
|
766
|
+
/** Dispose the underlying request / action */
|
|
767
|
+
readonly dispose: () => void;
|
|
768
|
+
}
|
|
769
|
+
/** @category Loading Signal */
|
|
770
|
+
type LoadingSignal<T> = Signal<T | undefined> & LoadingSignalProps;
|
|
771
|
+
/**
|
|
772
|
+
* Options for creating a LoadingSignal
|
|
773
|
+
* @category Loading Signal
|
|
774
|
+
*/
|
|
775
|
+
interface CreateLoadingSignalOptions {
|
|
776
|
+
/** The loading state */
|
|
777
|
+
loading?: Signal<boolean>;
|
|
778
|
+
/** The error state */
|
|
779
|
+
error?: Signal<Error | undefined>;
|
|
780
|
+
/** An optional disposal method */
|
|
781
|
+
dispose?: () => void;
|
|
782
|
+
}
|
|
783
|
+
/**
|
|
784
|
+
* Create a Loading Signal
|
|
785
|
+
* @param value - The value signal
|
|
786
|
+
* @param options - Optional state data
|
|
787
|
+
* @category Loading Signal
|
|
788
|
+
* @constructor
|
|
789
|
+
*/
|
|
790
|
+
declare function loadingSignal<T>(value: Signal<T | undefined>, options?: CreateLoadingSignalOptions): LoadingSignal<T>;
|
|
791
|
+
/** @category Loading Signal */
|
|
792
|
+
interface LoadingSignalOptions {
|
|
793
|
+
/** Dispose the loading signal on destroy */
|
|
794
|
+
autoDispose?: boolean;
|
|
795
|
+
/** Pass an injector for running outside of injection context */
|
|
796
|
+
injector?: Injector;
|
|
797
|
+
}
|
|
798
|
+
/**
|
|
799
|
+
* Convert a LoadingState to a LoadingSignal
|
|
800
|
+
* @param loadingState
|
|
801
|
+
* @param options
|
|
802
|
+
* @category Loading Signal
|
|
803
|
+
*/
|
|
804
|
+
declare function toLoadingSignal<T>(loadingState: IValueLoadingState<T>, options?: LoadingSignalOptions): LoadingSignal<T>;
|
|
805
|
+
/**
|
|
806
|
+
* Convert a Subscribable to a LoadingSignal
|
|
807
|
+
* @param observable
|
|
808
|
+
* @param options
|
|
809
|
+
* @category Loading Signal
|
|
810
|
+
*/
|
|
811
|
+
declare function toLoadingSignal<T>(observable: Subscribable<T>, options?: LoadingSignalOptions): LoadingSignal<T>;
|
|
812
|
+
/**
|
|
813
|
+
* Convert a promise to a LoadingSignal
|
|
814
|
+
* @param promise
|
|
815
|
+
* @param options
|
|
816
|
+
* @category Loading Signal
|
|
817
|
+
*/
|
|
818
|
+
declare function toLoadingSignal<T>(promise: Promise<T>, options?: LoadingSignalOptions): LoadingSignal<T>;
|
|
819
|
+
|
|
820
|
+
/**
|
|
821
|
+
* Create a signal containing the last 2 values emitted by the input signal
|
|
822
|
+
* @param inputSignal - The signal emitting values
|
|
823
|
+
* @param firstValue - The value to seed as the initial value in the new signal state
|
|
824
|
+
*/
|
|
825
|
+
declare function pairwiseSignal<T>(inputSignal: Signal<T>, firstValue: T): Signal<[prev: T, next: T]>;
|
|
826
|
+
/**
|
|
827
|
+
* Create a writable signal that proxies another signal via a custom setter
|
|
828
|
+
* @param signal - The signal to proxy
|
|
829
|
+
* @param getter - The getter for the proxy
|
|
830
|
+
* @param setter - The setter for the proxy
|
|
831
|
+
*/
|
|
832
|
+
declare function proxySignal<T, TOut>(signal: WritableSignal<T>, getter: (value: T) => TOut, setter: (value: TOut) => T): WritableSignal<TOut>;
|
|
833
|
+
|
|
834
|
+
export { AsyncRequestState, EmptyRequestState, ErrorRequestState, IRequestState, IValueRequestState, LoadingRequestState, RequestTracker, SignalMap, SignalQueue, SignalSet, SignalStack, StaticRequestState, ValueRequestTracker, WritableRequestState, debouncedSignal, debouncedThrottledSignal, loadingSignal, pairwiseSignal, proxySignal, requestState, requestTracker, searchSignal, signalMap, signalQueue, signalSet, signalStack, subjectToSignal, throttledSignal, toLoadingSignal };
|
|
821
835
|
export type { CreateLoadingSignalOptions, LoadingSignal, LoadingSignalOptions, ReadonlySignalMap, ReadonlySignalSet, SignalQueueDelta, SignalQueueOptions, SignalStackDelta };
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
export { debouncedSignal, debouncedThrottledSignal, searchSignal, throttledSignal } from './async.mjs';
|
|
2
|
-
export { subjectToSignal } from './interop.mjs';
|
|
3
|
-
export { loadingSignal, toLoadingSignal } from './loading-signal.mjs';
|
|
4
1
|
export { SignalMap, signalMap } from './data-structures/signal-map.mjs';
|
|
5
2
|
export { SignalSet, signalSet } from './data-structures/signal-set.mjs';
|
|
6
3
|
export { SignalQueue, signalQueue } from './data-structures/signal-queue.mjs';
|
|
@@ -14,3 +11,7 @@ export { LoadingRequestState } from './request-state/loading-request-state.mjs';
|
|
|
14
11
|
export { StaticRequestState } from './request-state/static-request-state.mjs';
|
|
15
12
|
export { WritableRequestState } from './request-state/writable-request-state.mjs';
|
|
16
13
|
export { RequestTracker, ValueRequestTracker, requestTracker } from './request-state/request-tracker.mjs';
|
|
14
|
+
export { debouncedSignal, debouncedThrottledSignal, searchSignal, throttledSignal } from './async.mjs';
|
|
15
|
+
export { subjectToSignal } from './interop.mjs';
|
|
16
|
+
export { loadingSignal, toLoadingSignal } from './loading-signal.mjs';
|
|
17
|
+
export { pairwiseSignal, proxySignal } from './operators.mjs';
|
package/dist/operators.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { computed } from '@angular/core';
|
|
1
|
+
import { computed, linkedSignal } from '@angular/core';
|
|
2
2
|
|
|
3
3
|
function pairwiseSignal(inputSignal, firstValue) {
|
|
4
4
|
let prevValue = firstValue;
|
|
@@ -9,5 +9,10 @@ function pairwiseSignal(inputSignal, firstValue) {
|
|
|
9
9
|
return tuple;
|
|
10
10
|
});
|
|
11
11
|
}
|
|
12
|
+
function proxySignal(signal, getter, setter) {
|
|
13
|
+
const output = linkedSignal(() => getter(signal()));
|
|
14
|
+
output.set = (value) => signal.set(setter(value));
|
|
15
|
+
return output;
|
|
16
|
+
}
|
|
12
17
|
|
|
13
|
-
export { pairwiseSignal };
|
|
18
|
+
export { pairwiseSignal, proxySignal };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@juulsgaard/signal-tools",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "22.0.1",
|
|
4
4
|
"description": "Tools for working with Angular signals",
|
|
5
5
|
"repository": "git@github.com:Juulsgaard/signal-tools.git",
|
|
6
6
|
"homepage": "https://juulsgaard.github.io/signal-tools/",
|
|
@@ -14,33 +14,33 @@
|
|
|
14
14
|
"dist/**"
|
|
15
15
|
],
|
|
16
16
|
"peerDependencies": {
|
|
17
|
-
"@angular/core": "^
|
|
18
|
-
"@juulsgaard/ts-tools": "~1.
|
|
19
|
-
"@juulsgaard/rxjs-tools": "~1.
|
|
17
|
+
"@angular/core": "^22.2.0",
|
|
18
|
+
"@juulsgaard/ts-tools": "~1.9.0",
|
|
19
|
+
"@juulsgaard/rxjs-tools": "~1.10.0",
|
|
20
20
|
"rxjs": "^7.8.2",
|
|
21
|
-
"typescript": "~
|
|
21
|
+
"typescript": "~6.0.0"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"tslib": "^2.8.1"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@angular/core": "^
|
|
28
|
-
"@juulsgaard/ts-tools": "1.
|
|
29
|
-
"@juulsgaard/rxjs-tools": "1.
|
|
27
|
+
"@angular/core": "^22.2.0",
|
|
28
|
+
"@juulsgaard/ts-tools": "1.9.0",
|
|
29
|
+
"@juulsgaard/rxjs-tools": "1.10.0",
|
|
30
30
|
"@types/jest": "^30.0.0",
|
|
31
|
-
"jest": "^30.
|
|
32
|
-
"rollup": "^4.
|
|
33
|
-
"rollup-plugin-dts": "^6.
|
|
31
|
+
"jest": "^30.5.2",
|
|
32
|
+
"rollup": "^4.63.6",
|
|
33
|
+
"rollup-plugin-dts": "^6.5.1",
|
|
34
34
|
"rollup-plugin-esbuild": "^6.2.1",
|
|
35
35
|
"rxjs": "7.8.2",
|
|
36
|
-
"ts-jest": "^29.4.
|
|
37
|
-
"typedoc": "^0.28.
|
|
38
|
-
"typescript": "~
|
|
36
|
+
"ts-jest": "^29.4.14",
|
|
37
|
+
"typedoc": "^0.28.20",
|
|
38
|
+
"typescript": "~6.0.0"
|
|
39
39
|
},
|
|
40
40
|
"scripts": {
|
|
41
41
|
"build": "rollup -c",
|
|
42
42
|
"test": "jest --config jestconfig.json",
|
|
43
43
|
"prepublishOnly": "rollup -c"
|
|
44
44
|
},
|
|
45
|
-
"packageManager": "pnpm@
|
|
45
|
+
"packageManager": "pnpm@12.8.2"
|
|
46
46
|
}
|