synstate 0.1.1 → 1.0.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/README.md +317 -298
- package/dist/core/class/child-observable-class.d.mts.map +1 -1
- package/dist/core/class/child-observable-class.mjs +43 -10
- package/dist/core/class/child-observable-class.mjs.map +1 -1
- package/dist/core/class/observable-base-class.d.mts +4 -4
- package/dist/core/class/observable-base-class.d.mts.map +1 -1
- package/dist/core/class/observable-base-class.mjs +8 -8
- package/dist/core/class/observable-base-class.mjs.map +1 -1
- package/dist/core/class/root-observable-class.d.mts +1 -1
- package/dist/core/class/root-observable-class.d.mts.map +1 -1
- package/dist/core/class/root-observable-class.mjs +9 -9
- package/dist/core/class/root-observable-class.mjs.map +1 -1
- package/dist/core/combine/combine.d.mts +7 -7
- package/dist/core/combine/combine.mjs +13 -14
- package/dist/core/combine/combine.mjs.map +1 -1
- package/dist/core/combine/merge.d.mts +6 -6
- package/dist/core/combine/merge.mjs +9 -9
- package/dist/core/combine/merge.mjs.map +1 -1
- package/dist/core/combine/zip.d.mts +20 -19
- package/dist/core/combine/zip.d.mts.map +1 -1
- package/dist/core/combine/zip.mjs +22 -21
- package/dist/core/combine/zip.mjs.map +1 -1
- package/dist/core/create/{interval.d.mts → counter.d.mts} +14 -12
- package/dist/core/create/counter.d.mts.map +1 -0
- package/dist/core/create/{interval.mjs → counter.mjs} +21 -23
- package/dist/core/create/counter.mjs.map +1 -0
- package/dist/core/create/from-abortable-promise.d.mts +29 -0
- package/dist/core/create/from-abortable-promise.d.mts.map +1 -0
- package/dist/core/create/from-abortable-promise.mjs +70 -0
- package/dist/core/create/from-abortable-promise.mjs.map +1 -0
- package/dist/core/create/from-promise.d.mts +9 -6
- package/dist/core/create/from-promise.d.mts.map +1 -1
- package/dist/core/create/from-promise.mjs +8 -5
- package/dist/core/create/from-promise.mjs.map +1 -1
- package/dist/core/create/from-subscribable.d.mts +4 -4
- package/dist/core/create/from-subscribable.mjs +4 -4
- package/dist/core/create/index.d.mts +3 -3
- package/dist/core/create/index.d.mts.map +1 -1
- package/dist/core/create/index.mjs +4 -4
- package/dist/core/create/just.d.mts +32 -0
- package/dist/core/create/just.d.mts.map +1 -0
- package/dist/core/create/just.mjs +44 -0
- package/dist/core/create/just.mjs.map +1 -0
- package/dist/core/create/source.d.mts +7 -12
- package/dist/core/create/source.d.mts.map +1 -1
- package/dist/core/create/source.mjs +1 -6
- package/dist/core/create/source.mjs.map +1 -1
- package/dist/core/create/timer.d.mts +6 -4
- package/dist/core/create/timer.d.mts.map +1 -1
- package/dist/core/create/timer.mjs +6 -7
- package/dist/core/create/timer.mjs.map +1 -1
- package/dist/core/index.d.mts +1 -1
- package/dist/core/index.d.mts.map +1 -1
- package/dist/core/index.mjs +21 -14
- package/dist/core/index.mjs.map +1 -1
- package/dist/core/operators/audit.d.mts +97 -0
- package/dist/core/operators/audit.d.mts.map +1 -0
- package/dist/core/operators/audit.mjs +144 -0
- package/dist/core/operators/audit.mjs.map +1 -0
- package/dist/core/operators/debounce.d.mts +88 -0
- package/dist/core/operators/debounce.d.mts.map +1 -0
- package/dist/core/operators/debounce.mjs +130 -0
- package/dist/core/operators/debounce.mjs.map +1 -0
- package/dist/core/operators/filter.d.mts +5 -5
- package/dist/core/operators/filter.mjs +3 -3
- package/dist/core/operators/filter.mjs.map +1 -1
- package/dist/core/operators/index.d.mts +4 -4
- package/dist/core/operators/index.d.mts.map +1 -1
- package/dist/core/operators/index.mjs +6 -6
- package/dist/core/operators/map.d.mts +41 -0
- package/dist/core/operators/map.d.mts.map +1 -0
- package/dist/core/operators/map.mjs +71 -0
- package/dist/core/operators/map.mjs.map +1 -0
- package/dist/core/operators/merge-map.d.mts +57 -30
- package/dist/core/operators/merge-map.d.mts.map +1 -1
- package/dist/core/operators/merge-map.mjs +59 -32
- package/dist/core/operators/merge-map.mjs.map +1 -1
- package/dist/core/operators/pairwise.d.mts +6 -6
- package/dist/core/operators/pairwise.mjs +9 -9
- package/dist/core/operators/pairwise.mjs.map +1 -1
- package/dist/core/operators/scan.d.mts +6 -6
- package/dist/core/operators/scan.mjs +9 -9
- package/dist/core/operators/scan.mjs.map +1 -1
- package/dist/core/operators/skip-if-no-change.d.mts +21 -9
- package/dist/core/operators/skip-if-no-change.d.mts.map +1 -1
- package/dist/core/operators/skip-if-no-change.mjs +25 -13
- package/dist/core/operators/skip-if-no-change.mjs.map +1 -1
- package/dist/core/operators/skip-until.d.mts +5 -5
- package/dist/core/operators/skip-until.mjs +8 -8
- package/dist/core/operators/skip-until.mjs.map +1 -1
- package/dist/core/operators/skip-while.d.mts +18 -9
- package/dist/core/operators/skip-while.d.mts.map +1 -1
- package/dist/core/operators/skip-while.mjs +28 -16
- package/dist/core/operators/skip-while.mjs.map +1 -1
- package/dist/core/operators/switch-map.d.mts +57 -26
- package/dist/core/operators/switch-map.d.mts.map +1 -1
- package/dist/core/operators/switch-map.mjs +59 -28
- package/dist/core/operators/switch-map.mjs.map +1 -1
- package/dist/core/operators/take-until.d.mts +5 -5
- package/dist/core/operators/take-until.mjs +8 -8
- package/dist/core/operators/take-until.mjs.map +1 -1
- package/dist/core/operators/take-while.d.mts +15 -8
- package/dist/core/operators/take-while.d.mts.map +1 -1
- package/dist/core/operators/take-while.mjs +19 -13
- package/dist/core/operators/take-while.mjs.map +1 -1
- package/dist/core/operators/throttle.d.mts +81 -0
- package/dist/core/operators/throttle.d.mts.map +1 -0
- package/dist/core/operators/throttle.mjs +126 -0
- package/dist/core/operators/throttle.mjs.map +1 -0
- package/dist/core/operators/with-buffered-from.d.mts +13 -9
- package/dist/core/operators/with-buffered-from.d.mts.map +1 -1
- package/dist/core/operators/with-buffered-from.mjs +17 -13
- package/dist/core/operators/with-buffered-from.mjs.map +1 -1
- package/dist/core/operators/with-current-value-from.d.mts +14 -9
- package/dist/core/operators/with-current-value-from.d.mts.map +1 -1
- package/dist/core/operators/with-current-value-from.mjs +18 -13
- package/dist/core/operators/with-current-value-from.mjs.map +1 -1
- package/dist/core/operators/with-initial-value.d.mts +5 -5
- package/dist/core/operators/with-initial-value.mjs +8 -8
- 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 +12 -0
- package/dist/core/predefined/index.mjs.map +1 -0
- package/dist/core/predefined/operators/attach-index.d.mts +57 -0
- package/dist/core/predefined/operators/attach-index.d.mts.map +1 -0
- package/dist/core/predefined/operators/attach-index.mjs +62 -0
- package/dist/core/predefined/operators/attach-index.mjs.map +1 -0
- package/dist/core/predefined/operators/index.d.mts +12 -0
- package/dist/core/predefined/operators/index.d.mts.map +1 -0
- package/dist/core/predefined/operators/index.mjs +12 -0
- package/dist/core/predefined/operators/index.mjs.map +1 -0
- package/dist/core/predefined/operators/map-optional.d.mts +51 -0
- package/dist/core/predefined/operators/map-optional.d.mts.map +1 -0
- package/dist/core/predefined/operators/map-optional.mjs +55 -0
- package/dist/core/predefined/operators/map-optional.mjs.map +1 -0
- package/dist/core/predefined/operators/map-result-err.d.mts +51 -0
- package/dist/core/predefined/operators/map-result-err.d.mts.map +1 -0
- package/dist/core/predefined/operators/map-result-err.mjs +55 -0
- package/dist/core/predefined/operators/map-result-err.mjs.map +1 -0
- package/dist/core/predefined/operators/map-result-ok.d.mts +51 -0
- package/dist/core/predefined/operators/map-result-ok.d.mts.map +1 -0
- package/dist/core/predefined/operators/map-result-ok.mjs +55 -0
- package/dist/core/predefined/operators/map-result-ok.mjs.map +1 -0
- package/dist/core/predefined/operators/map-to.d.mts +43 -0
- package/dist/core/predefined/operators/map-to.d.mts.map +1 -0
- package/dist/core/predefined/operators/map-to.mjs +48 -0
- package/dist/core/predefined/operators/map-to.mjs.map +1 -0
- package/dist/core/predefined/operators/pluck.d.mts +47 -0
- package/dist/core/predefined/operators/pluck.d.mts.map +1 -0
- package/dist/core/predefined/operators/pluck.mjs +52 -0
- package/dist/core/predefined/operators/pluck.mjs.map +1 -0
- package/dist/core/predefined/operators/skip.d.mts +50 -0
- package/dist/core/predefined/operators/skip.d.mts.map +1 -0
- package/dist/core/predefined/operators/skip.mjs +56 -0
- package/dist/core/predefined/operators/skip.mjs.map +1 -0
- package/dist/core/predefined/operators/take.d.mts +44 -0
- package/dist/core/predefined/operators/take.d.mts.map +1 -0
- package/dist/core/predefined/operators/take.mjs +49 -0
- package/dist/core/predefined/operators/take.mjs.map +1 -0
- package/dist/core/predefined/operators/unwrap-optional.d.mts +44 -0
- package/dist/core/predefined/operators/unwrap-optional.d.mts.map +1 -0
- package/dist/core/predefined/operators/unwrap-optional.mjs +50 -0
- package/dist/core/predefined/operators/unwrap-optional.mjs.map +1 -0
- package/dist/core/predefined/operators/unwrap-result-err.d.mts +44 -0
- package/dist/core/predefined/operators/unwrap-result-err.d.mts.map +1 -0
- package/dist/core/predefined/operators/unwrap-result-err.mjs +48 -0
- package/dist/core/predefined/operators/unwrap-result-err.mjs.map +1 -0
- package/dist/core/predefined/operators/unwrap-result-ok.d.mts +44 -0
- package/dist/core/predefined/operators/unwrap-result-ok.d.mts.map +1 -0
- package/dist/core/predefined/operators/unwrap-result-ok.mjs +50 -0
- package/dist/core/predefined/operators/unwrap-result-ok.mjs.map +1 -0
- package/dist/core/types/id.d.mts +1 -1
- package/dist/core/types/id.d.mts.map +1 -1
- package/dist/core/types/index.d.mts +1 -0
- package/dist/core/types/index.d.mts.map +1 -1
- package/dist/core/types/observable-family.d.mts +8 -14
- package/dist/core/types/observable-family.d.mts.map +1 -1
- package/dist/core/types/observable.d.mts +3 -3
- package/dist/core/types/observable.d.mts.map +1 -1
- package/dist/core/types/timer.d.mts +2 -0
- package/dist/core/types/timer.d.mts.map +1 -0
- package/dist/core/types/timer.mjs +2 -0
- package/dist/core/types/timer.mjs.map +1 -0
- package/dist/core/utils/id-maker.d.mts +2 -2
- package/dist/core/utils/id-maker.d.mts.map +1 -1
- package/dist/core/utils/id-maker.mjs +3 -3
- package/dist/core/utils/id-maker.mjs.map +1 -1
- package/dist/core/utils/index.mjs +1 -1
- package/dist/entry-point.mjs +24 -15
- package/dist/entry-point.mjs.map +1 -1
- package/dist/globals.d.mts +0 -3
- package/dist/index.mjs +24 -15
- package/dist/index.mjs.map +1 -1
- package/dist/utils/collect-to-array.d.mts +3 -0
- package/dist/utils/collect-to-array.d.mts.map +1 -0
- package/dist/utils/collect-to-array.mjs +11 -0
- package/dist/utils/collect-to-array.mjs.map +1 -0
- package/dist/utils/create-boolean-state.d.mts +40 -0
- package/dist/utils/create-boolean-state.d.mts.map +1 -0
- package/dist/utils/create-boolean-state.mjs +53 -0
- package/dist/utils/create-boolean-state.mjs.map +1 -0
- package/dist/utils/create-event-emitter.d.mts +4 -4
- package/dist/utils/create-event-emitter.mjs +4 -4
- package/dist/utils/create-reducer.d.mts +10 -7
- package/dist/utils/create-reducer.d.mts.map +1 -1
- package/dist/utils/create-reducer.mjs +7 -7
- package/dist/utils/create-reducer.mjs.map +1 -1
- package/dist/utils/create-state.d.mts +8 -48
- package/dist/utils/create-state.d.mts.map +1 -1
- package/dist/utils/create-state.mjs +10 -60
- package/dist/utils/create-state.mjs.map +1 -1
- package/dist/utils/index.d.mts +2 -0
- package/dist/utils/index.d.mts.map +1 -1
- package/dist/utils/index.mjs +3 -1
- package/dist/utils/index.mjs.map +1 -1
- package/package.json +17 -11
- package/src/core/class/child-observable-class.mts +65 -9
- package/src/core/class/circular-dependency-comparison.test.mts +142 -0
- package/src/core/class/circular-dependency.test.mts +251 -0
- package/src/core/class/observable-base-class.mts +9 -9
- package/src/core/class/root-observable-class.mts +14 -10
- package/src/core/combine/combine.mts +15 -15
- package/src/core/combine/merge.mts +13 -14
- package/src/core/combine/zip.mts +26 -25
- package/src/core/create/{interval.mts → counter.mts} +32 -30
- package/src/core/create/from-abortable-promise.mts +83 -0
- package/src/core/create/from-promise.mts +10 -7
- package/src/core/create/from-subscribable.mts +4 -4
- package/src/core/create/index.mts +3 -3
- package/src/core/create/just.mts +43 -0
- package/src/core/create/source.mts +10 -14
- package/src/core/create/timer.mts +12 -11
- package/src/core/index.mts +1 -1
- package/src/core/operators/audit.mts +172 -0
- package/src/core/operators/debounce.mts +154 -0
- package/src/core/operators/filter.mts +9 -9
- package/src/core/operators/index.mts +4 -4
- package/src/core/operators/map.mts +124 -0
- package/src/core/operators/merge-map.mts +60 -33
- package/src/core/operators/pairwise.mts +10 -10
- package/src/core/operators/scan.mts +10 -10
- package/src/core/operators/skip-if-no-change.mts +26 -14
- package/src/core/operators/skip-until.mts +9 -9
- package/src/core/operators/skip-while.mts +30 -28
- package/src/core/operators/switch-map.mts +60 -29
- package/src/core/operators/take-until.mts +9 -9
- package/src/core/operators/take-while.mts +21 -19
- package/src/core/operators/{throttle-time.mts → throttle.mts} +58 -38
- package/src/core/operators/with-buffered-from.mts +18 -14
- package/src/core/operators/with-current-value-from.mts +19 -14
- package/src/core/operators/with-initial-value.mts +9 -9
- package/src/core/predefined/index.mts +1 -0
- package/src/core/predefined/operators/attach-index.mts +62 -0
- package/src/core/predefined/operators/index.mts +11 -0
- package/src/core/predefined/operators/map-optional.mts +55 -0
- package/src/core/predefined/operators/map-result-err.mts +55 -0
- package/src/core/predefined/operators/map-result-ok.mts +55 -0
- package/src/core/predefined/operators/map-to.mts +45 -0
- package/src/core/predefined/operators/pluck.mts +51 -0
- package/src/core/predefined/operators/skip.mts +57 -0
- package/src/core/predefined/operators/take.mts +47 -0
- package/src/core/predefined/operators/unwrap-optional.mts +49 -0
- package/src/core/predefined/operators/unwrap-result-err.mts +48 -0
- package/src/core/predefined/operators/unwrap-result-ok.mts +49 -0
- package/src/core/types/id.mts +1 -1
- package/src/core/types/index.mts +1 -0
- package/src/core/types/observable-family.mts +8 -24
- package/src/core/types/observable.mts +3 -3
- package/src/core/types/timer.mts +2 -0
- package/src/core/utils/id-maker.mts +4 -4
- package/src/globals.d.mts +0 -3
- package/src/utils/collect-to-array.mts +17 -0
- package/src/utils/create-boolean-state.mts +68 -0
- package/src/utils/create-event-emitter.mts +4 -4
- package/src/utils/create-reducer.mts +11 -8
- package/src/utils/create-state.mts +10 -75
- package/src/utils/index.mts +2 -0
- package/dist/core/create/from-array.d.mts +0 -39
- package/dist/core/create/from-array.d.mts.map +0 -1
- package/dist/core/create/from-array.mjs +0 -65
- package/dist/core/create/from-array.mjs.map +0 -1
- package/dist/core/create/interval.d.mts.map +0 -1
- package/dist/core/create/interval.mjs.map +0 -1
- package/dist/core/create/of.d.mts +0 -39
- package/dist/core/create/of.d.mts.map +0 -1
- package/dist/core/create/of.mjs +0 -63
- package/dist/core/create/of.mjs.map +0 -1
- package/dist/core/operators/audit-time.d.mts +0 -62
- package/dist/core/operators/audit-time.d.mts.map +0 -1
- package/dist/core/operators/audit-time.mjs +0 -109
- package/dist/core/operators/audit-time.mjs.map +0 -1
- package/dist/core/operators/debounce-time.d.mts +0 -51
- package/dist/core/operators/debounce-time.d.mts.map +0 -1
- package/dist/core/operators/debounce-time.mjs +0 -93
- package/dist/core/operators/debounce-time.mjs.map +0 -1
- package/dist/core/operators/map-with-index.d.mts +0 -54
- package/dist/core/operators/map-with-index.d.mts.map +0 -1
- package/dist/core/operators/map-with-index.mjs +0 -88
- package/dist/core/operators/map-with-index.mjs.map +0 -1
- package/dist/core/operators/throttle-time.d.mts +0 -62
- package/dist/core/operators/throttle-time.d.mts.map +0 -1
- package/dist/core/operators/throttle-time.mjs +0 -107
- package/dist/core/operators/throttle-time.mjs.map +0 -1
- package/src/core/create/from-array.mts +0 -76
- package/src/core/create/of.mts +0 -73
- package/src/core/operators/audit-time.mts +0 -136
- package/src/core/operators/debounce-time.mts +0 -116
- package/src/core/operators/map-with-index.mts +0 -183
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { Optional } from 'ts-data-forge';
|
|
2
|
+
import { AsyncChildObservableClass } from '../class/child-observable-class.mjs';
|
|
3
|
+
import '../utils/id-maker.mjs';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Delays emissions from the source observable until a specified time has passed without another emission.
|
|
7
|
+
* Useful for handling user input events like typing or scrolling.
|
|
8
|
+
*
|
|
9
|
+
* @template A - The type of values from the source
|
|
10
|
+
* @param milliSeconds - The debounce duration in milliseconds
|
|
11
|
+
* @returns An operator that debounces the observable
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* // Timeline (250ms debounce):
|
|
16
|
+
* //
|
|
17
|
+
* // Time(x50ms) 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0
|
|
18
|
+
* //
|
|
19
|
+
* // input$ 0 2 3 9 10 11 12 13 14
|
|
20
|
+
* // |- 250ms -> |- 250ms ->
|
|
21
|
+
* // debounced$ 3 14 (emitted after 250ms silence)
|
|
22
|
+
* //
|
|
23
|
+
* // Explanation:
|
|
24
|
+
* // - debounce emits the latest value AFTER a quiet period with no new emissions
|
|
25
|
+
* // - Unlike audit (which uses a fixed window), debounce resets the timer on every emission
|
|
26
|
+
* // - Useful for search-as-you-type and form validation
|
|
27
|
+
*
|
|
28
|
+
* const input$ = source<number>();
|
|
29
|
+
*
|
|
30
|
+
* const debounced$ = input$.pipe(debounce(250));
|
|
31
|
+
*
|
|
32
|
+
* const valueHistory: number[] = [];
|
|
33
|
+
*
|
|
34
|
+
* debounced$.subscribe((value) => {
|
|
35
|
+
* valueHistory.push(value);
|
|
36
|
+
* });
|
|
37
|
+
*
|
|
38
|
+
* const sleep = (ms: number): Promise<void> =>
|
|
39
|
+
* new Promise((resolve) => {
|
|
40
|
+
* setTimeout(resolve, ms);
|
|
41
|
+
* });
|
|
42
|
+
*
|
|
43
|
+
* input$.next(0);
|
|
44
|
+
*
|
|
45
|
+
* await sleep(200);
|
|
46
|
+
*
|
|
47
|
+
* input$.next(2);
|
|
48
|
+
*
|
|
49
|
+
* await sleep(100);
|
|
50
|
+
*
|
|
51
|
+
* input$.next(3);
|
|
52
|
+
*
|
|
53
|
+
* assert.deepStrictEqual(valueHistory, []);
|
|
54
|
+
*
|
|
55
|
+
* await sleep(300);
|
|
56
|
+
*
|
|
57
|
+
* assert.deepStrictEqual(valueHistory, [3]);
|
|
58
|
+
*
|
|
59
|
+
* await sleep(300);
|
|
60
|
+
*
|
|
61
|
+
* input$.next(9);
|
|
62
|
+
*
|
|
63
|
+
* await sleep(100);
|
|
64
|
+
*
|
|
65
|
+
* input$.next(10);
|
|
66
|
+
*
|
|
67
|
+
* await sleep(100);
|
|
68
|
+
*
|
|
69
|
+
* input$.next(11);
|
|
70
|
+
*
|
|
71
|
+
* await sleep(100);
|
|
72
|
+
*
|
|
73
|
+
* input$.next(12);
|
|
74
|
+
*
|
|
75
|
+
* await sleep(100);
|
|
76
|
+
*
|
|
77
|
+
* input$.next(13);
|
|
78
|
+
*
|
|
79
|
+
* await sleep(100);
|
|
80
|
+
*
|
|
81
|
+
* input$.next(14);
|
|
82
|
+
*
|
|
83
|
+
* assert.deepStrictEqual(valueHistory, [3]);
|
|
84
|
+
*
|
|
85
|
+
* await sleep(300);
|
|
86
|
+
*
|
|
87
|
+
* assert.deepStrictEqual(valueHistory, [3, 14]);
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
const debounce = (milliSeconds) =>
|
|
91
|
+
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
92
|
+
((parentObservable) => new DebounceObservableClass(parentObservable, milliSeconds));
|
|
93
|
+
class DebounceObservableClass extends AsyncChildObservableClass {
|
|
94
|
+
#milliSeconds;
|
|
95
|
+
#mut_timerId;
|
|
96
|
+
constructor(parentObservable, milliSeconds) {
|
|
97
|
+
super({
|
|
98
|
+
parents: [parentObservable],
|
|
99
|
+
initialValue: parentObservable.getSnapshot(),
|
|
100
|
+
});
|
|
101
|
+
this.#mut_timerId = undefined;
|
|
102
|
+
this.#milliSeconds = milliSeconds;
|
|
103
|
+
}
|
|
104
|
+
tryUpdate(updateToken) {
|
|
105
|
+
const par = this.parents[0];
|
|
106
|
+
const sn = par.getSnapshot();
|
|
107
|
+
if (par.updateToken !== updateToken || Optional.isNone(sn)) {
|
|
108
|
+
return; // skip update
|
|
109
|
+
}
|
|
110
|
+
this.#resetTimer();
|
|
111
|
+
// set timer
|
|
112
|
+
this.#mut_timerId = setTimeout(() => {
|
|
113
|
+
if (Optional.isNone(sn))
|
|
114
|
+
return;
|
|
115
|
+
this.startUpdate(sn.value);
|
|
116
|
+
}, this.#milliSeconds);
|
|
117
|
+
}
|
|
118
|
+
#resetTimer() {
|
|
119
|
+
if (this.#mut_timerId !== undefined) {
|
|
120
|
+
clearTimeout(this.#mut_timerId);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
complete() {
|
|
124
|
+
this.#resetTimer();
|
|
125
|
+
super.complete();
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export { debounce };
|
|
130
|
+
//# sourceMappingURL=debounce.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"debounce.mjs","sources":["../../../src/core/operators/debounce.mts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAUA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoFG;AACI,MAAM,QAAQ,GAAG,CACtB,YAAoB;AAEpB;AACA,CAAC,CAAC,gBAAgB,KAChB,IAAI,uBAAuB,CACzB,gBAAgB,EAChB,YAAY,CACb;AAEL,MAAM,uBACJ,SAAQ,yBAA0C,CAAA;AAGzC,IAAA,aAAa;AACtB,IAAA,YAAY;IAEZ,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,aAAa,GAAG,YAAY;IACnC;AAES,IAAA,SAAS,CAAC,WAAwB,EAAA;QACzC,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;AAE3B,QAAA,MAAM,EAAE,GAAG,GAAG,CAAC,WAAW,EAAE;AAE5B,QAAA,IAAI,GAAG,CAAC,WAAW,KAAK,WAAW,IAAI,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE;AAC1D,YAAA,OAAO;QACT;QAEA,IAAI,CAAC,WAAW,EAAE;;AAGlB,QAAA,IAAI,CAAC,YAAY,GAAG,UAAU,CAAC,MAAK;AAClC,YAAA,IAAI,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;gBAAE;AAEzB,YAAA,IAAI,CAAC,WAAW,CAAC,EAAE,CAAC,KAAK,CAAC;AAC5B,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;;;;"}
|
|
@@ -23,29 +23,29 @@ import { type DropInitialValueOperator } from '../types/index.mjs';
|
|
|
23
23
|
*
|
|
24
24
|
* const even$ = num$.pipe(filter((x) => x % 2 === 0));
|
|
25
25
|
*
|
|
26
|
-
* const
|
|
26
|
+
* const valueHistory: number[] = [];
|
|
27
27
|
*
|
|
28
28
|
* even$.subscribe((x) => {
|
|
29
|
-
*
|
|
29
|
+
* valueHistory.push(x);
|
|
30
30
|
* });
|
|
31
31
|
*
|
|
32
32
|
* num$.next(1); // nothing logged
|
|
33
33
|
*
|
|
34
34
|
* num$.next(2); // logs: 2
|
|
35
35
|
*
|
|
36
|
-
* assert.deepStrictEqual(
|
|
36
|
+
* assert.deepStrictEqual(valueHistory, [2]);
|
|
37
37
|
*
|
|
38
38
|
* num$.next(3); // nothing logged
|
|
39
39
|
*
|
|
40
40
|
* num$.next(4); // logs: 4
|
|
41
41
|
*
|
|
42
|
-
* assert.deepStrictEqual(
|
|
42
|
+
* assert.deepStrictEqual(valueHistory, [2, 4]);
|
|
43
43
|
*
|
|
44
44
|
* num$.next(5);
|
|
45
45
|
*
|
|
46
46
|
* num$.next(6);
|
|
47
47
|
*
|
|
48
|
-
* assert.deepStrictEqual(
|
|
48
|
+
* assert.deepStrictEqual(valueHistory, [2, 4, 6]);
|
|
49
49
|
* ```
|
|
50
50
|
*/
|
|
51
51
|
export declare function filter<A, B extends A>(predicate: (value: A, index: SafeUint | -1) => value is B): DropInitialValueOperator<A, B>;
|
|
@@ -20,16 +20,16 @@ class FilterObservableClass extends SyncChildObservableClass {
|
|
|
20
20
|
this.#mut_index = -1;
|
|
21
21
|
this.#predicate = predicate;
|
|
22
22
|
}
|
|
23
|
-
tryUpdate(
|
|
23
|
+
tryUpdate(updateToken) {
|
|
24
24
|
const par = this.parents[0];
|
|
25
25
|
const sn = par.getSnapshot();
|
|
26
|
-
if (par.
|
|
26
|
+
if (par.updateToken !== updateToken || Optional.isNone(sn)) {
|
|
27
27
|
return; // skip update
|
|
28
28
|
}
|
|
29
29
|
this.#mut_index =
|
|
30
30
|
this.#mut_index === -1 ? asSafeUint(0) : SafeUint.add(1, this.#mut_index);
|
|
31
31
|
if (this.#predicate(sn.value, this.#mut_index)) {
|
|
32
|
-
this.setNext(sn.value,
|
|
32
|
+
this.setNext(sn.value, updateToken);
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"filter.mjs","sources":["../../../src/core/operators/filter.mts"],"sourcesContent":[null],"names":[],"mappings":";;;;AA2EM,SAAU,MAAM,CACpB,SAAsD,EAAA;AAEtD,IAAA,OAAO,CAAC,gBAAgB,KACtB,IAAI,qBAAqB,CAAC,gBAAgB,EAAE,SAAS,CAAC;AAC1D;AAEA,MAAM,qBACJ,SAAQ,wBAAyC,CAAA;AAGxC,IAAA,UAAU;AACnB,IAAA,UAAU;IAEV,WAAA,CACE,gBAA+B,EAC/B,SAAkD,EAAA;AAElD,QAAA,KAAK,CAAC;YACJ,OAAO,EAAE,CAAC,gBAAgB,CAAC;YAC3B,YAAY,EAAE,IAAI,CAAC,gBAAgB,CAAC,WAAW,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,KACxD,QAAQ,CAAC,MAAM,CAAC,EAAE;kBACd,QAAQ,CAAC;kBACT,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,EAAE;AACtB,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,
|
|
1
|
+
{"version":3,"file":"filter.mjs","sources":["../../../src/core/operators/filter.mts"],"sourcesContent":[null],"names":[],"mappings":";;;;AA2EM,SAAU,MAAM,CACpB,SAAsD,EAAA;AAEtD,IAAA,OAAO,CAAC,gBAAgB,KACtB,IAAI,qBAAqB,CAAC,gBAAgB,EAAE,SAAS,CAAC;AAC1D;AAEA,MAAM,qBACJ,SAAQ,wBAAyC,CAAA;AAGxC,IAAA,UAAU;AACnB,IAAA,UAAU;IAEV,WAAA,CACE,gBAA+B,EAC/B,SAAkD,EAAA;AAElD,QAAA,KAAK,CAAC;YACJ,OAAO,EAAE,CAAC,gBAAgB,CAAC;YAC3B,YAAY,EAAE,IAAI,CAAC,gBAAgB,CAAC,WAAW,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,KACxD,QAAQ,CAAC,MAAM,CAAC,EAAE;kBACd,QAAQ,CAAC;kBACT,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,EAAE;AACtB,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,WAAwB,EAAA;QACzC,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;AAE3B,QAAA,MAAM,EAAE,GAAG,GAAG,CAAC,WAAW,EAAE;AAE5B,QAAA,IAAI,GAAG,CAAC,WAAW,KAAK,WAAW,IAAI,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE;AAC1D,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,WAAW,CAAC;;;AAGxC;;;;"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export * from './audit
|
|
2
|
-
export * from './debounce
|
|
1
|
+
export * from './audit.mjs';
|
|
2
|
+
export * from './debounce.mjs';
|
|
3
3
|
export * from './filter.mjs';
|
|
4
|
-
export * from './map
|
|
4
|
+
export * from './map.mjs';
|
|
5
5
|
export * from './merge-map.mjs';
|
|
6
6
|
export * from './pairwise.mjs';
|
|
7
7
|
export * from './scan.mjs';
|
|
@@ -11,7 +11,7 @@ export * from './skip-while.mjs';
|
|
|
11
11
|
export * from './switch-map.mjs';
|
|
12
12
|
export * from './take-until.mjs';
|
|
13
13
|
export * from './take-while.mjs';
|
|
14
|
-
export * from './throttle
|
|
14
|
+
export * from './throttle.mjs';
|
|
15
15
|
export * from './with-buffered-from.mjs';
|
|
16
16
|
export * from './with-current-value-from.mjs';
|
|
17
17
|
export * from './with-initial-value.mjs';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../../src/core/operators/index.mts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../../src/core/operators/index.mts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,yBAAyB,CAAC;AACxC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,0BAA0B,CAAC;AACzC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,0BAA0B,CAAC"}
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
1
|
+
export { audit } from './audit.mjs';
|
|
2
|
+
export { debounce } from './debounce.mjs';
|
|
3
3
|
export { filter } from './filter.mjs';
|
|
4
|
-
export {
|
|
4
|
+
export { map } from './map.mjs';
|
|
5
5
|
export { flatMap, mergeMap } from './merge-map.mjs';
|
|
6
6
|
export { pairwise } from './pairwise.mjs';
|
|
7
7
|
export { scan } from './scan.mjs';
|
|
8
8
|
export { distinctUntilChanged, skipIfNoChange } from './skip-if-no-change.mjs';
|
|
9
9
|
export { skipUntil } from './skip-until.mjs';
|
|
10
|
-
export {
|
|
10
|
+
export { skipWhile } from './skip-while.mjs';
|
|
11
11
|
export { switchMap } from './switch-map.mjs';
|
|
12
12
|
export { takeUntil } from './take-until.mjs';
|
|
13
|
-
export {
|
|
14
|
-
export {
|
|
13
|
+
export { takeWhile } from './take-while.mjs';
|
|
14
|
+
export { throttle } from './throttle.mjs';
|
|
15
15
|
export { withBuffered, withBufferedFrom } from './with-buffered-from.mjs';
|
|
16
16
|
export { withCurrentValueFrom, withLatestFrom } from './with-current-value-from.mjs';
|
|
17
17
|
export { withInitialValue } from './with-initial-value.mjs';
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { type KeepInitialValueOperator } from '../types/index.mjs';
|
|
2
|
+
/**
|
|
3
|
+
* Transforms each value emitted by the source using a mapping function that also receives the emission index.
|
|
4
|
+
*
|
|
5
|
+
* @template A - The type of values from the source
|
|
6
|
+
* @template B - The type of mapped values
|
|
7
|
+
* @param mapFn - A function that maps each value (receives value and index)
|
|
8
|
+
* @returns An operator that maps values with index
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* // Timeline:
|
|
13
|
+
* //
|
|
14
|
+
* // num$ "A" "B" "C"
|
|
15
|
+
* // indexed$ "0: A" "1: B" "2: C"
|
|
16
|
+
* //
|
|
17
|
+
* // Explanation:
|
|
18
|
+
* // - mapWithIndex transforms each value along with its index
|
|
19
|
+
* // - Index starts at 0 and increments with each emission
|
|
20
|
+
*
|
|
21
|
+
* const num$ = source<string>();
|
|
22
|
+
*
|
|
23
|
+
* const indexed$ = num$.pipe(map((x, i) => `${i}: ${x}`));
|
|
24
|
+
*
|
|
25
|
+
* const valueHistory: string[] = [];
|
|
26
|
+
*
|
|
27
|
+
* indexed$.subscribe((s) => {
|
|
28
|
+
* valueHistory.push(s);
|
|
29
|
+
* });
|
|
30
|
+
*
|
|
31
|
+
* num$.next('A'); // 0: A
|
|
32
|
+
*
|
|
33
|
+
* num$.next('B'); // 1: B
|
|
34
|
+
*
|
|
35
|
+
* num$.next('C'); // 2: C
|
|
36
|
+
*
|
|
37
|
+
* assert.deepStrictEqual(valueHistory, ['0: A', '1: B', '2: C']);
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export declare const map: <A, B>(mapFn: (x: A, index: SafeUint | -1) => B) => KeepInitialValueOperator<A, B>;
|
|
41
|
+
//# sourceMappingURL=map.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"map.d.mts","sourceRoot":"","sources":["../../../src/core/operators/map.mts"],"names":[],"mappings":"AAGA,OAAO,EAEL,KAAK,wBAAwB,EAI9B,MAAM,oBAAoB,CAAC;AAG5B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,eAAO,MAAM,GAAG,GAAI,CAAC,EAAE,CAAC,EACtB,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,QAAQ,GAAG,CAAC,CAAC,KAAK,CAAC,KACvC,wBAAwB,CAAC,CAAC,EAAE,CAAC,CAMQ,CAAC"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { Optional, asSafeUint, SafeUint } from 'ts-data-forge';
|
|
2
|
+
import { SyncChildObservableClass } from '../class/child-observable-class.mjs';
|
|
3
|
+
import '../utils/id-maker.mjs';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Transforms each value emitted by the source using a mapping function that also receives the emission index.
|
|
7
|
+
*
|
|
8
|
+
* @template A - The type of values from the source
|
|
9
|
+
* @template B - The type of mapped values
|
|
10
|
+
* @param mapFn - A function that maps each value (receives value and index)
|
|
11
|
+
* @returns An operator that maps values with index
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* // Timeline:
|
|
16
|
+
* //
|
|
17
|
+
* // num$ "A" "B" "C"
|
|
18
|
+
* // indexed$ "0: A" "1: B" "2: C"
|
|
19
|
+
* //
|
|
20
|
+
* // Explanation:
|
|
21
|
+
* // - mapWithIndex transforms each value along with its index
|
|
22
|
+
* // - Index starts at 0 and increments with each emission
|
|
23
|
+
*
|
|
24
|
+
* const num$ = source<string>();
|
|
25
|
+
*
|
|
26
|
+
* const indexed$ = num$.pipe(map((x, i) => `${i}: ${x}`));
|
|
27
|
+
*
|
|
28
|
+
* const valueHistory: string[] = [];
|
|
29
|
+
*
|
|
30
|
+
* indexed$.subscribe((s) => {
|
|
31
|
+
* valueHistory.push(s);
|
|
32
|
+
* });
|
|
33
|
+
*
|
|
34
|
+
* num$.next('A'); // 0: A
|
|
35
|
+
*
|
|
36
|
+
* num$.next('B'); // 1: B
|
|
37
|
+
*
|
|
38
|
+
* num$.next('C'); // 2: C
|
|
39
|
+
*
|
|
40
|
+
* assert.deepStrictEqual(valueHistory, ['0: A', '1: B', '2: C']);
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
const map = (mapFn) =>
|
|
44
|
+
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
45
|
+
((parentObservable) => new MapObservableClass(parentObservable, mapFn));
|
|
46
|
+
/* implementation */
|
|
47
|
+
class MapObservableClass extends SyncChildObservableClass {
|
|
48
|
+
#mapFn;
|
|
49
|
+
#mut_index;
|
|
50
|
+
constructor(parentObservable, mapFn) {
|
|
51
|
+
super({
|
|
52
|
+
parents: [parentObservable],
|
|
53
|
+
initialValue: Optional.map(parentObservable.getSnapshot(), (x) => mapFn(x, -1)),
|
|
54
|
+
});
|
|
55
|
+
this.#mut_index = -1;
|
|
56
|
+
this.#mapFn = mapFn;
|
|
57
|
+
}
|
|
58
|
+
tryUpdate(updateToken) {
|
|
59
|
+
const par = this.parents[0];
|
|
60
|
+
const sn = par.getSnapshot();
|
|
61
|
+
if (par.updateToken !== updateToken || Optional.isNone(sn)) {
|
|
62
|
+
return; // skip update
|
|
63
|
+
}
|
|
64
|
+
this.#mut_index =
|
|
65
|
+
this.#mut_index === -1 ? asSafeUint(0) : SafeUint.add(1, this.#mut_index);
|
|
66
|
+
this.setNext(this.#mapFn(sn.value, this.#mut_index), updateToken);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export { map };
|
|
71
|
+
//# sourceMappingURL=map.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"map.mjs","sources":["../../../src/core/operators/map.mts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAYA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqCG;AACI,MAAM,GAAG,GAAG,CACjB,KAAwC;AAExC;AACA,CAAC,CAAC,gBAAgB,KAChB,IAAI,kBAAkB,CACpB,gBAAgB,EAChB,KAAK,CACN;AAEL;AAEA,MAAM,kBACJ,SAAQ,wBAAyC,CAAA;AAGxC,IAAA,MAAM;AACf,IAAA,UAAU;IAEV,WAAA,CACE,gBAA+B,EAC/B,KAAwC,EAAA;AAExC,QAAA,KAAK,CAAC;YACJ,OAAO,EAAE,CAAC,gBAAgB,CAAC;YAC3B,YAAY,EAAE,QAAQ,CAAC,GAAG,CAAC,gBAAgB,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC,KAC3D,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CACb;AACF,SAAA,CAAC;AAEF,QAAA,IAAI,CAAC,UAAU,GAAG,EAAE;AAEpB,QAAA,IAAI,CAAC,MAAM,GAAG,KAAK;;AAGZ,IAAA,SAAS,CAAC,WAAwB,EAAA;QACzC,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;AAE3B,QAAA,MAAM,EAAE,GAAG,GAAG,CAAC,WAAW,EAAE;AAE5B,QAAA,IAAI,GAAG,CAAC,WAAW,KAAK,WAAW,IAAI,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE;AAC1D,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,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,IAAI,CAAC,UAAU,CAAC,EAAE,WAAW,CAAC;;AAEpE;;;;"}
|
|
@@ -12,56 +12,83 @@ import { type DropInitialValueOperator, type Observable } from '../types/index.m
|
|
|
12
12
|
* ```ts
|
|
13
13
|
* // Timeline:
|
|
14
14
|
* //
|
|
15
|
-
* //
|
|
16
|
-
* //
|
|
17
|
-
* //
|
|
18
|
-
* //
|
|
15
|
+
* // input$ A B C
|
|
16
|
+
* // inner A A1 A2 A3
|
|
17
|
+
* // inner B B1 B2 B3
|
|
18
|
+
* // inner C C1 C2 C3
|
|
19
|
+
* // result$ A1 A2 A3 B1 B2 C1 B3 C2 C3
|
|
19
20
|
* //
|
|
20
21
|
* // Explanation:
|
|
21
|
-
* // - mergeMap
|
|
22
|
-
* // -
|
|
23
|
-
* // -
|
|
24
|
-
* // - All
|
|
22
|
+
* // - mergeMap creates an inner observable for each source value
|
|
23
|
+
* // - Unlike switchMap, previous inner observables are NOT cancelled
|
|
24
|
+
* // - B's inner continues even after C arrives (B3 is still emitted)
|
|
25
|
+
* // - All inner observables run concurrently and their results are merged
|
|
25
26
|
*
|
|
26
|
-
* const
|
|
27
|
+
* const input$ = source<string>();
|
|
27
28
|
*
|
|
28
|
-
* const
|
|
29
|
-
* mergeMap((
|
|
30
|
-
* const
|
|
29
|
+
* const result$ = input$.pipe(
|
|
30
|
+
* mergeMap((letter) => {
|
|
31
|
+
* const inner$ = source<string>();
|
|
31
32
|
*
|
|
32
33
|
* setTimeout(() => {
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
* result$.complete();
|
|
34
|
+
* inner$.next(`${letter}1`);
|
|
36
35
|
* }, 10);
|
|
37
36
|
*
|
|
38
|
-
*
|
|
37
|
+
* setTimeout(() => {
|
|
38
|
+
* inner$.next(`${letter}2`);
|
|
39
|
+
* }, 110);
|
|
40
|
+
*
|
|
41
|
+
* setTimeout(() => {
|
|
42
|
+
* inner$.next(`${letter}3`);
|
|
43
|
+
* }, 210);
|
|
44
|
+
*
|
|
45
|
+
* return inner$;
|
|
39
46
|
* }),
|
|
40
47
|
* );
|
|
41
48
|
*
|
|
42
|
-
* const
|
|
49
|
+
* const valueHistory: string[] = [];
|
|
43
50
|
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
51
|
+
* result$.subscribe((value) => {
|
|
52
|
+
* valueHistory.push(value);
|
|
46
53
|
* });
|
|
47
54
|
*
|
|
48
|
-
*
|
|
55
|
+
* const sleep = (ms: number): Promise<void> =>
|
|
56
|
+
* new Promise((resolve) => {
|
|
57
|
+
* setTimeout(resolve, ms);
|
|
58
|
+
* });
|
|
49
59
|
*
|
|
50
|
-
*
|
|
60
|
+
* // Emit A - inner emits A1, A2, A3 at 10ms, 110ms, 210ms
|
|
61
|
+
* input$.next('A');
|
|
51
62
|
*
|
|
52
|
-
*
|
|
63
|
+
* await sleep(250);
|
|
53
64
|
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
65
|
+
* assert.deepStrictEqual(valueHistory, ['A1', 'A2', 'A3']);
|
|
66
|
+
*
|
|
67
|
+
* // Emit B - inner starts emitting B1, B2 at 10ms, 110ms
|
|
68
|
+
* input$.next('B');
|
|
69
|
+
*
|
|
70
|
+
* await sleep(150);
|
|
57
71
|
*
|
|
58
|
-
* assert.deepStrictEqual(
|
|
72
|
+
* assert.deepStrictEqual(valueHistory, ['A1', 'A2', 'A3', 'B1', 'B2']);
|
|
59
73
|
*
|
|
60
|
-
*
|
|
74
|
+
* // Emit C while B's inner is still running (B3 at 210ms not yet fired)
|
|
75
|
+
* // Unlike switchMap, B's inner is NOT cancelled
|
|
76
|
+
* input$.next('C');
|
|
61
77
|
*
|
|
62
|
-
*
|
|
78
|
+
* await sleep(250);
|
|
63
79
|
*
|
|
64
|
-
*
|
|
80
|
+
* // B3 appears between C1 and C2, showing the merge behavior
|
|
81
|
+
* assert.deepStrictEqual(valueHistory, [
|
|
82
|
+
* 'A1',
|
|
83
|
+
* 'A2',
|
|
84
|
+
* 'A3',
|
|
85
|
+
* 'B1',
|
|
86
|
+
* 'B2',
|
|
87
|
+
* 'C1',
|
|
88
|
+
* 'B3',
|
|
89
|
+
* 'C2',
|
|
90
|
+
* 'C3',
|
|
91
|
+
* ]);
|
|
65
92
|
* ```
|
|
66
93
|
*
|
|
67
94
|
* @note To improve code readability, consider using `createState` instead of `mergeMap`,
|
|
@@ -69,7 +96,7 @@ import { type DropInitialValueOperator, type Observable } from '../types/index.m
|
|
|
69
96
|
*/
|
|
70
97
|
export declare const mergeMap: <A, B>(mapToObservable: (curr: A) => Observable<B>) => DropInitialValueOperator<A, B>;
|
|
71
98
|
/**
|
|
72
|
-
* Alias for `mergeMap
|
|
99
|
+
* Alias for `mergeMap`.
|
|
73
100
|
* @see mergeMap
|
|
74
101
|
*/
|
|
75
102
|
export declare const flatMap: <A, B>(mapToObservable: (curr: A) => Observable<B>) => DropInitialValueOperator<A, B>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"merge-map.d.mts","sourceRoot":"","sources":["../../../src/core/operators/merge-map.mts"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,wBAAwB,EAE7B,KAAK,UAAU,EAGhB,MAAM,oBAAoB,CAAC;AAE5B
|
|
1
|
+
{"version":3,"file":"merge-map.d.mts","sourceRoot":"","sources":["../../../src/core/operators/merge-map.mts"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,wBAAwB,EAE7B,KAAK,UAAU,EAGhB,MAAM,oBAAoB,CAAC;AAE5B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8FG;AACH,eAAO,MAAM,QAAQ,GAClB,CAAC,EAAE,CAAC,EACH,iBAAiB,CAAC,IAAI,EAAE,CAAC,KAAK,UAAU,CAAC,CAAC,CAAC,KAC1C,wBAAwB,CAAC,CAAC,EAAE,CAAC,CAEgC,CAAC;AAEnE;;;GAGG;AACH,eAAO,MAAM,OAAO,GAVjB,CAAC,EAAE,CAAC,mBACc,CAAC,IAAI,EAAE,CAAC,KAAK,UAAU,CAAC,CAAC,CAAC,KAC1C,wBAAwB,CAAC,CAAC,EAAE,CAAC,CAQH,CAAC"}
|
|
@@ -15,56 +15,83 @@ import '../utils/id-maker.mjs';
|
|
|
15
15
|
* ```ts
|
|
16
16
|
* // Timeline:
|
|
17
17
|
* //
|
|
18
|
-
* //
|
|
19
|
-
* //
|
|
20
|
-
* //
|
|
21
|
-
* //
|
|
18
|
+
* // input$ A B C
|
|
19
|
+
* // inner A A1 A2 A3
|
|
20
|
+
* // inner B B1 B2 B3
|
|
21
|
+
* // inner C C1 C2 C3
|
|
22
|
+
* // result$ A1 A2 A3 B1 B2 C1 B3 C2 C3
|
|
22
23
|
* //
|
|
23
24
|
* // Explanation:
|
|
24
|
-
* // - mergeMap
|
|
25
|
-
* // -
|
|
26
|
-
* // -
|
|
27
|
-
* // - All
|
|
25
|
+
* // - mergeMap creates an inner observable for each source value
|
|
26
|
+
* // - Unlike switchMap, previous inner observables are NOT cancelled
|
|
27
|
+
* // - B's inner continues even after C arrives (B3 is still emitted)
|
|
28
|
+
* // - All inner observables run concurrently and their results are merged
|
|
28
29
|
*
|
|
29
|
-
* const
|
|
30
|
+
* const input$ = source<string>();
|
|
30
31
|
*
|
|
31
|
-
* const
|
|
32
|
-
* mergeMap((
|
|
33
|
-
* const
|
|
32
|
+
* const result$ = input$.pipe(
|
|
33
|
+
* mergeMap((letter) => {
|
|
34
|
+
* const inner$ = source<string>();
|
|
34
35
|
*
|
|
35
36
|
* setTimeout(() => {
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
* result$.complete();
|
|
37
|
+
* inner$.next(`${letter}1`);
|
|
39
38
|
* }, 10);
|
|
40
39
|
*
|
|
41
|
-
*
|
|
40
|
+
* setTimeout(() => {
|
|
41
|
+
* inner$.next(`${letter}2`);
|
|
42
|
+
* }, 110);
|
|
43
|
+
*
|
|
44
|
+
* setTimeout(() => {
|
|
45
|
+
* inner$.next(`${letter}3`);
|
|
46
|
+
* }, 210);
|
|
47
|
+
*
|
|
48
|
+
* return inner$;
|
|
42
49
|
* }),
|
|
43
50
|
* );
|
|
44
51
|
*
|
|
45
|
-
* const
|
|
52
|
+
* const valueHistory: string[] = [];
|
|
46
53
|
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
54
|
+
* result$.subscribe((value) => {
|
|
55
|
+
* valueHistory.push(value);
|
|
49
56
|
* });
|
|
50
57
|
*
|
|
51
|
-
*
|
|
58
|
+
* const sleep = (ms: number): Promise<void> =>
|
|
59
|
+
* new Promise((resolve) => {
|
|
60
|
+
* setTimeout(resolve, ms);
|
|
61
|
+
* });
|
|
52
62
|
*
|
|
53
|
-
*
|
|
63
|
+
* // Emit A - inner emits A1, A2, A3 at 10ms, 110ms, 210ms
|
|
64
|
+
* input$.next('A');
|
|
54
65
|
*
|
|
55
|
-
*
|
|
66
|
+
* await sleep(250);
|
|
56
67
|
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
68
|
+
* assert.deepStrictEqual(valueHistory, ['A1', 'A2', 'A3']);
|
|
69
|
+
*
|
|
70
|
+
* // Emit B - inner starts emitting B1, B2 at 10ms, 110ms
|
|
71
|
+
* input$.next('B');
|
|
72
|
+
*
|
|
73
|
+
* await sleep(150);
|
|
60
74
|
*
|
|
61
|
-
* assert.deepStrictEqual(
|
|
75
|
+
* assert.deepStrictEqual(valueHistory, ['A1', 'A2', 'A3', 'B1', 'B2']);
|
|
62
76
|
*
|
|
63
|
-
*
|
|
77
|
+
* // Emit C while B's inner is still running (B3 at 210ms not yet fired)
|
|
78
|
+
* // Unlike switchMap, B's inner is NOT cancelled
|
|
79
|
+
* input$.next('C');
|
|
64
80
|
*
|
|
65
|
-
*
|
|
81
|
+
* await sleep(250);
|
|
66
82
|
*
|
|
67
|
-
*
|
|
83
|
+
* // B3 appears between C1 and C2, showing the merge behavior
|
|
84
|
+
* assert.deepStrictEqual(valueHistory, [
|
|
85
|
+
* 'A1',
|
|
86
|
+
* 'A2',
|
|
87
|
+
* 'A3',
|
|
88
|
+
* 'B1',
|
|
89
|
+
* 'B2',
|
|
90
|
+
* 'C1',
|
|
91
|
+
* 'B3',
|
|
92
|
+
* 'C2',
|
|
93
|
+
* 'C3',
|
|
94
|
+
* ]);
|
|
68
95
|
* ```
|
|
69
96
|
*
|
|
70
97
|
* @note To improve code readability, consider using `createState` instead of `mergeMap`,
|
|
@@ -72,7 +99,7 @@ import '../utils/id-maker.mjs';
|
|
|
72
99
|
*/
|
|
73
100
|
const mergeMap = (mapToObservable) => (parentObservable) => new MergeMapObservableClass(parentObservable, mapToObservable);
|
|
74
101
|
/**
|
|
75
|
-
* Alias for `mergeMap
|
|
102
|
+
* Alias for `mergeMap`.
|
|
76
103
|
* @see mergeMap
|
|
77
104
|
*/
|
|
78
105
|
const flatMap = mergeMap;
|
|
@@ -89,10 +116,10 @@ class MergeMapObservableClass extends AsyncChildObservableClass {
|
|
|
89
116
|
this.#mut_observables = [];
|
|
90
117
|
this.#mut_subscriptions = [];
|
|
91
118
|
}
|
|
92
|
-
tryUpdate(
|
|
119
|
+
tryUpdate(updateToken) {
|
|
93
120
|
const par = this.parents[0];
|
|
94
121
|
const sn = par.getSnapshot();
|
|
95
|
-
if (par.
|
|
122
|
+
if (par.updateToken !== updateToken || Optional.isNone(sn)) {
|
|
96
123
|
return; // skip update
|
|
97
124
|
}
|
|
98
125
|
const observable = this.#mapToObservable(sn.value);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"merge-map.mjs","sources":["../../../src/core/operators/merge-map.mts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAUA
|
|
1
|
+
{"version":3,"file":"merge-map.mjs","sources":["../../../src/core/operators/merge-map.mts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAUA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8FG;MACU,QAAQ,GACnB,CACE,eAA2C,KAE7C,CAAC,gBAAgB,KACf,IAAI,uBAAuB,CAAC,gBAAgB,EAAE,eAAe;AAEjE;;;AAGG;AACI,MAAM,OAAO,GAAG;AAEvB,MAAM,uBACJ,SAAQ,yBAA0C,CAAA;AAGzC,IAAA,gBAAgB;AACzB,IAAA,gBAAgB;AAChB,IAAA,kBAAkB;IAElB,WAAA,CACE,gBAA+B,EAC/B,eAA2C,EAAA;AAE3C,QAAA,KAAK,CAAC;YACJ,OAAO,EAAE,CAAC,gBAAgB,CAAC;YAC3B,YAAY,EAAE,QAAQ,CAAC,IAAI;AAC5B,SAAA,CAAC;AAEF,QAAA,IAAI,CAAC,gBAAgB,GAAG,eAAe;AAEvC,QAAA,IAAI,CAAC,gBAAgB,GAAG,EAAE;AAE1B,QAAA,IAAI,CAAC,kBAAkB,GAAG,EAAE;IAC9B;AAES,IAAA,SAAS,CAAC,WAAwB,EAAA;QACzC,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;AAE3B,QAAA,MAAM,EAAE,GAAG,GAAG,CAAC,WAAW,EAAE;AAE5B,QAAA,IAAI,GAAG,CAAC,WAAW,KAAK,WAAW,IAAI,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE;AAC1D,YAAA,OAAO;QACT;QAEA,MAAM,UAAU,GAAG,IAAI,CAAC,gBAAgB,CAAC,EAAE,CAAC,KAAK,CAAC;AAElD,QAAA,IAAI,CAAC,gBAAgB,GAAG,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,gBAAgB,EAAE,UAAU,CAAC;QAEvE,MAAM,YAAY,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,IAAI,KAAI;AACjD,YAAA,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;AACxB,QAAA,CAAC,CAAC;AAEF,QAAA,IAAI,CAAC,kBAAkB,GAAG,GAAG,CAAC,QAAQ,CACpC,IAAI,CAAC,kBAAkB,EACvB,YAAY,CACb;IACH;IAES,QAAQ,GAAA;AACf,QAAA,KAAK,MAAM,CAAC,IAAI,IAAI,CAAC,kBAAkB,EAAE;YACvC,CAAC,CAAC,WAAW,EAAE;QACjB;AAEA,QAAA,KAAK,MAAM,CAAC,IAAI,IAAI,CAAC,gBAAgB,EAAE;YACrC,CAAC,CAAC,QAAQ,EAAE;QACd;QAEA,KAAK,CAAC,QAAQ,EAAE;IAClB;AACD;;;;"}
|