synstate 1.0.2 → 2.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 +9 -10
- package/dist/core/class/child-observable-class.d.mts.map +1 -1
- package/dist/core/class/child-observable-class.mjs +148 -140
- package/dist/core/class/child-observable-class.mjs.map +1 -1
- package/dist/core/class/observable-base-class.d.mts.map +1 -1
- package/dist/core/class/observable-base-class.mjs +111 -107
- package/dist/core/class/observable-base-class.mjs.map +1 -1
- package/dist/core/class/root-observable-class.d.mts.map +1 -1
- package/dist/core/class/root-observable-class.mjs +32 -24
- package/dist/core/class/root-observable-class.mjs.map +1 -1
- package/dist/core/combine/combine.d.mts +3 -3
- package/dist/core/combine/combine.d.mts.map +1 -1
- package/dist/core/combine/combine.mjs +31 -113
- package/dist/core/combine/combine.mjs.map +1 -1
- package/dist/core/combine/merge.d.mts +2 -2
- package/dist/core/combine/merge.d.mts.map +1 -1
- package/dist/core/combine/merge.mjs +21 -69
- package/dist/core/combine/merge.mjs.map +1 -1
- package/dist/core/combine/zip.d.mts +2 -2
- package/dist/core/combine/zip.d.mts.map +1 -1
- package/dist/core/combine/zip.mjs +34 -79
- package/dist/core/combine/zip.mjs.map +1 -1
- package/dist/core/create/counter.d.mts +1 -1
- package/dist/core/create/counter.d.mts.map +1 -1
- package/dist/core/create/counter.mjs +45 -84
- package/dist/core/create/counter.mjs.map +1 -1
- package/dist/core/create/from-abortable-promise.d.mts.map +1 -1
- package/dist/core/create/from-abortable-promise.mjs +29 -61
- package/dist/core/create/from-abortable-promise.mjs.map +1 -1
- package/dist/core/create/from-promise.d.mts.map +1 -1
- package/dist/core/create/from-promise.mjs +17 -66
- package/dist/core/create/from-promise.mjs.map +1 -1
- package/dist/core/create/from-subscribable.d.mts.map +1 -1
- package/dist/core/create/from-subscribable.mjs +18 -69
- package/dist/core/create/from-subscribable.mjs.map +1 -1
- package/dist/core/create/just.d.mts.map +1 -1
- package/dist/core/create/just.mjs +5 -35
- package/dist/core/create/just.mjs.map +1 -1
- package/dist/core/create/source.mjs +10 -13
- package/dist/core/create/source.mjs.map +1 -1
- package/dist/core/create/timer.d.mts.map +1 -1
- package/dist/core/create/timer.mjs +32 -68
- package/dist/core/create/timer.mjs.map +1 -1
- package/dist/core/operators/audit.d.mts.map +1 -1
- package/dist/core/operators/audit.mjs +39 -133
- package/dist/core/operators/audit.mjs.map +1 -1
- package/dist/core/operators/debounce.d.mts.map +1 -1
- package/dist/core/operators/debounce.mjs +36 -119
- package/dist/core/operators/debounce.mjs.map +1 -1
- package/dist/core/operators/filter.mjs +22 -25
- package/dist/core/operators/filter.mjs.map +1 -1
- package/dist/core/operators/map.d.mts.map +1 -1
- package/dist/core/operators/map.mjs +28 -61
- package/dist/core/operators/map.mjs.map +1 -1
- package/dist/core/operators/merge-map.d.mts +1 -1
- package/dist/core/operators/merge-map.d.mts.map +1 -1
- package/dist/core/operators/merge-map.mjs +34 -130
- package/dist/core/operators/merge-map.mjs.map +1 -1
- package/dist/core/operators/pairwise.d.mts +3 -2
- package/dist/core/operators/pairwise.d.mts.map +1 -1
- package/dist/core/operators/pairwise.mjs +19 -75
- package/dist/core/operators/pairwise.mjs.map +1 -1
- package/dist/core/operators/scan.d.mts.map +1 -1
- package/dist/core/operators/scan.mjs +16 -67
- package/dist/core/operators/scan.mjs.map +1 -1
- package/dist/core/operators/skip-if-no-change.d.mts +1 -1
- package/dist/core/operators/skip-if-no-change.d.mts.map +1 -1
- package/dist/core/operators/skip-if-no-change.mjs +28 -92
- package/dist/core/operators/skip-if-no-change.mjs.map +1 -1
- package/dist/core/operators/skip-until.d.mts.map +1 -1
- package/dist/core/operators/skip-until.mjs +23 -72
- package/dist/core/operators/skip-until.mjs.map +1 -1
- package/dist/core/operators/skip-while.d.mts.map +1 -1
- package/dist/core/operators/skip-while.mjs +26 -88
- package/dist/core/operators/skip-while.mjs.map +1 -1
- package/dist/core/operators/switch-map.d.mts.map +1 -1
- package/dist/core/operators/switch-map.mjs +31 -124
- package/dist/core/operators/switch-map.mjs.map +1 -1
- package/dist/core/operators/take-until.d.mts.map +1 -1
- package/dist/core/operators/take-until.mjs +28 -69
- package/dist/core/operators/take-until.mjs.map +1 -1
- package/dist/core/operators/take-while.d.mts.map +1 -1
- package/dist/core/operators/take-while.mjs +23 -83
- package/dist/core/operators/take-while.mjs.map +1 -1
- package/dist/core/operators/throttle.d.mts.map +1 -1
- package/dist/core/operators/throttle.mjs +38 -115
- package/dist/core/operators/throttle.mjs.map +1 -1
- package/dist/core/operators/with-buffered-from.d.mts +1 -1
- package/dist/core/operators/with-buffered-from.d.mts.map +1 -1
- package/dist/core/operators/with-buffered-from.mjs +37 -90
- package/dist/core/operators/with-buffered-from.mjs.map +1 -1
- package/dist/core/operators/with-current-value-from.d.mts +1 -1
- package/dist/core/operators/with-current-value-from.d.mts.map +1 -1
- package/dist/core/operators/with-current-value-from.mjs +23 -84
- package/dist/core/operators/with-current-value-from.mjs.map +1 -1
- package/dist/core/operators/with-initial-value.d.mts.map +1 -1
- package/dist/core/operators/with-initial-value.mjs +13 -58
- package/dist/core/operators/with-initial-value.mjs.map +1 -1
- package/dist/core/predefined/operators/attach-index.d.mts +1 -1
- package/dist/core/predefined/operators/attach-index.d.mts.map +1 -1
- package/dist/core/predefined/operators/attach-index.mjs +0 -53
- package/dist/core/predefined/operators/attach-index.mjs.map +1 -1
- package/dist/core/predefined/operators/map-optional.d.mts.map +1 -1
- package/dist/core/predefined/operators/map-optional.mjs +1 -48
- package/dist/core/predefined/operators/map-optional.mjs.map +1 -1
- package/dist/core/predefined/operators/map-result-err.d.mts.map +1 -1
- package/dist/core/predefined/operators/map-result-err.mjs +1 -48
- package/dist/core/predefined/operators/map-result-err.mjs.map +1 -1
- package/dist/core/predefined/operators/map-result-ok.d.mts.map +1 -1
- package/dist/core/predefined/operators/map-result-ok.mjs +1 -48
- package/dist/core/predefined/operators/map-result-ok.mjs.map +1 -1
- package/dist/core/predefined/operators/map-to.d.mts.map +1 -1
- package/dist/core/predefined/operators/map-to.mjs +0 -40
- package/dist/core/predefined/operators/map-to.mjs.map +1 -1
- package/dist/core/predefined/operators/pluck.d.mts +1 -1
- package/dist/core/predefined/operators/pluck.d.mts.map +1 -1
- package/dist/core/predefined/operators/pluck.mjs +0 -43
- package/dist/core/predefined/operators/pluck.mjs.map +1 -1
- package/dist/core/predefined/operators/skip.d.mts.map +1 -1
- package/dist/core/predefined/operators/skip.mjs +0 -47
- package/dist/core/predefined/operators/skip.mjs.map +1 -1
- package/dist/core/predefined/operators/take.d.mts.map +1 -1
- package/dist/core/predefined/operators/take.mjs +0 -41
- package/dist/core/predefined/operators/take.mjs.map +1 -1
- package/dist/core/predefined/operators/unwrap-optional.mjs +4 -43
- package/dist/core/predefined/operators/unwrap-optional.mjs.map +1 -1
- package/dist/core/predefined/operators/unwrap-result-err.mjs +0 -40
- package/dist/core/predefined/operators/unwrap-result-err.mjs.map +1 -1
- package/dist/core/predefined/operators/unwrap-result-ok.mjs +4 -43
- package/dist/core/predefined/operators/unwrap-result-ok.mjs.map +1 -1
- package/dist/core/types/observable-family.d.mts +10 -10
- package/dist/core/types/observable-family.d.mts.map +1 -1
- package/dist/core/types/observable.d.mts.map +1 -1
- package/dist/core/types/observable.mjs +3 -5
- package/dist/core/types/observable.mjs.map +1 -1
- package/dist/core/types/types.d.mts +2 -1
- package/dist/core/types/types.d.mts.map +1 -1
- package/dist/core/utils/id-maker.mjs +5 -6
- package/dist/core/utils/id-maker.mjs.map +1 -1
- package/dist/core/utils/max-depth.d.mts.map +1 -1
- package/dist/core/utils/max-depth.mjs +1 -3
- package/dist/core/utils/max-depth.mjs.map +1 -1
- package/dist/core/utils/observable-utils.d.mts.map +1 -1
- package/dist/core/utils/observable-utils.mjs +3 -2
- package/dist/core/utils/observable-utils.mjs.map +1 -1
- package/dist/core/utils/utils.d.mts.map +1 -1
- package/dist/core/utils/utils.mjs +23 -30
- package/dist/core/utils/utils.mjs.map +1 -1
- package/dist/utils/collect-to-array.d.mts.map +1 -1
- package/dist/utils/collect-to-array.mjs +9 -6
- package/dist/utils/collect-to-array.mjs.map +1 -1
- package/dist/utils/create-boolean-state.d.mts +1 -1
- package/dist/utils/create-boolean-state.d.mts.map +1 -1
- package/dist/utils/create-boolean-state.mjs +18 -46
- package/dist/utils/create-boolean-state.mjs.map +1 -1
- package/dist/utils/create-event-emitter.mjs +10 -64
- package/dist/utils/create-event-emitter.mjs.map +1 -1
- package/dist/utils/create-reducer.d.mts +1 -1
- package/dist/utils/create-reducer.d.mts.map +1 -1
- package/dist/utils/create-reducer.mjs +8 -52
- package/dist/utils/create-reducer.mjs.map +1 -1
- package/dist/utils/create-state.d.mts +1 -1
- package/dist/utils/create-state.d.mts.map +1 -1
- package/dist/utils/create-state.mjs +23 -53
- package/dist/utils/create-state.mjs.map +1 -1
- package/package.json +13 -14
- package/src/core/class/child-observable-class.mts +1 -1
- package/src/core/class/observable-base-class.mts +16 -16
- package/src/core/combine/combine.mts +38 -16
- package/src/core/combine/merge.mts +3 -3
- package/src/core/combine/zip.mts +24 -13
- package/src/core/create/counter.mts +11 -9
- package/src/core/create/counter.test.mts +11 -0
- package/src/core/create/timer.mts +6 -6
- package/src/core/create/timer.test.mts +11 -0
- package/src/core/operators/audit-throttle-teardown.test.mts +21 -0
- package/src/core/operators/audit.mts +6 -6
- package/src/core/operators/debounce.mts +6 -6
- package/src/core/operators/pairwise.mts +10 -5
- package/src/core/operators/skip-while.mts +1 -5
- package/src/core/operators/skip-while.test.mts +20 -0
- package/src/core/operators/throttle.mts +6 -6
- package/src/core/operators/with-buffered-from.mts +4 -4
- package/src/core/predefined/operators/map-optional.mts +1 -2
- package/src/core/predefined/operators/map-result-err.mts +1 -1
- package/src/core/predefined/operators/map-result-ok.mts +1 -1
- package/src/core/types/observable-family.mts +12 -11
- package/src/core/types/observable.mts +5 -7
- package/src/core/types/types.mts +2 -1
- package/src/core/utils/max-depth.mts +5 -1
- package/src/core/utils/utils.mts +1 -1
- package/src/utils/create-boolean-state.mts +1 -1
- package/src/utils/create-reducer.mts +1 -1
- package/src/utils/create-state.mts +1 -1
|
@@ -3,99 +3,46 @@ 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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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 valueHistory: (readonly [number, readonly string[]])[] = [];
|
|
36
|
-
*
|
|
37
|
-
* result$.subscribe(([triggerValue, bufferedData]) => {
|
|
38
|
-
* valueHistory.push([triggerValue, bufferedData]);
|
|
39
|
-
* });
|
|
40
|
-
*
|
|
41
|
-
* data$.next('A');
|
|
42
|
-
*
|
|
43
|
-
* data$.next('B');
|
|
44
|
-
*
|
|
45
|
-
* trigger$.next(1);
|
|
46
|
-
*
|
|
47
|
-
* assert.deepStrictEqual(valueHistory, [[1, ['A', 'B']]]);
|
|
48
|
-
*
|
|
49
|
-
* data$.next('C');
|
|
50
|
-
*
|
|
51
|
-
* trigger$.next(2);
|
|
52
|
-
*
|
|
53
|
-
* assert.deepStrictEqual(valueHistory, [
|
|
54
|
-
* [1, ['A', 'B']],
|
|
55
|
-
* [2, ['C']],
|
|
56
|
-
* ]);
|
|
57
|
-
* ```
|
|
58
|
-
*/
|
|
59
|
-
const withBufferedFrom = (observable) =>
|
|
60
|
-
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
61
|
-
((parentObservable) => new WithBufferedFromObservableClass(parentObservable, observable));
|
|
62
|
-
/**
|
|
63
|
-
* Alias for `withBufferedFrom`.
|
|
64
|
-
* @see withBufferedFrom
|
|
65
|
-
*/
|
|
6
|
+
const withBufferedFrom = (observable) => (
|
|
7
|
+
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
8
|
+
((parentObservable) => new WithBufferedFromObservableClass(
|
|
9
|
+
parentObservable,
|
|
10
|
+
observable
|
|
11
|
+
))
|
|
12
|
+
);
|
|
66
13
|
const withBuffered = withBufferedFrom;
|
|
67
14
|
class WithBufferedFromObservableClass extends SyncChildObservableClass {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
}
|
|
96
|
-
#clearBuffer() {
|
|
97
|
-
this.#mut_bufferedValues = [];
|
|
15
|
+
#mut_bufferedValues = [];
|
|
16
|
+
constructor(parentObservable, observable) {
|
|
17
|
+
super({
|
|
18
|
+
parents: [parentObservable],
|
|
19
|
+
depth: 1 + maxDepth([parentObservable, observable]),
|
|
20
|
+
initialValue: pipe({
|
|
21
|
+
par: parentObservable.getSnapshot(),
|
|
22
|
+
me: observable.getSnapshot()
|
|
23
|
+
}).map(
|
|
24
|
+
({ par, me }) => Optional.isNone(par) ? Optional.none : Optional.some([
|
|
25
|
+
par.value,
|
|
26
|
+
Optional.isNone(me) ? [] : [me.value]
|
|
27
|
+
])
|
|
28
|
+
).value
|
|
29
|
+
});
|
|
30
|
+
observable.subscribe((value) => {
|
|
31
|
+
this.#mut_bufferedValues = Arr.toPushed(this.#mut_bufferedValues, value);
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
#clearBuffer() {
|
|
35
|
+
this.#mut_bufferedValues = [];
|
|
36
|
+
}
|
|
37
|
+
tryUpdate(updateToken) {
|
|
38
|
+
const par = this.parents[0];
|
|
39
|
+
const sn = par.getSnapshot();
|
|
40
|
+
if (par.updateToken !== updateToken || Optional.isNone(sn)) {
|
|
41
|
+
return;
|
|
98
42
|
}
|
|
43
|
+
this.setNext([sn.value, this.#mut_bufferedValues], updateToken);
|
|
44
|
+
this.#clearBuffer();
|
|
45
|
+
}
|
|
99
46
|
}
|
|
100
47
|
|
|
101
48
|
export { withBuffered, withBufferedFrom };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"with-buffered-from.mjs","sources":["../../../src/core/operators/with-buffered-from.mts"],"sourcesContent":[
|
|
1
|
+
{"version":3,"file":"with-buffered-from.mjs","sources":["../../../src/core/operators/with-buffered-from.mts"],"sourcesContent":["import { Arr, Optional, pipe } from 'ts-data-forge';\nimport { SyncChildObservableClass } from '../class/index.mjs';\nimport {\n type KeepInitialValueOperator,\n type Observable,\n type UpdateToken,\n type WithBufferedFromOperatorObservable,\n} from '../types/index.mjs';\nimport { maxDepth } from '../utils/index.mjs';\n\n/**\n * Buffers values from the source observable and emits them along with the parent value\n * when the parent emits. The buffer is cleared after each emission.\n *\n * @template A - The type of values from the parent observable\n * @template B - The type of values from the source observable\n * @param observable - The observable whose values will be buffered\n * @returns An operator that emits tuples of [parentValue, bufferedValues]\n *\n * @example\n * ```ts\n * // Timeline:\n * //\n * // data$ d1 d2 d3 d4 d5 d6 d7 d8\n * // trigger$ T1 T2 T3\n * // result$ [T1,[d1,d2,d3]] [T2,[d4,d5,d6]] [T3,[d7,d8]]\n * //\n * // Explanation:\n * // - withBufferedFrom collects values from the source observable\n * // - When the trigger emits, it emits a tuple of [triggerValue, bufferedValues]\n * // - Buffer is cleared after each emission\n * // - Useful for batching data collection triggered by events\n *\n * const data$ = source<string>();\n *\n * const trigger$ = source<number>();\n *\n * const result$ = trigger$.pipe(withBufferedFrom(data$));\n *\n * const valueHistory: (readonly [number, readonly string[]])[] = [];\n *\n * result$.subscribe(([triggerValue, bufferedData]) => {\n * valueHistory.push([triggerValue, bufferedData]);\n * });\n *\n * data$.next('A');\n *\n * data$.next('B');\n *\n * trigger$.next(1);\n *\n * assert.deepStrictEqual(valueHistory, [[1, ['A', 'B']]]);\n *\n * data$.next('C');\n *\n * trigger$.next(2);\n *\n * assert.deepStrictEqual(valueHistory, [\n * [1, ['A', 'B']],\n * [2, ['C']],\n * ]);\n * ```\n */\nexport const withBufferedFrom = <A, B>(\n observable: Observable<B>,\n): KeepInitialValueOperator<A, readonly [A, readonly B[]]> =>\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n ((parentObservable) =>\n new WithBufferedFromObservableClass(\n parentObservable,\n observable,\n )) as KeepInitialValueOperator<A, readonly [A, readonly B[]]>;\n\n/**\n * Alias for `withBufferedFrom`.\n * @see withBufferedFrom\n */\nexport const withBuffered = withBufferedFrom;\n\nclass WithBufferedFromObservableClass<A, B>\n extends SyncChildObservableClass<readonly [A, readonly B[]], readonly [A]>\n implements WithBufferedFromOperatorObservable<A, B>\n{\n #mut_bufferedValues: readonly B[] = [];\n\n constructor(parentObservable: Observable<A>, observable: Observable<B>) {\n super({\n parents: [parentObservable],\n depth: 1 + maxDepth([parentObservable, observable]),\n initialValue: pipe({\n par: parentObservable.getSnapshot(),\n me: observable.getSnapshot(),\n }).map(({ par, me }) =>\n Optional.isNone(par)\n ? Optional.none\n : Optional.some([\n par.value,\n Optional.isNone(me) ? [] : [me.value],\n ] as const),\n ).value,\n });\n\n observable.subscribe((value) => {\n this.#mut_bufferedValues = Arr.toPushed(this.#mut_bufferedValues, value);\n });\n }\n\n #clearBuffer(): void {\n this.#mut_bufferedValues = [];\n }\n\n override tryUpdate(updateToken: UpdateToken): void {\n const par = this.parents[0];\n\n const sn = par.getSnapshot();\n\n if (par.updateToken !== updateToken || Optional.isNone(sn)) {\n return; // skip update\n }\n\n this.setNext([sn.value, this.#mut_bufferedValues], updateToken);\n\n this.#clearBuffer();\n }\n}\n"],"names":[],"mappings":";;;;;AA+DO,MAAM,mBAAmB,CAC9B,UAAA;AAAA;AAAA,GAGC,CAAC,qBACA,IAAI,+BAAA;AAAA,IACF,gBAAA;AAAA,IACA;AAAA,GACF;AAAA;AAMG,MAAM,YAAA,GAAe;AAE5B,MAAM,wCACI,wBAAA,CAEV;AAAA,EACE,sBAAoC,EAAC;AAAA,EAErC,WAAA,CAAY,kBAAiC,UAAA,EAA2B;AACtE,IAAA,KAAA,CAAM;AAAA,MACJ,OAAA,EAAS,CAAC,gBAAgB,CAAA;AAAA,MAC1B,OAAO,CAAA,GAAI,QAAA,CAAS,CAAC,gBAAA,EAAkB,UAAU,CAAC,CAAA;AAAA,MAClD,cAAc,IAAA,CAAK;AAAA,QACjB,GAAA,EAAK,iBAAiB,WAAA,EAAY;AAAA,QAClC,EAAA,EAAI,WAAW,WAAA;AAAY,OAC5B,CAAA,CAAE,GAAA;AAAA,QAAI,CAAC,EAAE,GAAA,EAAK,EAAA,EAAG,KAChB,QAAA,CAAS,MAAA,CAAO,GAAG,CAAA,GACf,QAAA,CAAS,IAAA,GACT,QAAA,CAAS,IAAA,CAAK;AAAA,UACZ,GAAA,CAAI,KAAA;AAAA,UACJ,QAAA,CAAS,OAAO,EAAE,CAAA,GAAI,EAAC,GAAI,CAAC,GAAG,KAAK;AAAA,SAC5B;AAAA,OAChB,CAAE;AAAA,KACH,CAAA;AAED,IAAA,UAAA,CAAW,SAAA,CAAU,CAAC,KAAA,KAAU;AAC9B,MAAA,IAAA,CAAK,mBAAA,GAAsB,GAAA,CAAI,QAAA,CAAS,IAAA,CAAK,qBAAqB,KAAK,CAAA;AAAA,IACzE,CAAC,CAAA;AAAA,EACH;AAAA,EAEA,YAAA,GAAqB;AACnB,IAAA,IAAA,CAAK,sBAAsB,EAAC;AAAA,EAC9B;AAAA,EAES,UAAU,WAAA,EAAgC;AACjD,IAAA,MAAM,GAAA,GAAM,IAAA,CAAK,OAAA,CAAQ,CAAC,CAAA;AAE1B,IAAA,MAAM,EAAA,GAAK,IAAI,WAAA,EAAY;AAE3B,IAAA,IAAI,IAAI,WAAA,KAAgB,WAAA,IAAe,QAAA,CAAS,MAAA,CAAO,EAAE,CAAA,EAAG;AAC1D,MAAA;AAAA,IACF;AAEA,IAAA,IAAA,CAAK,QAAQ,CAAC,EAAA,CAAG,OAAO,IAAA,CAAK,mBAAmB,GAAG,WAAW,CAAA;AAE9D,IAAA,IAAA,CAAK,YAAA,EAAa;AAAA,EACpB;AACF;;;;"}
|
|
@@ -60,5 +60,5 @@ export declare const withCurrentValueFrom: <A, B>(observable: Observable<B>) =>
|
|
|
60
60
|
* Alias for `withCurrentValueFrom`.
|
|
61
61
|
* @see withCurrentValueFrom
|
|
62
62
|
*/
|
|
63
|
-
export declare const withLatestFrom:
|
|
63
|
+
export declare const withLatestFrom: typeof withCurrentValueFrom;
|
|
64
64
|
//# 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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuDG;AACH,eAAO,MAAM,oBAAoB,GAC9B,CAAC,EAAE,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuDG;AACH,eAAO,MAAM,oBAAoB,GAC9B,CAAC,EAAE,CAAC,cACS,UAAU,CAAC,CAAC,CAAC,KACxB,wBAAwB,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAEyB,CAAC;AAE1E;;;GAGG;AACH,eAAO,MAAM,cAAc,6BAAuB,CAAC"}
|
|
@@ -3,94 +3,33 @@ 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
|
|
21
|
-
* // result$ (skip) ["Bob",25] ["Charlie",30]
|
|
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 when the sampled observable (age$) emits
|
|
27
|
-
* // - Does not emit until both observables have emitted at least once
|
|
28
|
-
* // - "Alice" is skipped because age$ hasn't emitted yet
|
|
29
|
-
*
|
|
30
|
-
* const name$ = source<string>();
|
|
31
|
-
*
|
|
32
|
-
* const age$ = source<number>();
|
|
33
|
-
*
|
|
34
|
-
* const result$ = name$.pipe(withCurrentValueFrom(age$));
|
|
35
|
-
*
|
|
36
|
-
* const valueHistory: (readonly [string, number])[] = [];
|
|
37
|
-
*
|
|
38
|
-
* result$.subscribe(([name_, currentAge]) => {
|
|
39
|
-
* valueHistory.push([name_, currentAge]);
|
|
40
|
-
* });
|
|
41
|
-
*
|
|
42
|
-
* name$.next('Alice'); // nothing logged (age$ hasn't emitted)
|
|
43
|
-
*
|
|
44
|
-
* assert.deepStrictEqual(valueHistory, []);
|
|
45
|
-
*
|
|
46
|
-
* age$.next(25);
|
|
47
|
-
*
|
|
48
|
-
* name$.next('Bob'); // logs: Bob is 25 years old
|
|
49
|
-
*
|
|
50
|
-
* assert.deepStrictEqual(valueHistory, [['Bob', 25]]);
|
|
51
|
-
*
|
|
52
|
-
* age$.next(30);
|
|
53
|
-
*
|
|
54
|
-
* name$.next('Charlie'); // logs: Charlie is 30 years old
|
|
55
|
-
*
|
|
56
|
-
* assert.deepStrictEqual(valueHistory, [
|
|
57
|
-
* ['Bob', 25],
|
|
58
|
-
* ['Charlie', 30],
|
|
59
|
-
* ]);
|
|
60
|
-
* ```
|
|
61
|
-
*/
|
|
62
6
|
const withCurrentValueFrom = (observable) => (parentObservable) => new WithCurrentValueFromObservableClass(parentObservable, observable);
|
|
63
|
-
/**
|
|
64
|
-
* Alias for `withCurrentValueFrom`.
|
|
65
|
-
* @see withCurrentValueFrom
|
|
66
|
-
*/
|
|
67
7
|
const withLatestFrom = withCurrentValueFrom;
|
|
68
8
|
class WithCurrentValueFromObservableClass extends SyncChildObservableClass {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}
|
|
89
|
-
const curr = this.#observable.getSnapshot();
|
|
90
|
-
if (Optional.isNone(curr))
|
|
91
|
-
return; // skip update
|
|
92
|
-
this.setNext([ps.value, curr.value], updateToken);
|
|
9
|
+
#observable;
|
|
10
|
+
constructor(parentObservable, observable) {
|
|
11
|
+
super({
|
|
12
|
+
parents: [parentObservable],
|
|
13
|
+
depth: 1 + maxDepth([parentObservable, observable]),
|
|
14
|
+
initialValue: pipe({
|
|
15
|
+
par: parentObservable.getSnapshot(),
|
|
16
|
+
me: observable.getSnapshot()
|
|
17
|
+
}).map(
|
|
18
|
+
({ me, par }) => Optional.isNone(par) || Optional.isNone(me) ? Optional.none : Optional.some([par.value, me.value])
|
|
19
|
+
).value
|
|
20
|
+
});
|
|
21
|
+
this.#observable = observable;
|
|
22
|
+
}
|
|
23
|
+
tryUpdate(updateToken) {
|
|
24
|
+
const par = this.parents[0];
|
|
25
|
+
const ps = par.getSnapshot();
|
|
26
|
+
if (par.updateToken !== updateToken || Optional.isNone(ps)) {
|
|
27
|
+
return;
|
|
93
28
|
}
|
|
29
|
+
const curr = this.#observable.getSnapshot();
|
|
30
|
+
if (Optional.isNone(curr)) return;
|
|
31
|
+
this.setNext([ps.value, curr.value], updateToken);
|
|
32
|
+
}
|
|
94
33
|
}
|
|
95
34
|
|
|
96
35
|
export { withCurrentValueFrom, withLatestFrom };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"with-current-value-from.mjs","sources":["../../../src/core/operators/with-current-value-from.mts"],"sourcesContent":[
|
|
1
|
+
{"version":3,"file":"with-current-value-from.mjs","sources":["../../../src/core/operators/with-current-value-from.mts"],"sourcesContent":["import { Optional, pipe } from 'ts-data-forge';\nimport { SyncChildObservableClass } from '../class/index.mjs';\nimport {\n type DropInitialValueOperator,\n type Observable,\n type UpdateToken,\n type WithCurrentValueFromOperatorObservable,\n} from '../types/index.mjs';\nimport { maxDepth } from '../utils/index.mjs';\n\n/**\n * Samples the current value from another observable each time the source emits.\n * Emits a tuple of [sourceValue, sampledValue].\n *\n * @template A - The type of values from the source observable\n * @template B - The type of values from the sampled observable\n * @param observable - The observable to sample from\n * @returns An operator that emits tuples of source and sampled values\n *\n * @example\n * ```ts\n * // Timeline:\n * //\n * // name$ \"Alice\" \"Bob\" \"Charlie\"\n * // age$ 25 30\n * // result$ (skip) [\"Bob\",25] [\"Charlie\",30]\n * //\n * // Explanation:\n * // - withCurrentValueFrom samples the current value from another observable\n * // - Emits a tuple [sourceValue, sampledValue] each time the SOURCE emits\n * // - Does NOT emit when the sampled observable (age$) emits\n * // - Does not emit until both observables have emitted at least once\n * // - \"Alice\" is skipped because age$ hasn't emitted yet\n *\n * const name$ = source<string>();\n *\n * const age$ = source<number>();\n *\n * const result$ = name$.pipe(withCurrentValueFrom(age$));\n *\n * const valueHistory: (readonly [string, number])[] = [];\n *\n * result$.subscribe(([name_, currentAge]) => {\n * valueHistory.push([name_, currentAge]);\n * });\n *\n * name$.next('Alice'); // nothing logged (age$ hasn't emitted)\n *\n * assert.deepStrictEqual(valueHistory, []);\n *\n * age$.next(25);\n *\n * name$.next('Bob'); // logs: Bob is 25 years old\n *\n * assert.deepStrictEqual(valueHistory, [['Bob', 25]]);\n *\n * age$.next(30);\n *\n * name$.next('Charlie'); // logs: Charlie is 30 years old\n *\n * assert.deepStrictEqual(valueHistory, [\n * ['Bob', 25],\n * ['Charlie', 30],\n * ]);\n * ```\n */\nexport const withCurrentValueFrom =\n <A, B>(\n observable: Observable<B>,\n ): DropInitialValueOperator<A, readonly [A, B]> =>\n (parentObservable) =>\n new WithCurrentValueFromObservableClass(parentObservable, observable);\n\n/**\n * Alias for `withCurrentValueFrom`.\n * @see withCurrentValueFrom\n */\nexport const withLatestFrom = withCurrentValueFrom;\n\nclass WithCurrentValueFromObservableClass<A, B>\n extends SyncChildObservableClass<readonly [A, B], readonly [A]>\n implements WithCurrentValueFromOperatorObservable<A, B>\n{\n readonly #observable: Observable<B>;\n\n constructor(parentObservable: Observable<A>, observable: Observable<B>) {\n super({\n parents: [parentObservable],\n depth: 1 + maxDepth([parentObservable, observable]),\n initialValue: pipe({\n par: parentObservable.getSnapshot(),\n me: observable.getSnapshot(),\n }).map(({ me, par }) =>\n Optional.isNone(par) || Optional.isNone(me)\n ? Optional.none\n : Optional.some([par.value, me.value] as const),\n ).value,\n });\n\n this.#observable = observable;\n }\n\n override tryUpdate(updateToken: UpdateToken): void {\n const par = this.parents[0];\n\n const ps = par.getSnapshot();\n\n if (par.updateToken !== updateToken || Optional.isNone(ps)) {\n return; // skip update\n }\n\n const curr = this.#observable.getSnapshot();\n\n if (Optional.isNone(curr)) return; // skip update\n\n this.setNext([ps.value, curr.value], updateToken);\n }\n}\n"],"names":[],"mappings":";;;;;AAkEO,MAAM,oBAAA,GACX,CACE,UAAA,KAEF,CAAC,qBACC,IAAI,mCAAA,CAAoC,kBAAkB,UAAU;AAMjE,MAAM,cAAA,GAAiB;AAE9B,MAAM,4CACI,wBAAA,CAEV;AAAA,EACW,WAAA;AAAA,EAET,WAAA,CAAY,kBAAiC,UAAA,EAA2B;AACtE,IAAA,KAAA,CAAM;AAAA,MACJ,OAAA,EAAS,CAAC,gBAAgB,CAAA;AAAA,MAC1B,OAAO,CAAA,GAAI,QAAA,CAAS,CAAC,gBAAA,EAAkB,UAAU,CAAC,CAAA;AAAA,MAClD,cAAc,IAAA,CAAK;AAAA,QACjB,GAAA,EAAK,iBAAiB,WAAA,EAAY;AAAA,QAClC,EAAA,EAAI,WAAW,WAAA;AAAY,OAC5B,CAAA,CAAE,GAAA;AAAA,QAAI,CAAC,EAAE,EAAA,EAAI,GAAA,OACZ,QAAA,CAAS,MAAA,CAAO,GAAG,CAAA,IAAK,QAAA,CAAS,MAAA,CAAO,EAAE,CAAA,GACtC,QAAA,CAAS,OACT,QAAA,CAAS,IAAA,CAAK,CAAC,GAAA,CAAI,KAAA,EAAO,EAAA,CAAG,KAAK,CAAU;AAAA,OAClD,CAAE;AAAA,KACH,CAAA;AAED,IAAA,IAAA,CAAK,WAAA,GAAc,UAAA;AAAA,EACrB;AAAA,EAES,UAAU,WAAA,EAAgC;AACjD,IAAA,MAAM,GAAA,GAAM,IAAA,CAAK,OAAA,CAAQ,CAAC,CAAA;AAE1B,IAAA,MAAM,EAAA,GAAK,IAAI,WAAA,EAAY;AAE3B,IAAA,IAAI,IAAI,WAAA,KAAgB,WAAA,IAAe,QAAA,CAAS,MAAA,CAAO,EAAE,CAAA,EAAG;AAC1D,MAAA;AAAA,IACF;AAEA,IAAA,MAAM,IAAA,GAAO,IAAA,CAAK,WAAA,CAAY,WAAA,EAAY;AAE1C,IAAA,IAAI,QAAA,CAAS,MAAA,CAAO,IAAI,CAAA,EAAG;AAE3B,IAAA,IAAA,CAAK,QAAQ,CAAC,EAAA,CAAG,OAAO,IAAA,CAAK,KAAK,GAAG,WAAW,CAAA;AAAA,EAClD;AACF;;;;"}
|
|
@@ -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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AACH,eAAO,MAAM,gBAAgB,GAC1B,CAAC,EAAE,CAAC,GAAG,CAAC,
|
|
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,gBAAgB,CAAC,KAAG,wBAAwB,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAEO,CAAC"}
|
|
@@ -2,67 +2,22 @@ import { Optional } from 'ts-data-forge';
|
|
|
2
2
|
import { InitializedSyncChildObservableClass } from '../class/child-observable-class.mjs';
|
|
3
3
|
import '../utils/id-maker.mjs';
|
|
4
4
|
|
|
5
|
-
/**
|
|
6
|
-
* Provides an initial value for an observable that doesn't have one.
|
|
7
|
-
* The resulting observable will immediately emit the initial value upon subscription,
|
|
8
|
-
* and then emit all subsequent values from the source.
|
|
9
|
-
*
|
|
10
|
-
* @template A - The type of values from the source
|
|
11
|
-
* @template I - The type of the initial value (defaults to A)
|
|
12
|
-
* @param initialValue - The initial value to emit
|
|
13
|
-
* @returns An operator that sets the initial value
|
|
14
|
-
*
|
|
15
|
-
* @example
|
|
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
|
-
*
|
|
29
|
-
* const num$ = source<number>();
|
|
30
|
-
*
|
|
31
|
-
* const initialized$ = num$.pipe(withInitialValue(0));
|
|
32
|
-
*
|
|
33
|
-
* const valueHistory: number[] = [];
|
|
34
|
-
*
|
|
35
|
-
* initialized$.subscribe((x) => {
|
|
36
|
-
* valueHistory.push(x);
|
|
37
|
-
* });
|
|
38
|
-
*
|
|
39
|
-
* assert.deepStrictEqual(valueHistory, [0]);
|
|
40
|
-
*
|
|
41
|
-
* num$.next(1); // logs: 1
|
|
42
|
-
*
|
|
43
|
-
* assert.deepStrictEqual(valueHistory, [0, 1]);
|
|
44
|
-
*
|
|
45
|
-
* num$.next(2); // logs: 2
|
|
46
|
-
*
|
|
47
|
-
* assert.deepStrictEqual(valueHistory, [0, 1, 2]);
|
|
48
|
-
* ```
|
|
49
|
-
*/
|
|
50
5
|
const withInitialValue = (initialValue) => (parentObservable) => new WithInitialValueObservableClass(parentObservable, initialValue);
|
|
51
6
|
class WithInitialValueObservableClass extends InitializedSyncChildObservableClass {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}
|
|
64
|
-
this.setNext(sn.value, updateToken);
|
|
7
|
+
constructor(parentObservable, initialValue) {
|
|
8
|
+
super({
|
|
9
|
+
parents: [parentObservable],
|
|
10
|
+
initialValue: Optional.some(initialValue)
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
tryUpdate(updateToken) {
|
|
14
|
+
const par = this.parents[0];
|
|
15
|
+
const sn = par.getSnapshot();
|
|
16
|
+
if (par.updateToken !== updateToken || Optional.isNone(sn)) {
|
|
17
|
+
return;
|
|
65
18
|
}
|
|
19
|
+
this.setNext(sn.value, updateToken);
|
|
20
|
+
}
|
|
66
21
|
}
|
|
67
22
|
|
|
68
23
|
export { withInitialValue };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"with-initial-value.mjs","sources":["../../../src/core/operators/with-initial-value.mts"],"sourcesContent":[
|
|
1
|
+
{"version":3,"file":"with-initial-value.mjs","sources":["../../../src/core/operators/with-initial-value.mts"],"sourcesContent":["import { expectType, Optional } from 'ts-data-forge';\nimport { InitializedSyncChildObservableClass } from '../class/index.mjs';\nimport { source } from '../create/index.mjs';\nimport {\n type InitializedObservable,\n type Observable,\n type UpdateToken,\n type WithInitialValueOperator,\n type WithInitialValueOperatorObservable,\n} from '../types/index.mjs';\n\n/**\n * Provides an initial value for an observable that doesn't have one.\n * The resulting observable will immediately emit the initial value upon subscription,\n * and then emit all subsequent values from the source.\n *\n * @template A - The type of values from the source\n * @template I - The type of the initial value (defaults to A)\n * @param initialValue - The initial value to emit\n * @returns An operator that sets the initial value\n *\n * @example\n * ```ts\n * // Timeline:\n * //\n * // num$ 1 2 3\n * // withInitial$ 0 1 2 3\n * // ^\n * // initial value\n * //\n * // Explanation:\n * // - withInitialValue provides an initial value before the source emits\n * // - Converts an uninitialized observable to an initialized one\n * // - Useful when you need a default value immediately\n *\n * const num$ = source<number>();\n *\n * const initialized$ = num$.pipe(withInitialValue(0));\n *\n * const valueHistory: number[] = [];\n *\n * initialized$.subscribe((x) => {\n * valueHistory.push(x);\n * });\n *\n * assert.deepStrictEqual(valueHistory, [0]);\n *\n * num$.next(1); // logs: 1\n *\n * assert.deepStrictEqual(valueHistory, [0, 1]);\n *\n * num$.next(2); // logs: 2\n *\n * assert.deepStrictEqual(valueHistory, [0, 1, 2]);\n * ```\n */\nexport const withInitialValue =\n <A, I = A>(initialValue: I): WithInitialValueOperator<A, A | I> =>\n (parentObservable) =>\n new WithInitialValueObservableClass(parentObservable, initialValue);\n\nclass WithInitialValueObservableClass<A, I>\n extends InitializedSyncChildObservableClass<A | I, readonly [A]>\n implements WithInitialValueOperatorObservable<A, I>\n{\n constructor(parentObservable: Observable<A>, initialValue: I) {\n super({\n parents: [parentObservable],\n initialValue: Optional.some(initialValue),\n });\n }\n\n override tryUpdate(updateToken: UpdateToken): void {\n const par = this.parents[0];\n\n const sn = par.getSnapshot();\n\n if (par.updateToken !== updateToken || Optional.isNone(sn)) {\n return; // skip update\n }\n\n this.setNext(sn.value, updateToken);\n }\n}\n\nif (import.meta.vitest !== undefined) {\n test('type test', () => {\n expect(1).toBe(1); // dummy\n });\n\n {\n const s = source<number>();\n\n const _d: InitializedObservable<number> = s.pipe(withInitialValue(0));\n\n expectType<typeof _d, InitializedObservable<number>>('=');\n }\n}\n"],"names":[],"mappings":";;;;AAwDO,MAAM,gBAAA,GACX,CAAW,YAAA,KACX,CAAC,qBACC,IAAI,+BAAA,CAAgC,kBAAkB,YAAY;AAEtE,MAAM,wCACI,mCAAA,CAEV;AAAA,EACE,WAAA,CAAY,kBAAiC,YAAA,EAAiB;AAC5D,IAAA,KAAA,CAAM;AAAA,MACJ,OAAA,EAAS,CAAC,gBAAgB,CAAA;AAAA,MAC1B,YAAA,EAAc,QAAA,CAAS,IAAA,CAAK,YAAY;AAAA,KACzC,CAAA;AAAA,EAAA;AACH,EAES,UAAU,WAAA,EAAgC;AACjD,IAAA,MAAM,GAAA,GAAM,IAAA,CAAK,OAAA,CAAQ,CAAC,CAAA;AAE1B,IAAA,MAAM,EAAA,GAAK,IAAI,WAAA,EAAY;AAE3B,IAAA,IAAI,IAAI,WAAA,KAAgB,WAAA,IAAe,QAAA,CAAS,MAAA,CAAO,EAAE,CAAA,EAAG;AAC1D,MAAA;AAAA,IAAA;AAGF,IAAA,IAAA,CAAK,OAAA,CAAQ,EAAA,CAAG,KAAA,EAAO,WAAW,CAAA;AAAA,EAAA;AAEtC;;;;"}
|
|
@@ -54,5 +54,5 @@ export declare const withIndex: <A>() => KeepInitialValueOperator<A, readonly [S
|
|
|
54
54
|
* Alias for `withIndex`.
|
|
55
55
|
* @see withIndex
|
|
56
56
|
*/
|
|
57
|
-
export declare const attachIndex:
|
|
57
|
+
export declare const attachIndex: typeof withIndex;
|
|
58
58
|
//# sourceMappingURL=attach-index.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attach-index.d.mts","sourceRoot":"","sources":["../../../../src/core/predefined/operators/attach-index.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE9C,OAAO,EAAE,KAAK,wBAAwB,EAAE,MAAM,uBAAuB,CAAC;AAEtE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AACH,eAAO,MAAM,SAAS,GAAI,CAAC,OAAM,wBAAwB,CACvD,CAAC,EACD,SAAS,CAAC,QAAQ,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CACM,CAAC;AAEpC;;;GAGG;AACH,eAAO,MAAM,WAAW,
|
|
1
|
+
{"version":3,"file":"attach-index.d.mts","sourceRoot":"","sources":["../../../../src/core/predefined/operators/attach-index.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE9C,OAAO,EAAE,KAAK,wBAAwB,EAAE,MAAM,uBAAuB,CAAC;AAEtE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AACH,eAAO,MAAM,SAAS,GAAI,CAAC,OAAM,wBAAwB,CACvD,CAAC,EACD,SAAS,CAAC,QAAQ,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CACM,CAAC;AAEpC;;;GAGG;AACH,eAAO,MAAM,WAAW,kBAAY,CAAC"}
|
|
@@ -2,60 +2,7 @@ import 'ts-data-forge';
|
|
|
2
2
|
import '../../utils/id-maker.mjs';
|
|
3
3
|
import { map } from '../../operators/map.mjs';
|
|
4
4
|
|
|
5
|
-
/**
|
|
6
|
-
* Attaches a sequential index to each emitted value, producing `[index, value]` tuples.
|
|
7
|
-
* Index starts at 0 and increments with each emission.
|
|
8
|
-
*
|
|
9
|
-
* @template A - The type of values from the source
|
|
10
|
-
* @returns An operator that emits `[index, value]` tuples
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* ```ts
|
|
14
|
-
* // Timeline:
|
|
15
|
-
* //
|
|
16
|
-
* // letter$ "A" "B" "C"
|
|
17
|
-
* // indexed$ [0,"A"] [1,"B"] [2,"C"]
|
|
18
|
-
* //
|
|
19
|
-
* // Explanation:
|
|
20
|
-
* // - attachIndex attaches a sequential index to each emitted value
|
|
21
|
-
* // - Produces [index, value] tuples
|
|
22
|
-
* // - Index starts at 0 and increments with each emission
|
|
23
|
-
*
|
|
24
|
-
* const letter$ = source<string>();
|
|
25
|
-
*
|
|
26
|
-
* const indexed$ = letter$.pipe(attachIndex());
|
|
27
|
-
*
|
|
28
|
-
* const valueHistory: (readonly [number, string])[] = [];
|
|
29
|
-
*
|
|
30
|
-
* indexed$.subscribe(([i, letter]) => {
|
|
31
|
-
* valueHistory.push([i, letter]);
|
|
32
|
-
* });
|
|
33
|
-
*
|
|
34
|
-
* letter$.next('A');
|
|
35
|
-
*
|
|
36
|
-
* assert.deepStrictEqual(valueHistory, [[0, 'A']]);
|
|
37
|
-
*
|
|
38
|
-
* letter$.next('B');
|
|
39
|
-
*
|
|
40
|
-
* assert.deepStrictEqual(valueHistory, [
|
|
41
|
-
* [0, 'A'],
|
|
42
|
-
* [1, 'B'],
|
|
43
|
-
* ]);
|
|
44
|
-
*
|
|
45
|
-
* letter$.next('C');
|
|
46
|
-
*
|
|
47
|
-
* assert.deepStrictEqual(valueHistory, [
|
|
48
|
-
* [0, 'A'],
|
|
49
|
-
* [1, 'B'],
|
|
50
|
-
* [2, 'C'],
|
|
51
|
-
* ]);
|
|
52
|
-
* ```
|
|
53
|
-
*/
|
|
54
5
|
const withIndex = () => map((a, i) => [i, a]);
|
|
55
|
-
/**
|
|
56
|
-
* Alias for `withIndex`.
|
|
57
|
-
* @see withIndex
|
|
58
|
-
*/
|
|
59
6
|
const attachIndex = withIndex;
|
|
60
7
|
|
|
61
8
|
export { attachIndex, withIndex };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attach-index.mjs","sources":["../../../../src/core/predefined/operators/attach-index.mts"],"sourcesContent":[
|
|
1
|
+
{"version":3,"file":"attach-index.mjs","sources":["../../../../src/core/predefined/operators/attach-index.mts"],"sourcesContent":["import { type SafeUint } from 'ts-type-forge';\nimport { map } from '../../operators/index.mjs';\nimport { type KeepInitialValueOperator } from '../../types/index.mjs';\n\n/**\n * Attaches a sequential index to each emitted value, producing `[index, value]` tuples.\n * Index starts at 0 and increments with each emission.\n *\n * @template A - The type of values from the source\n * @returns An operator that emits `[index, value]` tuples\n *\n * @example\n * ```ts\n * // Timeline:\n * //\n * // letter$ \"A\" \"B\" \"C\"\n * // indexed$ [0,\"A\"] [1,\"B\"] [2,\"C\"]\n * //\n * // Explanation:\n * // - attachIndex attaches a sequential index to each emitted value\n * // - Produces [index, value] tuples\n * // - Index starts at 0 and increments with each emission\n *\n * const letter$ = source<string>();\n *\n * const indexed$ = letter$.pipe(attachIndex());\n *\n * const valueHistory: (readonly [number, string])[] = [];\n *\n * indexed$.subscribe(([i, letter]) => {\n * valueHistory.push([i, letter]);\n * });\n *\n * letter$.next('A');\n *\n * assert.deepStrictEqual(valueHistory, [[0, 'A']]);\n *\n * letter$.next('B');\n *\n * assert.deepStrictEqual(valueHistory, [\n * [0, 'A'],\n * [1, 'B'],\n * ]);\n *\n * letter$.next('C');\n *\n * assert.deepStrictEqual(valueHistory, [\n * [0, 'A'],\n * [1, 'B'],\n * [2, 'C'],\n * ]);\n * ```\n */\nexport const withIndex = <A,>(): KeepInitialValueOperator<\n A,\n readonly [SafeUint | -1, A]\n> => map((a, i) => [i, a] as const);\n\n/**\n * Alias for `withIndex`.\n * @see withIndex\n */\nexport const attachIndex = withIndex;\n"],"names":[],"mappings":";;;;AAqDO,MAAM,SAAA,GAAY,MAGpB,GAAA,CAAI,CAAC,GAAG,CAAA,KAAM,CAAC,CAAA,EAAG,CAAC,CAAU;AAM3B,MAAM,WAAA,GAAc;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"map-optional.d.mts","sourceRoot":"","sources":["../../../../src/core/predefined/operators/map-optional.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,KAAK,eAAe,EAAE,MAAM,eAAe,CAAC;AAE/D,OAAO,EAAE,KAAK,wBAAwB,EAAE,MAAM,uBAAuB,CAAC;AAEtE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,eAAO,MAAM,WAAW,GAAI,CAAC,SAAS,eAAe,EAAE,CAAC,
|
|
1
|
+
{"version":3,"file":"map-optional.d.mts","sourceRoot":"","sources":["../../../../src/core/predefined/operators/map-optional.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,KAAK,eAAe,EAAE,MAAM,eAAe,CAAC;AAE/D,OAAO,EAAE,KAAK,wBAAwB,EAAE,MAAM,uBAAuB,CAAC;AAEtE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,eAAO,MAAM,WAAW,GAAI,CAAC,SAAS,eAAe,EAAE,CAAC,SAC/C,CAAC,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,KAClC,wBAAwB,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,CAA6B,CAAC"}
|
|
@@ -2,54 +2,7 @@ import { Optional } from 'ts-data-forge';
|
|
|
2
2
|
import '../../utils/id-maker.mjs';
|
|
3
3
|
import { map } from '../../operators/map.mjs';
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
* Transforms the inner value of an `Optional` type emitted by the source.
|
|
7
|
-
* If the value is `Some`, the mapping function is applied; if `None`, it remains `None`.
|
|
8
|
-
*
|
|
9
|
-
* @template O - The Optional type from the source
|
|
10
|
-
* @template B - The type of the mapped inner value
|
|
11
|
-
* @param mapFn - A function to transform the unwrapped value
|
|
12
|
-
* @returns An operator that maps the inner value of Optional emissions
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* ```ts
|
|
16
|
-
* // Timeline:
|
|
17
|
-
* //
|
|
18
|
-
* // value$ Some(2) None Some(5)
|
|
19
|
-
* // doubled$ Some(4) None Some(10)
|
|
20
|
-
* //
|
|
21
|
-
* // Explanation:
|
|
22
|
-
* // - mapOptional transforms the inner value of Optional emissions
|
|
23
|
-
* // - Some values are mapped; None values pass through unchanged
|
|
24
|
-
*
|
|
25
|
-
* const value$ = source<Optional<number>>();
|
|
26
|
-
*
|
|
27
|
-
* const doubled$ = value$.pipe(mapOptional((x) => x * 2));
|
|
28
|
-
*
|
|
29
|
-
* const valueHistory: Optional<number>[] = [];
|
|
30
|
-
*
|
|
31
|
-
* doubled$.subscribe((v) => {
|
|
32
|
-
* valueHistory.push(v);
|
|
33
|
-
* });
|
|
34
|
-
*
|
|
35
|
-
* value$.next(Optional.some(2));
|
|
36
|
-
*
|
|
37
|
-
* assert.deepStrictEqual(valueHistory, [Optional.some(4)]);
|
|
38
|
-
*
|
|
39
|
-
* value$.next(Optional.none);
|
|
40
|
-
*
|
|
41
|
-
* assert.deepStrictEqual(valueHistory, [Optional.some(4), Optional.none]);
|
|
42
|
-
*
|
|
43
|
-
* value$.next(Optional.some(5));
|
|
44
|
-
*
|
|
45
|
-
* assert.deepStrictEqual(valueHistory, [
|
|
46
|
-
* Optional.some(4),
|
|
47
|
-
* Optional.none,
|
|
48
|
-
* Optional.some(10),
|
|
49
|
-
* ]);
|
|
50
|
-
* ```
|
|
51
|
-
*/
|
|
52
|
-
const mapOptional = (mapFn) => map((a) => Optional.map(a, mapFn));
|
|
5
|
+
const mapOptional = (mapFn) => map(Optional.map(mapFn));
|
|
53
6
|
|
|
54
7
|
export { mapOptional };
|
|
55
8
|
//# sourceMappingURL=map-optional.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"map-optional.mjs","sources":["../../../../src/core/predefined/operators/map-optional.mts"],"sourcesContent":[
|
|
1
|
+
{"version":3,"file":"map-optional.mjs","sources":["../../../../src/core/predefined/operators/map-optional.mts"],"sourcesContent":["import { Optional, type UnknownOptional } from 'ts-data-forge';\nimport { map } from '../../operators/index.mjs';\nimport { type KeepInitialValueOperator } from '../../types/index.mjs';\n\n/**\n * Transforms the inner value of an `Optional` type emitted by the source.\n * If the value is `Some`, the mapping function is applied; if `None`, it remains `None`.\n *\n * @template O - The Optional type from the source\n * @template B - The type of the mapped inner value\n * @param mapFn - A function to transform the unwrapped value\n * @returns An operator that maps the inner value of Optional emissions\n *\n * @example\n * ```ts\n * // Timeline:\n * //\n * // value$ Some(2) None Some(5)\n * // doubled$ Some(4) None Some(10)\n * //\n * // Explanation:\n * // - mapOptional transforms the inner value of Optional emissions\n * // - Some values are mapped; None values pass through unchanged\n *\n * const value$ = source<Optional<number>>();\n *\n * const doubled$ = value$.pipe(mapOptional((x) => x * 2));\n *\n * const valueHistory: Optional<number>[] = [];\n *\n * doubled$.subscribe((v) => {\n * valueHistory.push(v);\n * });\n *\n * value$.next(Optional.some(2));\n *\n * assert.deepStrictEqual(valueHistory, [Optional.some(4)]);\n *\n * value$.next(Optional.none);\n *\n * assert.deepStrictEqual(valueHistory, [Optional.some(4), Optional.none]);\n *\n * value$.next(Optional.some(5));\n *\n * assert.deepStrictEqual(valueHistory, [\n * Optional.some(4),\n * Optional.none,\n * Optional.some(10),\n * ]);\n * ```\n */\nexport const mapOptional = <O extends UnknownOptional, B>(\n mapFn: (x: Optional.Unwrap<O>) => B,\n): KeepInitialValueOperator<O, Optional<B>> => map(Optional.map(mapFn));\n"],"names":[],"mappings":";;;;AAmDO,MAAM,cAAc,CACzB,KAAA,KAC6C,IAAI,QAAA,CAAS,GAAA,CAAI,KAAK,CAAC;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"map-result-err.d.mts","sourceRoot":"","sources":["../../../../src/core/predefined/operators/map-result-err.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,KAAK,aAAa,EAAE,MAAM,eAAe,CAAC;AAE3D,OAAO,EAAE,KAAK,wBAAwB,EAAE,MAAM,uBAAuB,CAAC;AAEtE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,eAAO,MAAM,YAAY,GAAI,CAAC,SAAS,aAAa,EAAE,EAAE,
|
|
1
|
+
{"version":3,"file":"map-result-err.d.mts","sourceRoot":"","sources":["../../../../src/core/predefined/operators/map-result-err.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,KAAK,aAAa,EAAE,MAAM,eAAe,CAAC;AAE3D,OAAO,EAAE,KAAK,wBAAwB,EAAE,MAAM,uBAAuB,CAAC;AAEtE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,eAAO,MAAM,YAAY,GAAI,CAAC,SAAS,aAAa,EAAE,EAAE,SAC/C,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,CAClC,CAAC"}
|