synstate 0.1.0 → 0.1.2
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/LICENSE +201 -0
- package/README.md +272 -532
- package/assets/synstate-icon.png +0 -0
- package/dist/core/combine/combine.d.mts +33 -3
- package/dist/core/combine/combine.d.mts.map +1 -1
- package/dist/core/combine/combine.mjs +34 -4
- package/dist/core/combine/combine.mjs.map +1 -1
- package/dist/core/combine/merge.d.mts +30 -4
- package/dist/core/combine/merge.d.mts.map +1 -1
- package/dist/core/combine/merge.mjs +30 -4
- package/dist/core/combine/merge.mjs.map +1 -1
- package/dist/core/combine/zip.d.mts +28 -3
- package/dist/core/combine/zip.d.mts.map +1 -1
- package/dist/core/combine/zip.mjs +28 -3
- package/dist/core/combine/zip.mjs.map +1 -1
- package/dist/core/create/from-array.d.mts +21 -3
- package/dist/core/create/from-array.d.mts.map +1 -1
- package/dist/core/create/from-array.mjs +21 -3
- package/dist/core/create/from-array.mjs.map +1 -1
- package/dist/core/create/from-promise.d.mts +29 -7
- package/dist/core/create/from-promise.d.mts.map +1 -1
- package/dist/core/create/from-promise.mjs +29 -7
- package/dist/core/create/from-promise.mjs.map +1 -1
- package/dist/core/create/from-subscribable.d.mts +58 -0
- package/dist/core/create/from-subscribable.d.mts.map +1 -1
- package/dist/core/create/from-subscribable.mjs +58 -0
- package/dist/core/create/from-subscribable.mjs.map +1 -1
- package/dist/core/create/interval.d.mts +29 -4
- package/dist/core/create/interval.d.mts.map +1 -1
- package/dist/core/create/interval.mjs +29 -4
- package/dist/core/create/interval.mjs.map +1 -1
- package/dist/core/create/of.d.mts +22 -3
- package/dist/core/create/of.d.mts.map +1 -1
- package/dist/core/create/of.mjs +22 -3
- package/dist/core/create/of.mjs.map +1 -1
- package/dist/core/create/source.d.mts +21 -2
- package/dist/core/create/source.d.mts.map +1 -1
- package/dist/core/create/source.mjs +2 -2
- package/dist/core/create/source.mjs.map +1 -1
- package/dist/core/create/timer.d.mts +23 -4
- package/dist/core/create/timer.d.mts.map +1 -1
- package/dist/core/create/timer.mjs +23 -4
- package/dist/core/create/timer.mjs.map +1 -1
- package/dist/core/index.d.mts +1 -0
- package/dist/core/index.d.mts.map +1 -1
- package/dist/core/index.mjs +15 -3
- package/dist/core/index.mjs.map +1 -1
- package/dist/core/operators/audit-time.d.mts +59 -0
- package/dist/core/operators/audit-time.d.mts.map +1 -1
- package/dist/core/operators/audit-time.mjs +59 -0
- package/dist/core/operators/audit-time.mjs.map +1 -1
- package/dist/core/operators/debounce-time.d.mts +22 -2
- package/dist/core/operators/debounce-time.d.mts.map +1 -1
- package/dist/core/operators/debounce-time.mjs +22 -2
- package/dist/core/operators/debounce-time.mjs.map +1 -1
- package/dist/core/operators/filter.d.mts +26 -1
- package/dist/core/operators/filter.d.mts.map +1 -1
- package/dist/core/operators/filter.mjs.map +1 -1
- package/dist/core/operators/index.mjs +3 -3
- package/dist/core/operators/map-with-index.d.mts +19 -17
- package/dist/core/operators/map-with-index.d.mts.map +1 -1
- package/dist/core/operators/map-with-index.mjs +21 -23
- package/dist/core/operators/map-with-index.mjs.map +1 -1
- package/dist/core/operators/merge-map.d.mts +48 -6
- package/dist/core/operators/merge-map.d.mts.map +1 -1
- package/dist/core/operators/merge-map.mjs +48 -6
- package/dist/core/operators/merge-map.mjs.map +1 -1
- package/dist/core/operators/pairwise.d.mts +30 -1
- package/dist/core/operators/pairwise.d.mts.map +1 -1
- package/dist/core/operators/pairwise.mjs +30 -1
- package/dist/core/operators/pairwise.mjs.map +1 -1
- package/dist/core/operators/scan.d.mts +23 -1
- package/dist/core/operators/scan.d.mts.map +1 -1
- package/dist/core/operators/scan.mjs +23 -1
- package/dist/core/operators/scan.mjs.map +1 -1
- package/dist/core/operators/skip-if-no-change.d.mts +26 -2
- package/dist/core/operators/skip-if-no-change.d.mts.map +1 -1
- package/dist/core/operators/skip-if-no-change.mjs +27 -3
- package/dist/core/operators/skip-if-no-change.mjs.map +1 -1
- package/dist/core/operators/skip-until.d.mts +50 -0
- package/dist/core/operators/skip-until.d.mts.map +1 -1
- package/dist/core/operators/skip-until.mjs +50 -0
- package/dist/core/operators/skip-until.mjs.map +1 -1
- package/dist/core/operators/skip-while.d.mts +48 -1
- package/dist/core/operators/skip-while.d.mts.map +1 -1
- package/dist/core/operators/skip-while.mjs +50 -5
- package/dist/core/operators/skip-while.mjs.map +1 -1
- package/dist/core/operators/switch-map.d.mts +39 -5
- package/dist/core/operators/switch-map.d.mts.map +1 -1
- package/dist/core/operators/switch-map.mjs +39 -5
- package/dist/core/operators/switch-map.mjs.map +1 -1
- package/dist/core/operators/take-until.d.mts +20 -1
- package/dist/core/operators/take-until.d.mts.map +1 -1
- package/dist/core/operators/take-until.mjs +20 -1
- package/dist/core/operators/take-until.mjs.map +1 -1
- package/dist/core/operators/take-while.d.mts +47 -1
- package/dist/core/operators/take-while.d.mts.map +1 -1
- package/dist/core/operators/take-while.mjs +48 -3
- package/dist/core/operators/take-while.mjs.map +1 -1
- package/dist/core/operators/throttle-time.d.mts +44 -5
- package/dist/core/operators/throttle-time.d.mts.map +1 -1
- package/dist/core/operators/throttle-time.mjs +44 -5
- package/dist/core/operators/throttle-time.mjs.map +1 -1
- package/dist/core/operators/with-buffered-from.d.mts +57 -0
- package/dist/core/operators/with-buffered-from.d.mts.map +1 -1
- package/dist/core/operators/with-buffered-from.mjs +58 -1
- package/dist/core/operators/with-buffered-from.mjs.map +1 -1
- package/dist/core/operators/with-current-value-from.d.mts +59 -0
- package/dist/core/operators/with-current-value-from.d.mts.map +1 -1
- package/dist/core/operators/with-current-value-from.mjs +60 -1
- package/dist/core/operators/with-current-value-from.mjs.map +1 -1
- package/dist/core/operators/with-initial-value.d.mts +24 -2
- package/dist/core/operators/with-initial-value.d.mts.map +1 -1
- package/dist/core/operators/with-initial-value.mjs +24 -2
- package/dist/core/operators/with-initial-value.mjs.map +1 -1
- package/dist/core/predefined/index.d.mts +2 -0
- package/dist/core/predefined/index.d.mts.map +1 -0
- package/dist/core/predefined/index.mjs +13 -0
- package/dist/core/predefined/index.mjs.map +1 -0
- package/dist/core/predefined/operators/attach-index.d.mts +8 -0
- package/dist/core/predefined/operators/attach-index.d.mts.map +1 -0
- package/dist/core/predefined/operators/attach-index.mjs +13 -0
- package/dist/core/predefined/operators/attach-index.mjs.map +1 -0
- package/dist/core/predefined/operators/index.d.mts +13 -0
- package/dist/core/predefined/operators/index.d.mts.map +1 -0
- package/dist/core/predefined/operators/index.mjs +13 -0
- package/dist/core/predefined/operators/index.mjs.map +1 -0
- package/dist/core/predefined/operators/map-optional.d.mts +4 -0
- package/dist/core/predefined/operators/map-optional.d.mts.map +1 -0
- package/dist/core/predefined/operators/map-optional.mjs +7 -0
- package/dist/core/predefined/operators/map-optional.mjs.map +1 -0
- package/dist/core/predefined/operators/map-result-err.d.mts +4 -0
- package/dist/core/predefined/operators/map-result-err.d.mts.map +1 -0
- package/dist/core/predefined/operators/map-result-err.mjs +7 -0
- package/dist/core/predefined/operators/map-result-err.mjs.map +1 -0
- package/dist/core/predefined/operators/map-result-ok.d.mts +4 -0
- package/dist/core/predefined/operators/map-result-ok.d.mts.map +1 -0
- package/dist/core/predefined/operators/map-result-ok.mjs +7 -0
- package/dist/core/predefined/operators/map-result-ok.mjs.map +1 -0
- package/dist/core/predefined/operators/map-to.d.mts +3 -0
- package/dist/core/predefined/operators/map-to.d.mts.map +1 -0
- package/dist/core/predefined/operators/map-to.mjs +6 -0
- package/dist/core/predefined/operators/map-to.mjs.map +1 -0
- package/dist/core/predefined/operators/map.d.mts +3 -0
- package/dist/core/predefined/operators/map.d.mts.map +1 -0
- package/dist/core/predefined/operators/map.mjs +8 -0
- package/dist/core/predefined/operators/map.mjs.map +1 -0
- package/dist/core/predefined/operators/pluck.d.mts +8 -0
- package/dist/core/predefined/operators/pluck.d.mts.map +1 -0
- package/dist/core/predefined/operators/pluck.mjs +11 -0
- package/dist/core/predefined/operators/pluck.mjs.map +1 -0
- package/dist/core/predefined/operators/skip.d.mts +3 -0
- package/dist/core/predefined/operators/skip.d.mts.map +1 -0
- package/dist/core/predefined/operators/skip.mjs +9 -0
- package/dist/core/predefined/operators/skip.mjs.map +1 -0
- package/dist/core/predefined/operators/take.d.mts +3 -0
- package/dist/core/predefined/operators/take.d.mts.map +1 -0
- package/dist/core/predefined/operators/take.mjs +8 -0
- package/dist/core/predefined/operators/take.mjs.map +1 -0
- package/dist/core/predefined/operators/unwrap-optional.d.mts +4 -0
- package/dist/core/predefined/operators/unwrap-optional.d.mts.map +1 -0
- package/dist/core/predefined/operators/unwrap-optional.mjs +9 -0
- package/dist/core/predefined/operators/unwrap-optional.mjs.map +1 -0
- package/dist/core/predefined/operators/unwrap-result-err.d.mts +4 -0
- package/dist/core/predefined/operators/unwrap-result-err.d.mts.map +1 -0
- package/dist/core/predefined/operators/unwrap-result-err.mjs +7 -0
- package/dist/core/predefined/operators/unwrap-result-err.mjs.map +1 -0
- package/dist/core/predefined/operators/unwrap-result-ok.d.mts +4 -0
- package/dist/core/predefined/operators/unwrap-result-ok.d.mts.map +1 -0
- package/dist/core/predefined/operators/unwrap-result-ok.mjs +9 -0
- package/dist/core/predefined/operators/unwrap-result-ok.mjs.map +1 -0
- package/dist/core/types/observable-family.d.mts +7 -7
- package/dist/entry-point.mjs +15 -3
- package/dist/entry-point.mjs.map +1 -1
- package/dist/index.mjs +15 -3
- package/dist/index.mjs.map +1 -1
- package/dist/utils/create-event-emitter.d.mts +20 -2
- package/dist/utils/create-event-emitter.d.mts.map +1 -1
- package/dist/utils/create-event-emitter.mjs +20 -2
- package/dist/utils/create-event-emitter.mjs.map +1 -1
- package/dist/utils/create-reducer.d.mts +13 -1
- package/dist/utils/create-reducer.d.mts.map +1 -1
- package/dist/utils/create-reducer.mjs +13 -1
- package/dist/utils/create-reducer.mjs.map +1 -1
- package/dist/utils/create-state.d.mts +24 -4
- package/dist/utils/create-state.d.mts.map +1 -1
- package/dist/utils/create-state.mjs +24 -4
- package/dist/utils/create-state.mjs.map +1 -1
- package/package.json +13 -12
- package/src/core/combine/combine.mts +34 -4
- package/src/core/combine/merge.mts +30 -4
- package/src/core/combine/zip.mts +28 -3
- package/src/core/create/from-array.mts +21 -3
- package/src/core/create/from-promise.mts +29 -7
- package/src/core/create/from-subscribable.mts +58 -0
- package/src/core/create/interval.mts +29 -4
- package/src/core/create/of.mts +22 -3
- package/src/core/create/source.mts +22 -3
- package/src/core/create/timer.mts +23 -4
- package/src/core/index.mts +1 -0
- package/src/core/operators/audit-time.mts +59 -0
- package/src/core/operators/debounce-time.mts +22 -2
- package/src/core/operators/filter.mts +26 -1
- package/src/core/operators/map-with-index.mts +22 -66
- package/src/core/operators/merge-map.mts +48 -6
- package/src/core/operators/pairwise.mts +30 -1
- package/src/core/operators/scan.mts +23 -1
- package/src/core/operators/skip-if-no-change.mts +27 -3
- package/src/core/operators/skip-until.mts +50 -0
- package/src/core/operators/skip-while.mts +49 -16
- package/src/core/operators/switch-map.mts +39 -5
- package/src/core/operators/take-until.mts +20 -1
- package/src/core/operators/take-while.mts +49 -8
- package/src/core/operators/throttle-time.mts +44 -5
- package/src/core/operators/with-buffered-from.mts +58 -1
- package/src/core/operators/with-current-value-from.mts +60 -1
- package/src/core/operators/with-initial-value.mts +24 -2
- package/src/core/predefined/index.mts +1 -0
- package/src/core/predefined/operators/attach-index.mts +13 -0
- package/src/core/predefined/operators/index.mts +12 -0
- package/src/core/predefined/operators/map-optional.mts +8 -0
- package/src/core/predefined/operators/map-result-err.mts +8 -0
- package/src/core/predefined/operators/map-result-ok.mts +8 -0
- package/src/core/predefined/operators/map-to.mts +5 -0
- package/src/core/predefined/operators/map.mts +5 -0
- package/src/core/predefined/operators/pluck.mts +12 -0
- package/src/core/predefined/operators/skip.mts +10 -0
- package/src/core/predefined/operators/take.mts +6 -0
- package/src/core/predefined/operators/unwrap-optional.mts +9 -0
- package/src/core/predefined/operators/unwrap-result-err.mts +8 -0
- package/src/core/predefined/operators/unwrap-result-ok.mts +9 -0
- package/src/core/types/observable-family.mts +7 -7
- package/src/utils/create-event-emitter.mts +20 -2
- package/src/utils/create-reducer.mts +13 -1
- package/src/utils/create-state.mts +24 -4
|
@@ -1,4 +1,50 @@
|
|
|
1
1
|
import { type DropInitialValueOperator } from '../types/index.mjs';
|
|
2
|
+
/**
|
|
3
|
+
* Emits values from the source observable while the predicate returns true.
|
|
4
|
+
* Completes immediately when the predicate returns false.
|
|
5
|
+
*
|
|
6
|
+
* @template A - The type of values from the source
|
|
7
|
+
* @param predicate - Function to test each value
|
|
8
|
+
* @returns An operator that takes values while the predicate is true
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* // Timeline:
|
|
13
|
+
* //
|
|
14
|
+
* // num$ 1 2 3 4 5 6 (ignored)
|
|
15
|
+
* // taken$ 1 2 3 4 | (completes)
|
|
16
|
+
* //
|
|
17
|
+
* // Explanation:
|
|
18
|
+
* // - takeWhile emits values while the predicate returns true
|
|
19
|
+
* // - Completes immediately when the predicate returns false
|
|
20
|
+
* // - No further values are emitted after completion
|
|
21
|
+
*
|
|
22
|
+
* const num$ = source<number>();
|
|
23
|
+
*
|
|
24
|
+
* const taken$ = num$.pipe(takeWhile((x) => x < 5));
|
|
25
|
+
*
|
|
26
|
+
* const mut_history: number[] = [];
|
|
27
|
+
*
|
|
28
|
+
* taken$.subscribe((x) => {
|
|
29
|
+
* mut_history.push(x);
|
|
30
|
+
* });
|
|
31
|
+
*
|
|
32
|
+
* num$.next(1); // logs: 1
|
|
33
|
+
*
|
|
34
|
+
* assert.deepStrictEqual(mut_history, [1]);
|
|
35
|
+
*
|
|
36
|
+
* num$.next(2); // logs: 2
|
|
37
|
+
*
|
|
38
|
+
* assert.deepStrictEqual(mut_history, [1, 2]);
|
|
39
|
+
*
|
|
40
|
+
* num$.next(5); // nothing logged (completes)
|
|
41
|
+
*
|
|
42
|
+
* assert.deepStrictEqual(mut_history, [1, 2]);
|
|
43
|
+
*
|
|
44
|
+
* num$.next(6); // nothing logged (already completed)
|
|
45
|
+
*
|
|
46
|
+
* assert.deepStrictEqual(mut_history, [1, 2]);
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
2
49
|
export declare const takeWhile: <A>(predicate: (value: A, index: SafeUint | -1) => boolean) => DropInitialValueOperator<A, A>;
|
|
3
|
-
export declare const take: <A>(n: PositiveSafeIntWithSmallInt) => DropInitialValueOperator<A, A>;
|
|
4
50
|
//# sourceMappingURL=take-while.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"take-while.d.mts","sourceRoot":"","sources":["../../../src/core/operators/take-while.mts"],"names":[],"mappings":"AASA,OAAO,EACL,KAAK,wBAAwB,EAK9B,MAAM,oBAAoB,CAAC;AAG5B,eAAO,MAAM,SAAS,GACnB,CAAC,EACA,WAAW,CAAC,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,QAAQ,GAAG,CAAC,CAAC,KAAK,OAAO,KACrD,wBAAwB,CAAC,CAAC,EAAE,CAAC,CAE2B,CAAC
|
|
1
|
+
{"version":3,"file":"take-while.d.mts","sourceRoot":"","sources":["../../../src/core/operators/take-while.mts"],"names":[],"mappings":"AASA,OAAO,EACL,KAAK,wBAAwB,EAK9B,MAAM,oBAAoB,CAAC;AAG5B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,eAAO,MAAM,SAAS,GACnB,CAAC,EACA,WAAW,CAAC,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,QAAQ,GAAG,CAAC,CAAC,KAAK,OAAO,KACrD,wBAAwB,CAAC,CAAC,EAAE,CAAC,CAE2B,CAAC"}
|
|
@@ -2,9 +2,54 @@ import { pipe, Optional, asSafeUint, SafeUint } from 'ts-data-forge';
|
|
|
2
2
|
import { SyncChildObservableClass } from '../class/child-observable-class.mjs';
|
|
3
3
|
import '../utils/id-maker.mjs';
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Emits values from the source observable while the predicate returns true.
|
|
7
|
+
* Completes immediately when the predicate returns false.
|
|
8
|
+
*
|
|
9
|
+
* @template A - The type of values from the source
|
|
10
|
+
* @param predicate - Function to test each value
|
|
11
|
+
* @returns An operator that takes values while the predicate is true
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* // Timeline:
|
|
16
|
+
* //
|
|
17
|
+
* // num$ 1 2 3 4 5 6 (ignored)
|
|
18
|
+
* // taken$ 1 2 3 4 | (completes)
|
|
19
|
+
* //
|
|
20
|
+
* // Explanation:
|
|
21
|
+
* // - takeWhile emits values while the predicate returns true
|
|
22
|
+
* // - Completes immediately when the predicate returns false
|
|
23
|
+
* // - No further values are emitted after completion
|
|
24
|
+
*
|
|
25
|
+
* const num$ = source<number>();
|
|
26
|
+
*
|
|
27
|
+
* const taken$ = num$.pipe(takeWhile((x) => x < 5));
|
|
28
|
+
*
|
|
29
|
+
* const mut_history: number[] = [];
|
|
30
|
+
*
|
|
31
|
+
* taken$.subscribe((x) => {
|
|
32
|
+
* mut_history.push(x);
|
|
33
|
+
* });
|
|
34
|
+
*
|
|
35
|
+
* num$.next(1); // logs: 1
|
|
36
|
+
*
|
|
37
|
+
* assert.deepStrictEqual(mut_history, [1]);
|
|
38
|
+
*
|
|
39
|
+
* num$.next(2); // logs: 2
|
|
40
|
+
*
|
|
41
|
+
* assert.deepStrictEqual(mut_history, [1, 2]);
|
|
42
|
+
*
|
|
43
|
+
* num$.next(5); // nothing logged (completes)
|
|
44
|
+
*
|
|
45
|
+
* assert.deepStrictEqual(mut_history, [1, 2]);
|
|
46
|
+
*
|
|
47
|
+
* num$.next(6); // nothing logged (already completed)
|
|
48
|
+
*
|
|
49
|
+
* assert.deepStrictEqual(mut_history, [1, 2]);
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
5
52
|
const takeWhile = (predicate) => (parentObservable) => new TakeWhileObservableClass(parentObservable, predicate);
|
|
6
|
-
/* Specialized operators */
|
|
7
|
-
const take = (n) => takeWhile((_, index) => index + 1 <= n);
|
|
8
53
|
/* implementation */
|
|
9
54
|
class TakeWhileObservableClass extends SyncChildObservableClass {
|
|
10
55
|
#predicate;
|
|
@@ -38,5 +83,5 @@ class TakeWhileObservableClass extends SyncChildObservableClass {
|
|
|
38
83
|
}
|
|
39
84
|
}
|
|
40
85
|
|
|
41
|
-
export {
|
|
86
|
+
export { takeWhile };
|
|
42
87
|
//# sourceMappingURL=take-while.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"take-while.mjs","sources":["../../../src/core/operators/take-while.mts"],"sourcesContent":[null],"names":[],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"take-while.mjs","sources":["../../../src/core/operators/take-while.mts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAkBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8CG;AACI,MAAM,SAAS,GACpB,CACE,SAAsD,KAExD,CAAC,gBAAgB,KACf,IAAI,wBAAwB,CAAC,gBAAgB,EAAE,SAAS;AAE5D;AAEA,MAAM,wBACJ,SAAQ,wBAAyC,CAAA;AAGxC,IAAA,UAAU;AACnB,IAAA,UAAU;IAEV,WAAA,CACE,gBAA+B,EAC/B,SAAsD,EAAA;AAEtD,QAAA,KAAK,CAAC;YACJ,OAAO,EAAE,CAAC,gBAAgB,CAAC;YAC3B,YAAY,EAAE,IAAI,CAAC,gBAAgB,CAAC,WAAW,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,KACzD,QAAQ,CAAC,MAAM,CAAC,GAAG;kBACf,QAAQ,CAAC;kBACT,SAAS,CAAC,GAAG,CAAC,KAAK,EAAE,EAAE;AACvB,sBAAE;AACF,sBAAE,QAAQ,CAAC,IAAI,CACpB,CAAC,KAAK;AACR,SAAA,CAAC;AAEF,QAAA,IAAI,CAAC,UAAU,GAAG,EAAE;AAEpB,QAAA,IAAI,CAAC,UAAU,GAAG,SAAS;;AAGpB,IAAA,SAAS,CAAC,aAA4B,EAAA;QAC7C,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;AAE3B,QAAA,MAAM,EAAE,GAAG,GAAG,CAAC,WAAW,EAAE;AAE5B,QAAA,IAAI,GAAG,CAAC,aAAa,KAAK,aAAa,IAAI,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE;AAC9D,YAAA,OAAO;;AAGT,QAAA,IAAI,CAAC,UAAU;YACb,IAAI,CAAC,UAAU,KAAK,EAAE,GAAG,UAAU,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,UAAU,CAAC;AAE3E,QAAA,IAAI,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC,KAAK,EAAE,IAAI,CAAC,UAAU,CAAC,EAAE;YAC9C,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,aAAa,CAAC;;aAChC;YACL,IAAI,CAAC,QAAQ,EAAE;;;AAGpB;;;;"}
|
|
@@ -9,14 +9,53 @@ import { type KeepInitialValueOperator } from '../types/index.mjs';
|
|
|
9
9
|
*
|
|
10
10
|
* @example
|
|
11
11
|
* ```ts
|
|
12
|
-
*
|
|
12
|
+
* // Timeline (1000ms throttle):
|
|
13
|
+
* //
|
|
14
|
+
* // Time(ms) 0 100 200 300 ... 1000 1100 1200 ... 2000 2100
|
|
15
|
+
* // scroll$ e1 e2 e3 e4 e5 e6 e7 e8 e9
|
|
16
|
+
* // throttled$ e1 e5 e8
|
|
17
|
+
* // |-------1000ms------> |------1000ms------> |------1000ms------>
|
|
18
|
+
* //
|
|
19
|
+
* // Explanation:
|
|
20
|
+
* // - throttleTime emits the first value immediately, then ignores subsequent values
|
|
21
|
+
* // for the specified duration (1000ms)
|
|
22
|
+
* // - At 0ms: e1 is emitted immediately
|
|
23
|
+
* // - At 100-300ms: e2, e3, e4 are ignored (within 1000ms window)
|
|
24
|
+
* // - At 1000ms: e5 is emitted (1000ms has passed since e1)
|
|
25
|
+
* // - At 1100-1200ms: e6, e7 are ignored
|
|
26
|
+
* // - At 2000ms: e8 is emitted (1000ms has passed since e5)
|
|
13
27
|
*
|
|
14
|
-
* const
|
|
28
|
+
* const scroll$ = source<number>();
|
|
15
29
|
*
|
|
16
|
-
* throttled$.
|
|
17
|
-
*
|
|
30
|
+
* const throttled$ = scroll$.pipe(throttleTime(200));
|
|
31
|
+
*
|
|
32
|
+
* const mut_history: number[] = [];
|
|
33
|
+
*
|
|
34
|
+
* throttled$.subscribe((value) => {
|
|
35
|
+
* mut_history.push(value);
|
|
18
36
|
* });
|
|
19
|
-
*
|
|
37
|
+
*
|
|
38
|
+
* scroll$.next(1);
|
|
39
|
+
*
|
|
40
|
+
* assert.deepStrictEqual(mut_history, [1]);
|
|
41
|
+
*
|
|
42
|
+
* await new Promise((resolve) => {
|
|
43
|
+
* setTimeout(resolve, 50);
|
|
44
|
+
* });
|
|
45
|
+
*
|
|
46
|
+
* scroll$.next(2);
|
|
47
|
+
*
|
|
48
|
+
* scroll$.next(3);
|
|
49
|
+
*
|
|
50
|
+
* assert.deepStrictEqual(mut_history, [1]);
|
|
51
|
+
*
|
|
52
|
+
* await new Promise((resolve) => {
|
|
53
|
+
* setTimeout(resolve, 200);
|
|
54
|
+
* });
|
|
55
|
+
*
|
|
56
|
+
* scroll$.next(4);
|
|
57
|
+
*
|
|
58
|
+
* assert.deepStrictEqual(mut_history, [1, 4]);
|
|
20
59
|
* ```
|
|
21
60
|
*/
|
|
22
61
|
export declare const throttleTime: <A>(milliSeconds: number) => KeepInitialValueOperator<A, A>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"throttle-time.d.mts","sourceRoot":"","sources":["../../../src/core/operators/throttle-time.mts"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,wBAAwB,EAI9B,MAAM,oBAAoB,CAAC;AAE5B
|
|
1
|
+
{"version":3,"file":"throttle-time.d.mts","sourceRoot":"","sources":["../../../src/core/operators/throttle-time.mts"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,wBAAwB,EAI9B,MAAM,oBAAoB,CAAC;AAE5B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0DG;AACH,eAAO,MAAM,YAAY,GAAI,CAAC,EAC5B,cAAc,MAAM,KACnB,wBAAwB,CAAC,CAAC,EAAE,CAAC,CAMQ,CAAC"}
|
|
@@ -12,14 +12,53 @@ import '../utils/id-maker.mjs';
|
|
|
12
12
|
*
|
|
13
13
|
* @example
|
|
14
14
|
* ```ts
|
|
15
|
-
*
|
|
15
|
+
* // Timeline (1000ms throttle):
|
|
16
|
+
* //
|
|
17
|
+
* // Time(ms) 0 100 200 300 ... 1000 1100 1200 ... 2000 2100
|
|
18
|
+
* // scroll$ e1 e2 e3 e4 e5 e6 e7 e8 e9
|
|
19
|
+
* // throttled$ e1 e5 e8
|
|
20
|
+
* // |-------1000ms------> |------1000ms------> |------1000ms------>
|
|
21
|
+
* //
|
|
22
|
+
* // Explanation:
|
|
23
|
+
* // - throttleTime emits the first value immediately, then ignores subsequent values
|
|
24
|
+
* // for the specified duration (1000ms)
|
|
25
|
+
* // - At 0ms: e1 is emitted immediately
|
|
26
|
+
* // - At 100-300ms: e2, e3, e4 are ignored (within 1000ms window)
|
|
27
|
+
* // - At 1000ms: e5 is emitted (1000ms has passed since e1)
|
|
28
|
+
* // - At 1100-1200ms: e6, e7 are ignored
|
|
29
|
+
* // - At 2000ms: e8 is emitted (1000ms has passed since e5)
|
|
16
30
|
*
|
|
17
|
-
* const
|
|
31
|
+
* const scroll$ = source<number>();
|
|
18
32
|
*
|
|
19
|
-
* throttled$.
|
|
20
|
-
*
|
|
33
|
+
* const throttled$ = scroll$.pipe(throttleTime(200));
|
|
34
|
+
*
|
|
35
|
+
* const mut_history: number[] = [];
|
|
36
|
+
*
|
|
37
|
+
* throttled$.subscribe((value) => {
|
|
38
|
+
* mut_history.push(value);
|
|
21
39
|
* });
|
|
22
|
-
*
|
|
40
|
+
*
|
|
41
|
+
* scroll$.next(1);
|
|
42
|
+
*
|
|
43
|
+
* assert.deepStrictEqual(mut_history, [1]);
|
|
44
|
+
*
|
|
45
|
+
* await new Promise((resolve) => {
|
|
46
|
+
* setTimeout(resolve, 50);
|
|
47
|
+
* });
|
|
48
|
+
*
|
|
49
|
+
* scroll$.next(2);
|
|
50
|
+
*
|
|
51
|
+
* scroll$.next(3);
|
|
52
|
+
*
|
|
53
|
+
* assert.deepStrictEqual(mut_history, [1]);
|
|
54
|
+
*
|
|
55
|
+
* await new Promise((resolve) => {
|
|
56
|
+
* setTimeout(resolve, 200);
|
|
57
|
+
* });
|
|
58
|
+
*
|
|
59
|
+
* scroll$.next(4);
|
|
60
|
+
*
|
|
61
|
+
* assert.deepStrictEqual(mut_history, [1, 4]);
|
|
23
62
|
* ```
|
|
24
63
|
*/
|
|
25
64
|
const throttleTime = (milliSeconds) =>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"throttle-time.mjs","sources":["../../../src/core/operators/throttle-time.mts"],"sourcesContent":[null],"names":[],"mappings":";;;;AASA
|
|
1
|
+
{"version":3,"file":"throttle-time.mjs","sources":["../../../src/core/operators/throttle-time.mts"],"sourcesContent":[null],"names":[],"mappings":";;;;AASA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0DG;AACI,MAAM,YAAY,GAAG,CAC1B,YAAoB;AAEpB;AACA,CAAC,CAAC,gBAAgB,KAChB,IAAI,2BAA2B,CAC7B,gBAAgB,EAChB,YAAY,CACb;AAEL,MAAM,2BACJ,SAAQ,wBAAyC,CAAA;AAGxC,IAAA,aAAa;AACtB,IAAA,YAAY;AACZ,IAAA,eAAe;IAEf,WAAA,CAAY,gBAA+B,EAAE,YAAoB,EAAA;AAC/D,QAAA,KAAK,CAAC;YACJ,OAAO,EAAE,CAAC,gBAAgB,CAAC;AAC3B,YAAA,YAAY,EAAE,gBAAgB,CAAC,WAAW,EAAE;AAC7C,SAAA,CAAC;AAEF,QAAA,IAAI,CAAC,YAAY,GAAG,SAAS;AAE7B,QAAA,IAAI,CAAC,eAAe,GAAG,KAAK;AAE5B,QAAA,IAAI,CAAC,aAAa,GAAG,YAAY;IACnC;AAES,IAAA,SAAS,CAAC,aAA4B,EAAA;QAC7C,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;AAE3B,QAAA,MAAM,EAAE,GAAG,GAAG,CAAC,WAAW,EAAE;AAE5B,QAAA,IACE,GAAG,CAAC,aAAa,KAAK,aAAa;AACnC,YAAA,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;YACnB,IAAI,CAAC,eAAe,EACpB;AACA,YAAA,OAAO;QACT;QAEA,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,aAAa,CAAC;AAErC,QAAA,IAAI,CAAC,eAAe,GAAG,IAAI;;AAG3B,QAAA,IAAI,CAAC,YAAY,GAAG,UAAU,CAAC,MAAK;AAClC,YAAA,IAAI,CAAC,eAAe,GAAG,KAAK;AAC9B,QAAA,CAAC,EAAE,IAAI,CAAC,aAAa,CAAC;IACxB;IAEA,WAAW,GAAA;AACT,QAAA,IAAI,IAAI,CAAC,YAAY,KAAK,SAAS,EAAE;AACnC,YAAA,YAAY,CAAC,IAAI,CAAC,YAAY,CAAC;QACjC;IACF;IAES,QAAQ,GAAA;QACf,IAAI,CAAC,WAAW,EAAE;QAElB,KAAK,CAAC,QAAQ,EAAE;IAClB;AACD;;;;"}
|
|
@@ -1,4 +1,61 @@
|
|
|
1
1
|
import { type KeepInitialValueOperator, type Observable } from '../types/index.mjs';
|
|
2
|
+
/**
|
|
3
|
+
* Buffers values from the source observable and emits them along with the parent value
|
|
4
|
+
* when the parent emits. The buffer is cleared after each emission.
|
|
5
|
+
*
|
|
6
|
+
* @template A - The type of values from the parent observable
|
|
7
|
+
* @template B - The type of values from the source observable
|
|
8
|
+
* @param observable - The observable whose values will be buffered
|
|
9
|
+
* @returns An operator that emits tuples of [parentValue, bufferedValues]
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* // Timeline:
|
|
14
|
+
* //
|
|
15
|
+
* // data$ d1 d2 d3 d4 d5 d6 d7 d8
|
|
16
|
+
* // trigger$ T1 T2 T3
|
|
17
|
+
* // result$ [T1,[d1,d2,d3]] [T2,[d4,d5,d6]] [T3,[d7,d8]]
|
|
18
|
+
* //
|
|
19
|
+
* // Explanation:
|
|
20
|
+
* // - withBufferedFrom collects values from the source observable
|
|
21
|
+
* // - When the trigger emits, it emits a tuple of [triggerValue, bufferedValues]
|
|
22
|
+
* // - Buffer is cleared after each emission
|
|
23
|
+
* // - Useful for batching data collection triggered by events
|
|
24
|
+
*
|
|
25
|
+
* const data$ = source<string>();
|
|
26
|
+
*
|
|
27
|
+
* const trigger$ = source<number>();
|
|
28
|
+
*
|
|
29
|
+
* const result$ = trigger$.pipe(withBufferedFrom(data$));
|
|
30
|
+
*
|
|
31
|
+
* const mut_history: (readonly [number, readonly string[]])[] = [];
|
|
32
|
+
*
|
|
33
|
+
* result$.subscribe(([triggerValue, bufferedData]) => {
|
|
34
|
+
* mut_history.push([triggerValue, bufferedData]);
|
|
35
|
+
* });
|
|
36
|
+
*
|
|
37
|
+
* data$.next('a');
|
|
38
|
+
*
|
|
39
|
+
* data$.next('b');
|
|
40
|
+
*
|
|
41
|
+
* trigger$.next(1);
|
|
42
|
+
*
|
|
43
|
+
* assert.deepStrictEqual(mut_history, [[1, ['a', 'b']]]);
|
|
44
|
+
*
|
|
45
|
+
* data$.next('c');
|
|
46
|
+
*
|
|
47
|
+
* trigger$.next(2);
|
|
48
|
+
*
|
|
49
|
+
* assert.deepStrictEqual(mut_history, [
|
|
50
|
+
* [1, ['a', 'b']],
|
|
51
|
+
* [2, ['c']],
|
|
52
|
+
* ]);
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
2
55
|
export declare const withBufferedFrom: <A, B>(observable: Observable<B>) => KeepInitialValueOperator<A, readonly [A, readonly B[]]>;
|
|
56
|
+
/**
|
|
57
|
+
* Alias for `withBufferedFrom`.
|
|
58
|
+
* @see withBufferedFrom
|
|
59
|
+
*/
|
|
3
60
|
export declare const withBuffered: <A, B>(observable: Observable<B>) => KeepInitialValueOperator<A, readonly [A, readonly B[]]>;
|
|
4
61
|
//# sourceMappingURL=with-buffered-from.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"with-buffered-from.d.mts","sourceRoot":"","sources":["../../../src/core/operators/with-buffered-from.mts"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,wBAAwB,EAC7B,KAAK,UAAU,EAGhB,MAAM,oBAAoB,CAAC;AAG5B,eAAO,MAAM,gBAAgB,GAAI,CAAC,EAAE,CAAC,EACnC,YAAY,UAAU,CAAC,CAAC,CAAC,KACxB,wBAAwB,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC,EAAE,SAAS,CAAC,EAAE,CAAC,CAMQ,CAAC;AAElE,eAAO,MAAM,YAAY,
|
|
1
|
+
{"version":3,"file":"with-buffered-from.d.mts","sourceRoot":"","sources":["../../../src/core/operators/with-buffered-from.mts"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,wBAAwB,EAC7B,KAAK,UAAU,EAGhB,MAAM,oBAAoB,CAAC;AAG5B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoDG;AACH,eAAO,MAAM,gBAAgB,GAAI,CAAC,EAAE,CAAC,EACnC,YAAY,UAAU,CAAC,CAAC,CAAC,KACxB,wBAAwB,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC,EAAE,SAAS,CAAC,EAAE,CAAC,CAMQ,CAAC;AAElE;;;GAGG;AACH,eAAO,MAAM,YAAY,GAdQ,CAAC,EAAE,CAAC,cACvB,UAAU,CAAC,CAAC,CAAC,KACxB,wBAAwB,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC,EAAE,SAAS,CAAC,EAAE,CAAC,CAYb,CAAC"}
|
|
@@ -3,10 +3,67 @@ import { SyncChildObservableClass } from '../class/child-observable-class.mjs';
|
|
|
3
3
|
import '../utils/id-maker.mjs';
|
|
4
4
|
import { maxDepth } from '../utils/max-depth.mjs';
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* Buffers values from the source observable and emits them along with the parent value
|
|
8
|
+
* when the parent emits. The buffer is cleared after each emission.
|
|
9
|
+
*
|
|
10
|
+
* @template A - The type of values from the parent observable
|
|
11
|
+
* @template B - The type of values from the source observable
|
|
12
|
+
* @param observable - The observable whose values will be buffered
|
|
13
|
+
* @returns An operator that emits tuples of [parentValue, bufferedValues]
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* // Timeline:
|
|
18
|
+
* //
|
|
19
|
+
* // data$ d1 d2 d3 d4 d5 d6 d7 d8
|
|
20
|
+
* // trigger$ T1 T2 T3
|
|
21
|
+
* // result$ [T1,[d1,d2,d3]] [T2,[d4,d5,d6]] [T3,[d7,d8]]
|
|
22
|
+
* //
|
|
23
|
+
* // Explanation:
|
|
24
|
+
* // - withBufferedFrom collects values from the source observable
|
|
25
|
+
* // - When the trigger emits, it emits a tuple of [triggerValue, bufferedValues]
|
|
26
|
+
* // - Buffer is cleared after each emission
|
|
27
|
+
* // - Useful for batching data collection triggered by events
|
|
28
|
+
*
|
|
29
|
+
* const data$ = source<string>();
|
|
30
|
+
*
|
|
31
|
+
* const trigger$ = source<number>();
|
|
32
|
+
*
|
|
33
|
+
* const result$ = trigger$.pipe(withBufferedFrom(data$));
|
|
34
|
+
*
|
|
35
|
+
* const mut_history: (readonly [number, readonly string[]])[] = [];
|
|
36
|
+
*
|
|
37
|
+
* result$.subscribe(([triggerValue, bufferedData]) => {
|
|
38
|
+
* mut_history.push([triggerValue, bufferedData]);
|
|
39
|
+
* });
|
|
40
|
+
*
|
|
41
|
+
* data$.next('a');
|
|
42
|
+
*
|
|
43
|
+
* data$.next('b');
|
|
44
|
+
*
|
|
45
|
+
* trigger$.next(1);
|
|
46
|
+
*
|
|
47
|
+
* assert.deepStrictEqual(mut_history, [[1, ['a', 'b']]]);
|
|
48
|
+
*
|
|
49
|
+
* data$.next('c');
|
|
50
|
+
*
|
|
51
|
+
* trigger$.next(2);
|
|
52
|
+
*
|
|
53
|
+
* assert.deepStrictEqual(mut_history, [
|
|
54
|
+
* [1, ['a', 'b']],
|
|
55
|
+
* [2, ['c']],
|
|
56
|
+
* ]);
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
6
59
|
const withBufferedFrom = (observable) =>
|
|
7
60
|
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
8
61
|
((parentObservable) => new WithBufferedFromObservableClass(parentObservable, observable));
|
|
9
|
-
|
|
62
|
+
/**
|
|
63
|
+
* Alias for `withBufferedFrom`.
|
|
64
|
+
* @see withBufferedFrom
|
|
65
|
+
*/
|
|
66
|
+
const withBuffered = withBufferedFrom;
|
|
10
67
|
class WithBufferedFromObservableClass extends SyncChildObservableClass {
|
|
11
68
|
#mut_bufferedValues = [];
|
|
12
69
|
constructor(parentObservable, observable) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"with-buffered-from.mjs","sources":["../../../src/core/operators/with-buffered-from.mts"],"sourcesContent":[null],"names":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"with-buffered-from.mjs","sources":["../../../src/core/operators/with-buffered-from.mts"],"sourcesContent":[null],"names":[],"mappings":";;;;;AAUA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoDG;AACI,MAAM,gBAAgB,GAAG,CAC9B,UAAyB;AAEzB;AACA,CAAC,CAAC,gBAAgB,KAChB,IAAI,+BAA+B,CACjC,gBAAgB,EAChB,UAAU,CACX;AAEL;;;AAGG;AACI,MAAM,YAAY,GAAG;AAE5B,MAAM,+BACJ,SAAQ,wBAAkE,CAAA;IAG1E,mBAAmB,GAAiB,EAAE;IAEtC,WAAA,CAAY,gBAA+B,EAAE,UAAyB,EAAA;AACpE,QAAA,KAAK,CAAC;YACJ,OAAO,EAAE,CAAC,gBAAgB,CAAC;YAC3B,KAAK,EAAE,CAAC,GAAG,QAAQ,CAAC,CAAC,gBAAgB,EAAE,UAAU,CAAC,CAAC;YACnD,YAAY,EAAE,IAAI,CAAC;AACjB,gBAAA,GAAG,EAAE,gBAAgB,CAAC,WAAW,EAAE;AACnC,gBAAA,EAAE,EAAE,UAAU,CAAC,WAAW,EAAE;AAC7B,aAAA,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,KACjB,QAAQ,CAAC,MAAM,CAAC,GAAG;kBACf,QAAQ,CAAC;AACX,kBAAE,QAAQ,CAAC,IAAI,CAAC;AACZ,oBAAA,GAAG,CAAC,KAAK;AACT,oBAAA,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,CAAC,KAAK,CAAC;iBAC7B,CAAC,CAChB,CAAC,KAAK;AACR,SAAA,CAAC;AAEF,QAAA,UAAU,CAAC,SAAS,CAAC,CAAC,KAAK,KAAI;AAC7B,YAAA,IAAI,CAAC,mBAAmB,GAAG,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,mBAAmB,EAAE,KAAK,CAAC;AAC1E,QAAA,CAAC,CAAC;IACJ;AAES,IAAA,SAAS,CAAC,aAA4B,EAAA;QAC7C,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;AAE3B,QAAA,MAAM,EAAE,GAAG,GAAG,CAAC,WAAW,EAAE;AAE5B,QAAA,IAAI,GAAG,CAAC,aAAa,KAAK,aAAa,IAAI,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE;AAC9D,YAAA,OAAO;QACT;AAEA,QAAA,IAAI,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,KAAK,EAAE,IAAI,CAAC,mBAAmB,CAAC,EAAE,aAAa,CAAC;QAEjE,IAAI,CAAC,YAAY,EAAE;IACrB;IAEA,YAAY,GAAA;AACV,QAAA,IAAI,CAAC,mBAAmB,GAAG,EAAE;IAC/B;AACD;;;;"}
|
|
@@ -1,4 +1,63 @@
|
|
|
1
1
|
import { type DropInitialValueOperator, type Observable } from '../types/index.mjs';
|
|
2
|
+
/**
|
|
3
|
+
* Samples the current value from another observable each time the source emits.
|
|
4
|
+
* Emits a tuple of [sourceValue, sampledValue].
|
|
5
|
+
*
|
|
6
|
+
* @template A - The type of values from the source observable
|
|
7
|
+
* @template B - The type of values from the sampled observable
|
|
8
|
+
* @param observable - The observable to sample from
|
|
9
|
+
* @returns An operator that emits tuples of source and sampled values
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* // Timeline:
|
|
14
|
+
* //
|
|
15
|
+
* // name$ "Alice" "Bob" "Charlie"
|
|
16
|
+
* // age$ 25 30 35 40
|
|
17
|
+
* // result$ ["Alice",25] ["Bob",30] ["Bob",35] ["Charlie",40]
|
|
18
|
+
* //
|
|
19
|
+
* // Explanation:
|
|
20
|
+
* // - withCurrentValueFrom samples the current value from another observable
|
|
21
|
+
* // - Emits a tuple [sourceValue, sampledValue] each time the source emits
|
|
22
|
+
* // - Does not emit until both observables have emitted at least once
|
|
23
|
+
* // - Similar to combine, but only emits when the source (not the sampled) emits
|
|
24
|
+
*
|
|
25
|
+
* const name$ = source<string>();
|
|
26
|
+
*
|
|
27
|
+
* const age$ = source<number>();
|
|
28
|
+
*
|
|
29
|
+
* const result$ = name$.pipe(withCurrentValueFrom(age$));
|
|
30
|
+
*
|
|
31
|
+
* const mut_history: (readonly [string, number])[] = [];
|
|
32
|
+
*
|
|
33
|
+
* result$.subscribe(([name_, currentAge]) => {
|
|
34
|
+
* mut_history.push([name_, currentAge]);
|
|
35
|
+
* });
|
|
36
|
+
*
|
|
37
|
+
* name$.next('Alice'); // nothing logged (age$ hasn't emitted)
|
|
38
|
+
*
|
|
39
|
+
* assert.deepStrictEqual(mut_history, []);
|
|
40
|
+
*
|
|
41
|
+
* age$.next(25);
|
|
42
|
+
*
|
|
43
|
+
* name$.next('Bob'); // logs: Bob is 25 years old
|
|
44
|
+
*
|
|
45
|
+
* assert.deepStrictEqual(mut_history, [['Bob', 25]]);
|
|
46
|
+
*
|
|
47
|
+
* age$.next(30);
|
|
48
|
+
*
|
|
49
|
+
* name$.next('Charlie'); // logs: Charlie is 30 years old
|
|
50
|
+
*
|
|
51
|
+
* assert.deepStrictEqual(mut_history, [
|
|
52
|
+
* ['Bob', 25],
|
|
53
|
+
* ['Charlie', 30],
|
|
54
|
+
* ]);
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
2
57
|
export declare const withCurrentValueFrom: <A, B>(observable: Observable<B>) => DropInitialValueOperator<A, readonly [A, B]>;
|
|
58
|
+
/**
|
|
59
|
+
* Alias for `withCurrentValueFrom`.
|
|
60
|
+
* @see withCurrentValueFrom
|
|
61
|
+
*/
|
|
3
62
|
export declare const withLatestFrom: <A, B>(observable: Observable<B>) => DropInitialValueOperator<A, readonly [A, B]>;
|
|
4
63
|
//# sourceMappingURL=with-current-value-from.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"with-current-value-from.d.mts","sourceRoot":"","sources":["../../../src/core/operators/with-current-value-from.mts"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,wBAAwB,EAC7B,KAAK,UAAU,EAGhB,MAAM,oBAAoB,CAAC;AAG5B,eAAO,MAAM,oBAAoB,GAC9B,CAAC,EAAE,CAAC,EACH,YAAY,UAAU,CAAC,CAAC,CAAC,KACxB,wBAAwB,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAEyB,CAAC;AAE1E,eAAO,MAAM,cAAc,
|
|
1
|
+
{"version":3,"file":"with-current-value-from.d.mts","sourceRoot":"","sources":["../../../src/core/operators/with-current-value-from.mts"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,wBAAwB,EAC7B,KAAK,UAAU,EAGhB,MAAM,oBAAoB,CAAC;AAG5B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsDG;AACH,eAAO,MAAM,oBAAoB,GAC9B,CAAC,EAAE,CAAC,EACH,YAAY,UAAU,CAAC,CAAC,CAAC,KACxB,wBAAwB,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAEyB,CAAC;AAE1E;;;GAGG;AACH,eAAO,MAAM,cAAc,GAVxB,CAAC,EAAE,CAAC,cACS,UAAU,CAAC,CAAC,CAAC,KACxB,wBAAwB,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAQE,CAAC"}
|
|
@@ -3,8 +3,67 @@ import { SyncChildObservableClass } from '../class/child-observable-class.mjs';
|
|
|
3
3
|
import '../utils/id-maker.mjs';
|
|
4
4
|
import { maxDepth } from '../utils/max-depth.mjs';
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* Samples the current value from another observable each time the source emits.
|
|
8
|
+
* Emits a tuple of [sourceValue, sampledValue].
|
|
9
|
+
*
|
|
10
|
+
* @template A - The type of values from the source observable
|
|
11
|
+
* @template B - The type of values from the sampled observable
|
|
12
|
+
* @param observable - The observable to sample from
|
|
13
|
+
* @returns An operator that emits tuples of source and sampled values
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* // Timeline:
|
|
18
|
+
* //
|
|
19
|
+
* // name$ "Alice" "Bob" "Charlie"
|
|
20
|
+
* // age$ 25 30 35 40
|
|
21
|
+
* // result$ ["Alice",25] ["Bob",30] ["Bob",35] ["Charlie",40]
|
|
22
|
+
* //
|
|
23
|
+
* // Explanation:
|
|
24
|
+
* // - withCurrentValueFrom samples the current value from another observable
|
|
25
|
+
* // - Emits a tuple [sourceValue, sampledValue] each time the source emits
|
|
26
|
+
* // - Does not emit until both observables have emitted at least once
|
|
27
|
+
* // - Similar to combine, but only emits when the source (not the sampled) emits
|
|
28
|
+
*
|
|
29
|
+
* const name$ = source<string>();
|
|
30
|
+
*
|
|
31
|
+
* const age$ = source<number>();
|
|
32
|
+
*
|
|
33
|
+
* const result$ = name$.pipe(withCurrentValueFrom(age$));
|
|
34
|
+
*
|
|
35
|
+
* const mut_history: (readonly [string, number])[] = [];
|
|
36
|
+
*
|
|
37
|
+
* result$.subscribe(([name_, currentAge]) => {
|
|
38
|
+
* mut_history.push([name_, currentAge]);
|
|
39
|
+
* });
|
|
40
|
+
*
|
|
41
|
+
* name$.next('Alice'); // nothing logged (age$ hasn't emitted)
|
|
42
|
+
*
|
|
43
|
+
* assert.deepStrictEqual(mut_history, []);
|
|
44
|
+
*
|
|
45
|
+
* age$.next(25);
|
|
46
|
+
*
|
|
47
|
+
* name$.next('Bob'); // logs: Bob is 25 years old
|
|
48
|
+
*
|
|
49
|
+
* assert.deepStrictEqual(mut_history, [['Bob', 25]]);
|
|
50
|
+
*
|
|
51
|
+
* age$.next(30);
|
|
52
|
+
*
|
|
53
|
+
* name$.next('Charlie'); // logs: Charlie is 30 years old
|
|
54
|
+
*
|
|
55
|
+
* assert.deepStrictEqual(mut_history, [
|
|
56
|
+
* ['Bob', 25],
|
|
57
|
+
* ['Charlie', 30],
|
|
58
|
+
* ]);
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
6
61
|
const withCurrentValueFrom = (observable) => (parentObservable) => new WithCurrentValueFromObservableClass(parentObservable, observable);
|
|
7
|
-
|
|
62
|
+
/**
|
|
63
|
+
* Alias for `withCurrentValueFrom`.
|
|
64
|
+
* @see withCurrentValueFrom
|
|
65
|
+
*/
|
|
66
|
+
const withLatestFrom = withCurrentValueFrom;
|
|
8
67
|
class WithCurrentValueFromObservableClass extends SyncChildObservableClass {
|
|
9
68
|
#observable;
|
|
10
69
|
constructor(parentObservable, observable) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"with-current-value-from.mjs","sources":["../../../src/core/operators/with-current-value-from.mts"],"sourcesContent":[null],"names":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"with-current-value-from.mjs","sources":["../../../src/core/operators/with-current-value-from.mts"],"sourcesContent":[null],"names":[],"mappings":";;;;;AAUA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsDG;MACU,oBAAoB,GAC/B,CACE,UAAyB,KAE3B,CAAC,gBAAgB,KACf,IAAI,mCAAmC,CAAC,gBAAgB,EAAE,UAAU;AAExE;;;AAGG;AACI,MAAM,cAAc,GAAG;AAE9B,MAAM,mCACJ,SAAQ,wBAAuD,CAAA;AAGtD,IAAA,WAAW;IAEpB,WAAA,CAAY,gBAA+B,EAAE,UAAyB,EAAA;AACpE,QAAA,KAAK,CAAC;YACJ,OAAO,EAAE,CAAC,gBAAgB,CAAC;YAC3B,KAAK,EAAE,CAAC,GAAG,QAAQ,CAAC,CAAC,gBAAgB,EAAE,UAAU,CAAC,CAAC;YACnD,YAAY,EAAE,IAAI,CAAC;AACjB,gBAAA,GAAG,EAAE,gBAAgB,CAAC,WAAW,EAAE;AACnC,gBAAA,EAAE,EAAE,UAAU,CAAC,WAAW,EAAE;aAC7B,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,GAAG,EAAE,KACjB,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,QAAQ,CAAC,MAAM,CAAC,EAAE;kBACtC,QAAQ,CAAC;AACX,kBAAE,QAAQ,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAU,CAAC,CAClD,CAAC,KAAK;AACR,SAAA,CAAC;AAEF,QAAA,IAAI,CAAC,WAAW,GAAG,UAAU;IAC/B;AAES,IAAA,SAAS,CAAC,aAA4B,EAAA;QAC7C,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;AAE3B,QAAA,MAAM,EAAE,GAAG,GAAG,CAAC,WAAW,EAAE;AAE5B,QAAA,IAAI,GAAG,CAAC,aAAa,KAAK,aAAa,IAAI,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE;AAC9D,YAAA,OAAO;QACT;QAEA,MAAM,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,WAAW,EAAE;AAE3C,QAAA,IAAI,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC;AAAE,YAAA,OAAO;AAElC,QAAA,IAAI,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,EAAE,aAAa,CAAC;IACrD;AACD;;;;"}
|
|
@@ -11,15 +11,37 @@ import { type WithInitialValueOperator } from '../types/index.mjs';
|
|
|
11
11
|
*
|
|
12
12
|
* @example
|
|
13
13
|
* ```ts
|
|
14
|
+
* // Timeline:
|
|
15
|
+
* //
|
|
16
|
+
* // num$ 1 2 3
|
|
17
|
+
* // withInitial$ 0 1 2 3
|
|
18
|
+
* // ^
|
|
19
|
+
* // initial value
|
|
20
|
+
* //
|
|
21
|
+
* // Explanation:
|
|
22
|
+
* // - withInitialValue provides an initial value before the source emits
|
|
23
|
+
* // - Converts an uninitialized observable to an initialized one
|
|
24
|
+
* // - Useful when you need a default value immediately
|
|
25
|
+
*
|
|
14
26
|
* const num$ = source<number>();
|
|
15
27
|
*
|
|
16
28
|
* const initialized$ = num$.pipe(withInitialValue(0));
|
|
17
29
|
*
|
|
30
|
+
* const mut_history: number[] = [];
|
|
31
|
+
*
|
|
18
32
|
* initialized$.subscribe((x) => {
|
|
19
|
-
*
|
|
20
|
-
* });
|
|
33
|
+
* mut_history.push(x);
|
|
34
|
+
* });
|
|
35
|
+
*
|
|
36
|
+
* assert.deepStrictEqual(mut_history, [0]);
|
|
21
37
|
*
|
|
22
38
|
* num$.next(1); // logs: 1
|
|
39
|
+
*
|
|
40
|
+
* assert.deepStrictEqual(mut_history, [0, 1]);
|
|
41
|
+
*
|
|
42
|
+
* num$.next(2); // logs: 2
|
|
43
|
+
*
|
|
44
|
+
* assert.deepStrictEqual(mut_history, [0, 1, 2]);
|
|
23
45
|
* ```
|
|
24
46
|
*/
|
|
25
47
|
export declare const withInitialValue: <A, I = A>(initialValue: I) => WithInitialValueOperator<A, A | I>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"with-initial-value.d.mts","sourceRoot":"","sources":["../../../src/core/operators/with-initial-value.mts"],"names":[],"mappings":"AAGA,OAAO,EAIL,KAAK,wBAAwB,EAE9B,MAAM,oBAAoB,CAAC;AAE5B
|
|
1
|
+
{"version":3,"file":"with-initial-value.d.mts","sourceRoot":"","sources":["../../../src/core/operators/with-initial-value.mts"],"names":[],"mappings":"AAGA,OAAO,EAIL,KAAK,wBAAwB,EAE9B,MAAM,oBAAoB,CAAC;AAE5B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AACH,eAAO,MAAM,gBAAgB,GAC1B,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,cAAc,CAAC,KAAG,wBAAwB,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAEO,CAAC"}
|
|
@@ -14,15 +14,37 @@ import '../utils/id-maker.mjs';
|
|
|
14
14
|
*
|
|
15
15
|
* @example
|
|
16
16
|
* ```ts
|
|
17
|
+
* // Timeline:
|
|
18
|
+
* //
|
|
19
|
+
* // num$ 1 2 3
|
|
20
|
+
* // withInitial$ 0 1 2 3
|
|
21
|
+
* // ^
|
|
22
|
+
* // initial value
|
|
23
|
+
* //
|
|
24
|
+
* // Explanation:
|
|
25
|
+
* // - withInitialValue provides an initial value before the source emits
|
|
26
|
+
* // - Converts an uninitialized observable to an initialized one
|
|
27
|
+
* // - Useful when you need a default value immediately
|
|
28
|
+
*
|
|
17
29
|
* const num$ = source<number>();
|
|
18
30
|
*
|
|
19
31
|
* const initialized$ = num$.pipe(withInitialValue(0));
|
|
20
32
|
*
|
|
33
|
+
* const mut_history: number[] = [];
|
|
34
|
+
*
|
|
21
35
|
* initialized$.subscribe((x) => {
|
|
22
|
-
*
|
|
23
|
-
* });
|
|
36
|
+
* mut_history.push(x);
|
|
37
|
+
* });
|
|
38
|
+
*
|
|
39
|
+
* assert.deepStrictEqual(mut_history, [0]);
|
|
24
40
|
*
|
|
25
41
|
* num$.next(1); // logs: 1
|
|
42
|
+
*
|
|
43
|
+
* assert.deepStrictEqual(mut_history, [0, 1]);
|
|
44
|
+
*
|
|
45
|
+
* num$.next(2); // logs: 2
|
|
46
|
+
*
|
|
47
|
+
* assert.deepStrictEqual(mut_history, [0, 1, 2]);
|
|
26
48
|
* ```
|
|
27
49
|
*/
|
|
28
50
|
const withInitialValue = (initialValue) => (parentObservable) => new WithInitialValueObservableClass(parentObservable, initialValue);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"with-initial-value.mjs","sources":["../../../src/core/operators/with-initial-value.mts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAWA
|
|
1
|
+
{"version":3,"file":"with-initial-value.mjs","sources":["../../../src/core/operators/with-initial-value.mts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAWA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4CG;AACI,MAAM,gBAAgB,GAC3B,CAAW,YAAe,KAC1B,CAAC,gBAAgB,KACf,IAAI,+BAA+B,CAAC,gBAAgB,EAAE,YAAY;AAEtE,MAAM,+BACJ,SAAQ,mCAAwD,CAAA;IAGhE,WAAA,CAAY,gBAA+B,EAAE,YAAe,EAAA;AAC1D,QAAA,KAAK,CAAC;YACJ,OAAO,EAAE,CAAC,gBAAgB,CAAC;AAC3B,YAAA,YAAY,EAAE,QAAQ,CAAC,IAAI,CAAC,YAAY,CAAC;AAC1C,SAAA,CAAC;;AAGK,IAAA,SAAS,CAAC,aAA4B,EAAA;QAC7C,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;AAE3B,QAAA,MAAM,EAAE,GAAG,GAAG,CAAC,WAAW,EAAE;AAE5B,QAAA,IAAI,GAAG,CAAC,aAAa,KAAK,aAAa,IAAI,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE;AAC9D,YAAA,OAAO;;QAGT,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,aAAa,CAAC;;AAExC;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../../src/core/predefined/index.mts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC"}
|