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
|
@@ -1,93 +0,0 @@
|
|
|
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 (300ms debounce):
|
|
16
|
-
* //
|
|
17
|
-
* // Time(ms) 0 100 200 300 400 500 600 ... 900 1000
|
|
18
|
-
* // input$ 'h' 'he' 'hel' 'hello'
|
|
19
|
-
* // debounced$ 'hello' (emitted after 300ms silence)
|
|
20
|
-
* //
|
|
21
|
-
* // Explanation:
|
|
22
|
-
* // - At 0ms: 'h' is emitted, timer starts
|
|
23
|
-
* // - At 100ms: 'he' is emitted, timer resets
|
|
24
|
-
* // - At 200ms: 'hel' is emitted, timer resets
|
|
25
|
-
* // - At 300ms: 'hello' is emitted, timer resets
|
|
26
|
-
* // - At 600ms: No new emission for 300ms, 'hello' is finally emitted
|
|
27
|
-
*
|
|
28
|
-
* const input$ = source<string>();
|
|
29
|
-
*
|
|
30
|
-
* const debounced$ = input$.pipe(debounceTime(300));
|
|
31
|
-
*
|
|
32
|
-
* const mut_history: string[] = [];
|
|
33
|
-
*
|
|
34
|
-
* debounced$.subscribe((value) => {
|
|
35
|
-
* mut_history.push(value);
|
|
36
|
-
* });
|
|
37
|
-
*
|
|
38
|
-
* input$.next('h');
|
|
39
|
-
*
|
|
40
|
-
* input$.next('he');
|
|
41
|
-
*
|
|
42
|
-
* input$.next('hel');
|
|
43
|
-
*
|
|
44
|
-
* input$.next('hello');
|
|
45
|
-
*
|
|
46
|
-
* await new Promise((resolve) => {
|
|
47
|
-
* setTimeout(resolve, 400);
|
|
48
|
-
* });
|
|
49
|
-
*
|
|
50
|
-
* assert.deepStrictEqual(mut_history, ['hello']);
|
|
51
|
-
* ```
|
|
52
|
-
*/
|
|
53
|
-
const debounceTime = (milliSeconds) =>
|
|
54
|
-
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
55
|
-
((parentObservable) => new DebounceTimeObservableClass(parentObservable, milliSeconds));
|
|
56
|
-
class DebounceTimeObservableClass extends AsyncChildObservableClass {
|
|
57
|
-
#milliSeconds;
|
|
58
|
-
#mut_timerId;
|
|
59
|
-
constructor(parentObservable, milliSeconds) {
|
|
60
|
-
super({
|
|
61
|
-
parents: [parentObservable],
|
|
62
|
-
initialValue: parentObservable.getSnapshot(),
|
|
63
|
-
});
|
|
64
|
-
this.#mut_timerId = undefined;
|
|
65
|
-
this.#milliSeconds = milliSeconds;
|
|
66
|
-
}
|
|
67
|
-
tryUpdate(updaterSymbol) {
|
|
68
|
-
const par = this.parents[0];
|
|
69
|
-
const sn = par.getSnapshot();
|
|
70
|
-
if (par.updaterSymbol !== updaterSymbol || Optional.isNone(sn)) {
|
|
71
|
-
return; // skip update
|
|
72
|
-
}
|
|
73
|
-
this.#resetTimer();
|
|
74
|
-
// set timer
|
|
75
|
-
this.#mut_timerId = setTimeout(() => {
|
|
76
|
-
if (Optional.isNone(sn))
|
|
77
|
-
return;
|
|
78
|
-
this.startUpdate(sn.value);
|
|
79
|
-
}, this.#milliSeconds);
|
|
80
|
-
}
|
|
81
|
-
#resetTimer() {
|
|
82
|
-
if (this.#mut_timerId !== undefined) {
|
|
83
|
-
clearTimeout(this.#mut_timerId);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
complete() {
|
|
87
|
-
this.#resetTimer();
|
|
88
|
-
super.complete();
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export { debounceTime };
|
|
93
|
-
//# sourceMappingURL=debounce-time.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"debounce-time.mjs","sources":["../../../src/core/operators/debounce-time.mts"],"sourcesContent":[null],"names":[],"mappings":";;;;AASA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+CG;AACI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;;"}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { Optional, Result } from 'ts-data-forge';
|
|
2
|
-
import { type KeepInitialValueOperator } from '../types/index.mjs';
|
|
3
|
-
/**
|
|
4
|
-
* Transforms each value emitted by the source using a mapping function that also receives the emission index.
|
|
5
|
-
*
|
|
6
|
-
* @template A - The type of values from the source
|
|
7
|
-
* @template B - The type of mapped values
|
|
8
|
-
* @param mapFn - A function that maps each value (receives value and index)
|
|
9
|
-
* @returns An operator that maps values with index
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* ```ts
|
|
13
|
-
* // Timeline:
|
|
14
|
-
* //
|
|
15
|
-
* // num$ "a" "b" "c"
|
|
16
|
-
* // indexed$ "0: a" "1: b" "2: c"
|
|
17
|
-
* //
|
|
18
|
-
* // Explanation:
|
|
19
|
-
* // - mapWithIndex transforms each value along with its index
|
|
20
|
-
* // - Index starts at 0 and increments with each emission
|
|
21
|
-
*
|
|
22
|
-
* const num$ = source<string>();
|
|
23
|
-
*
|
|
24
|
-
* const indexed$ = num$.pipe(mapWithIndex((x, i) => `${i}: ${x}`));
|
|
25
|
-
*
|
|
26
|
-
* const mut_history: string[] = [];
|
|
27
|
-
*
|
|
28
|
-
* indexed$.subscribe((s) => {
|
|
29
|
-
* mut_history.push(s);
|
|
30
|
-
* });
|
|
31
|
-
*
|
|
32
|
-
* num$.next('a'); // 0: a
|
|
33
|
-
*
|
|
34
|
-
* num$.next('b'); // 1: b
|
|
35
|
-
*
|
|
36
|
-
* num$.next('c'); // 2: c
|
|
37
|
-
*
|
|
38
|
-
* assert.deepStrictEqual(mut_history, ['0: a', '1: b', '2: c']);
|
|
39
|
-
* ```
|
|
40
|
-
*/
|
|
41
|
-
export declare const mapWithIndex: <A, B>(mapFn: (x: A, index: SafeUint | -1) => B) => KeepInitialValueOperator<A, B>;
|
|
42
|
-
export declare const map: <A, B>(mapFn: (x: A) => B) => KeepInitialValueOperator<A, B>;
|
|
43
|
-
export declare const mapTo: <A, B>(value: B) => KeepInitialValueOperator<A, B>;
|
|
44
|
-
export declare const pluck: <A, K extends keyof A>(key: K) => KeepInitialValueOperator<A, A[K]>;
|
|
45
|
-
export declare const getKey: <A, K extends keyof A>(key: K) => KeepInitialValueOperator<A, A[K]>;
|
|
46
|
-
export declare const attachIndex: <A>() => KeepInitialValueOperator<A, readonly [SafeUint | -1, A]>;
|
|
47
|
-
export declare const withIndex: <A>() => KeepInitialValueOperator<A, readonly [SafeUint | -1, A]>;
|
|
48
|
-
export declare const unwrapOptional: <O extends UnknownOptional>() => KeepInitialValueOperator<O, Optional.Unwrap<O> | undefined>;
|
|
49
|
-
export declare const unwrapResultOk: <R extends UnknownResult>() => KeepInitialValueOperator<R, Result.UnwrapOk<R> | undefined>;
|
|
50
|
-
export declare const unwrapResultErr: <R extends UnknownResult>() => KeepInitialValueOperator<R, Result.UnwrapErr<R> | undefined>;
|
|
51
|
-
export declare const mapOptional: <O extends UnknownOptional, B>(mapFn: (x: Optional.Unwrap<O>) => B) => KeepInitialValueOperator<O, Optional<B>>;
|
|
52
|
-
export declare const mapResultOk: <R extends UnknownResult, S2>(mapFn: (x: Result.UnwrapOk<R>) => S2) => KeepInitialValueOperator<R, Result<S2, Result.UnwrapErr<R>>>;
|
|
53
|
-
export declare const mapResultErr: <R extends UnknownResult, E2>(mapFn: (x: Result.UnwrapErr<R>) => E2) => KeepInitialValueOperator<R, Result<Result.UnwrapOk<R>, E2>>;
|
|
54
|
-
//# sourceMappingURL=map-with-index.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"map-with-index.d.mts","sourceRoot":"","sources":["../../../src/core/operators/map-with-index.mts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EACR,MAAM,EAIP,MAAM,eAAe,CAAC;AAGvB,OAAO,EAEL,KAAK,wBAAwB,EAI9B,MAAM,oBAAoB,CAAC;AAG5B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqC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B,CAAC,CAAC,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,SAAS,CAEA,CAAC;AAEhE,eAAO,MAAM,eAAe,GAC1B,CAAC,SAAS,aAAa,OACpB,wBAAwB,CAAC,CAAC,EAAE,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,SAAS,CACC,CAAC;AAElE,eAAO,MAAM,WAAW,GAAI,CAAC,SAAS,eAAe,EAAE,CAAC,EACtD,OAAO,CAAC,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,KAClC,wBAAwB,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,CACN,CAAC;AAErC,eAAO,MAAM,WAAW,GAAI,CAAC,SAAS,aAAa,EAAE,EAAE,EACrD,OAAO,CAAC,CAAC,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,EAAE,KACnC,wBAAwB,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE,EAAE,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAC5B,CAAC;AAEnC,eAAO,MAAM,YAAY,GAAI,CAAC,SAAS,aAAa,EAAE,EAAE,EACtD,OAAO,CAAC,CAAC,EAAE,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,EAAE,KACpC,wBAAwB,CAAC,CAAC,EAAE,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CACxB,CAAC"}
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import { Optional, asSafeUint, SafeUint, Result } 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(mapWithIndex((x, i) => `${i}: ${x}`));
|
|
27
|
-
*
|
|
28
|
-
* const mut_history: string[] = [];
|
|
29
|
-
*
|
|
30
|
-
* indexed$.subscribe((s) => {
|
|
31
|
-
* mut_history.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(mut_history, ['0: a', '1: b', '2: c']);
|
|
41
|
-
* ```
|
|
42
|
-
*/
|
|
43
|
-
const mapWithIndex = (mapFn) =>
|
|
44
|
-
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
45
|
-
((parentObservable) => new MapWithIndexObservableClass(parentObservable, mapFn));
|
|
46
|
-
/* Specialized operators */
|
|
47
|
-
const map = (mapFn) => mapWithIndex(mapFn);
|
|
48
|
-
const mapTo = (value) => map(() => value);
|
|
49
|
-
const pluck = (key) => map((a) => a[key]);
|
|
50
|
-
const getKey = pluck; // alias
|
|
51
|
-
const attachIndex = () => mapWithIndex((a, i) => [i, a]);
|
|
52
|
-
const withIndex = attachIndex; // alias
|
|
53
|
-
const unwrapOptional = () =>
|
|
54
|
-
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
55
|
-
map(Optional.unwrap);
|
|
56
|
-
const unwrapResultOk = () =>
|
|
57
|
-
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
58
|
-
map(Result.unwrapOk);
|
|
59
|
-
const unwrapResultErr = () => map(Result.unwrapErr);
|
|
60
|
-
const mapOptional = (mapFn) => map((a) => Optional.map(a, mapFn));
|
|
61
|
-
const mapResultOk = (mapFn) => map((a) => Result.map(a, mapFn));
|
|
62
|
-
const mapResultErr = (mapFn) => map((a) => Result.mapErr(a, mapFn));
|
|
63
|
-
/* implementation */
|
|
64
|
-
class MapWithIndexObservableClass extends SyncChildObservableClass {
|
|
65
|
-
#mapFn;
|
|
66
|
-
#mut_index;
|
|
67
|
-
constructor(parentObservable, mapFn) {
|
|
68
|
-
super({
|
|
69
|
-
parents: [parentObservable],
|
|
70
|
-
initialValue: Optional.map(parentObservable.getSnapshot(), (x) => mapFn(x, -1)),
|
|
71
|
-
});
|
|
72
|
-
this.#mut_index = -1;
|
|
73
|
-
this.#mapFn = mapFn;
|
|
74
|
-
}
|
|
75
|
-
tryUpdate(updaterSymbol) {
|
|
76
|
-
const par = this.parents[0];
|
|
77
|
-
const sn = par.getSnapshot();
|
|
78
|
-
if (par.updaterSymbol !== updaterSymbol || Optional.isNone(sn)) {
|
|
79
|
-
return; // skip update
|
|
80
|
-
}
|
|
81
|
-
this.#mut_index =
|
|
82
|
-
this.#mut_index === -1 ? asSafeUint(0) : SafeUint.add(1, this.#mut_index);
|
|
83
|
-
this.setNext(this.#mapFn(sn.value, this.#mut_index), updaterSymbol);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
export { attachIndex, getKey, map, mapOptional, mapResultErr, mapResultOk, mapTo, mapWithIndex, pluck, unwrapOptional, unwrapResultErr, unwrapResultOk, withIndex };
|
|
88
|
-
//# sourceMappingURL=map-with-index.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|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MAAM,2BACJ,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,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,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,IAAI,CAAC,UAAU,CAAC,EAAE,aAAa,CAAC;;AAEtE;;;;"}
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { type KeepInitialValueOperator } from '../types/index.mjs';
|
|
2
|
-
/**
|
|
3
|
-
* Emits the first value, then ignores subsequent values for a specified duration.
|
|
4
|
-
* After the duration, the next emission is allowed through.
|
|
5
|
-
*
|
|
6
|
-
* @template A - The type of values from the source
|
|
7
|
-
* @param milliSeconds - The throttle duration in milliseconds
|
|
8
|
-
* @returns An operator that throttles emissions
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
* ```ts
|
|
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)
|
|
27
|
-
*
|
|
28
|
-
* const scroll$ = source<number>();
|
|
29
|
-
*
|
|
30
|
-
* const throttled$ = scroll$.pipe(throttleTime(200));
|
|
31
|
-
*
|
|
32
|
-
* const mut_history: number[] = [];
|
|
33
|
-
*
|
|
34
|
-
* throttled$.subscribe((value) => {
|
|
35
|
-
* mut_history.push(value);
|
|
36
|
-
* });
|
|
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]);
|
|
59
|
-
* ```
|
|
60
|
-
*/
|
|
61
|
-
export declare const throttleTime: <A>(milliSeconds: number) => KeepInitialValueOperator<A, A>;
|
|
62
|
-
//# sourceMappingURL=throttle-time.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import { Optional } from 'ts-data-forge';
|
|
2
|
-
import { SyncChildObservableClass } from '../class/child-observable-class.mjs';
|
|
3
|
-
import '../utils/id-maker.mjs';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Emits the first value, then ignores subsequent values for a specified duration.
|
|
7
|
-
* After the duration, the next emission is allowed through.
|
|
8
|
-
*
|
|
9
|
-
* @template A - The type of values from the source
|
|
10
|
-
* @param milliSeconds - The throttle duration in milliseconds
|
|
11
|
-
* @returns An operator that throttles emissions
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* ```ts
|
|
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)
|
|
30
|
-
*
|
|
31
|
-
* const scroll$ = source<number>();
|
|
32
|
-
*
|
|
33
|
-
* const throttled$ = scroll$.pipe(throttleTime(200));
|
|
34
|
-
*
|
|
35
|
-
* const mut_history: number[] = [];
|
|
36
|
-
*
|
|
37
|
-
* throttled$.subscribe((value) => {
|
|
38
|
-
* mut_history.push(value);
|
|
39
|
-
* });
|
|
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]);
|
|
62
|
-
* ```
|
|
63
|
-
*/
|
|
64
|
-
const throttleTime = (milliSeconds) =>
|
|
65
|
-
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
66
|
-
((parentObservable) => new ThrottleTimeObservableClass(parentObservable, milliSeconds));
|
|
67
|
-
class ThrottleTimeObservableClass extends SyncChildObservableClass {
|
|
68
|
-
#milliSeconds;
|
|
69
|
-
#mut_timerId;
|
|
70
|
-
#mut_isSkipping;
|
|
71
|
-
constructor(parentObservable, milliSeconds) {
|
|
72
|
-
super({
|
|
73
|
-
parents: [parentObservable],
|
|
74
|
-
initialValue: parentObservable.getSnapshot(),
|
|
75
|
-
});
|
|
76
|
-
this.#mut_timerId = undefined;
|
|
77
|
-
this.#mut_isSkipping = false;
|
|
78
|
-
this.#milliSeconds = milliSeconds;
|
|
79
|
-
}
|
|
80
|
-
tryUpdate(updaterSymbol) {
|
|
81
|
-
const par = this.parents[0];
|
|
82
|
-
const sn = par.getSnapshot();
|
|
83
|
-
if (par.updaterSymbol !== updaterSymbol ||
|
|
84
|
-
Optional.isNone(sn) ||
|
|
85
|
-
this.#mut_isSkipping) {
|
|
86
|
-
return; // skip update
|
|
87
|
-
}
|
|
88
|
-
this.setNext(sn.value, updaterSymbol);
|
|
89
|
-
this.#mut_isSkipping = true;
|
|
90
|
-
// set timer
|
|
91
|
-
this.#mut_timerId = setTimeout(() => {
|
|
92
|
-
this.#mut_isSkipping = false;
|
|
93
|
-
}, this.#milliSeconds);
|
|
94
|
-
}
|
|
95
|
-
#resetTimer() {
|
|
96
|
-
if (this.#mut_timerId !== undefined) {
|
|
97
|
-
clearTimeout(this.#mut_timerId);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
complete() {
|
|
101
|
-
this.#resetTimer();
|
|
102
|
-
super.complete();
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
export { throttleTime };
|
|
107
|
-
//# sourceMappingURL=throttle-time.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"throttle-time.mjs","sources":["../../../src/core/operators/throttle-time.mts"],"sourcesContent":[null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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,76 +0,0 @@
|
|
|
1
|
-
import { Optional } from 'ts-data-forge';
|
|
2
|
-
import { RootObservableClass } from '../class/index.mjs';
|
|
3
|
-
import { type FromArrayObservable } from '../types/index.mjs';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Creates an observable that emits all values from an array sequentially, then completes.
|
|
7
|
-
*
|
|
8
|
-
* @template A - The type of array elements
|
|
9
|
-
* @param values - The array of values to emit
|
|
10
|
-
* @param startManually - If true, waits for manual start (default: false)
|
|
11
|
-
* @returns An observable that emits array values
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* ```ts
|
|
15
|
-
* // Timeline:
|
|
16
|
-
* //
|
|
17
|
-
* // nums$ 1 2 3 | (completes)
|
|
18
|
-
* //
|
|
19
|
-
* // Explanation:
|
|
20
|
-
* // - fromArray creates an observable from an array
|
|
21
|
-
* // - Emits all values synchronously, then completes
|
|
22
|
-
*
|
|
23
|
-
* const nums$ = fromArray([1, 2, 3]);
|
|
24
|
-
*
|
|
25
|
-
* const mut_history: number[] = [];
|
|
26
|
-
*
|
|
27
|
-
* await new Promise<void>((resolve) => {
|
|
28
|
-
* nums$.subscribe(
|
|
29
|
-
* (x) => {
|
|
30
|
-
* mut_history.push(x);
|
|
31
|
-
* },
|
|
32
|
-
* () => {
|
|
33
|
-
* resolve();
|
|
34
|
-
* },
|
|
35
|
-
* );
|
|
36
|
-
* });
|
|
37
|
-
*
|
|
38
|
-
* assert.deepStrictEqual(mut_history, [1, 2, 3]);
|
|
39
|
-
* ```
|
|
40
|
-
*/
|
|
41
|
-
export const fromArray = <A,>(
|
|
42
|
-
values: readonly A[],
|
|
43
|
-
startManually: boolean = false,
|
|
44
|
-
): FromArrayObservable<A> =>
|
|
45
|
-
new FromArrayObservableClass<A>(values, startManually);
|
|
46
|
-
|
|
47
|
-
class FromArrayObservableClass<A>
|
|
48
|
-
extends RootObservableClass<A>
|
|
49
|
-
implements FromArrayObservable<A>
|
|
50
|
-
{
|
|
51
|
-
readonly #values: readonly A[];
|
|
52
|
-
|
|
53
|
-
constructor(values: readonly A[], startManually: boolean = false) {
|
|
54
|
-
super({ initialValue: Optional.none });
|
|
55
|
-
|
|
56
|
-
this.#values = values;
|
|
57
|
-
|
|
58
|
-
if (!startManually) {
|
|
59
|
-
setTimeout(() => {
|
|
60
|
-
this.emit();
|
|
61
|
-
}, 0);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
emit(): this {
|
|
66
|
-
if (this.isCompleted) return this;
|
|
67
|
-
|
|
68
|
-
for (const v of this.#values) {
|
|
69
|
-
this.startUpdate(v);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
this.complete();
|
|
73
|
-
|
|
74
|
-
return this;
|
|
75
|
-
}
|
|
76
|
-
}
|
package/src/core/create/of.mts
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { Optional } from 'ts-data-forge';
|
|
2
|
-
import { RootObservableClass } from '../class/index.mjs';
|
|
3
|
-
import { type OfObservable } from '../types/index.mjs';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Creates an observable that emits a single value and then completes.
|
|
7
|
-
*
|
|
8
|
-
* @template A - The type of the value
|
|
9
|
-
* @param value - The value to emit
|
|
10
|
-
* @param startManually - If true, waits for manual start (default: false)
|
|
11
|
-
* @returns An observable that emits the value
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* ```ts
|
|
15
|
-
* // Timeline:
|
|
16
|
-
* //
|
|
17
|
-
* // num$ 42 | (completes immediately)
|
|
18
|
-
* //
|
|
19
|
-
* // Explanation:
|
|
20
|
-
* // - of creates an observable that emits a single value, then completes
|
|
21
|
-
* // - Useful for converting a static value into an observable
|
|
22
|
-
*
|
|
23
|
-
* const num$ = of(42);
|
|
24
|
-
*
|
|
25
|
-
* const mut_history: number[] = [];
|
|
26
|
-
*
|
|
27
|
-
* await new Promise<void>((resolve) => {
|
|
28
|
-
* num$.subscribe(
|
|
29
|
-
* (x) => {
|
|
30
|
-
* mut_history.push(x);
|
|
31
|
-
* },
|
|
32
|
-
* () => {
|
|
33
|
-
* resolve();
|
|
34
|
-
* },
|
|
35
|
-
* );
|
|
36
|
-
* });
|
|
37
|
-
*
|
|
38
|
-
* assert.deepStrictEqual(mut_history, [42]);
|
|
39
|
-
* ```
|
|
40
|
-
*/
|
|
41
|
-
export const of = <A,>(
|
|
42
|
-
value: A,
|
|
43
|
-
startManually: boolean = false,
|
|
44
|
-
): OfObservable<A> => new OfObservableClass<A>(value, startManually);
|
|
45
|
-
|
|
46
|
-
class OfObservableClass<A>
|
|
47
|
-
extends RootObservableClass<A>
|
|
48
|
-
implements OfObservable<A>
|
|
49
|
-
{
|
|
50
|
-
readonly #value: A;
|
|
51
|
-
|
|
52
|
-
constructor(value: A, startManually: boolean = false) {
|
|
53
|
-
super({ initialValue: Optional.none });
|
|
54
|
-
|
|
55
|
-
this.#value = value;
|
|
56
|
-
|
|
57
|
-
if (!startManually) {
|
|
58
|
-
setTimeout(() => {
|
|
59
|
-
this.emit();
|
|
60
|
-
}, 0);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
emit(): this {
|
|
65
|
-
if (this.isCompleted) return this;
|
|
66
|
-
|
|
67
|
-
this.startUpdate(this.#value);
|
|
68
|
-
|
|
69
|
-
this.complete();
|
|
70
|
-
|
|
71
|
-
return this;
|
|
72
|
-
}
|
|
73
|
-
}
|