synstate 0.1.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 +878 -0
- package/dist/core/class/child-observable-class.d.mts +37 -0
- package/dist/core/class/child-observable-class.d.mts.map +1 -0
- package/dist/core/class/child-observable-class.mjs +134 -0
- package/dist/core/class/child-observable-class.mjs.map +1 -0
- package/dist/core/class/index.d.mts +4 -0
- package/dist/core/class/index.d.mts.map +1 -0
- package/dist/core/class/index.mjs +4 -0
- package/dist/core/class/index.mjs.map +1 -0
- package/dist/core/class/observable-base-class.d.mts +28 -0
- package/dist/core/class/observable-base-class.d.mts.map +1 -0
- package/dist/core/class/observable-base-class.mjs +116 -0
- package/dist/core/class/observable-base-class.mjs.map +1 -0
- package/dist/core/class/root-observable-class.d.mts +12 -0
- package/dist/core/class/root-observable-class.d.mts.map +1 -0
- package/dist/core/class/root-observable-class.mjs +35 -0
- package/dist/core/class/root-observable-class.mjs.map +1 -0
- package/dist/core/combine/combine.d.mts +35 -0
- package/dist/core/combine/combine.d.mts.map +1 -0
- package/dist/core/combine/combine.mjs +94 -0
- package/dist/core/combine/combine.mjs.map +1 -0
- package/dist/core/combine/index.d.mts +4 -0
- package/dist/core/combine/index.d.mts.map +1 -0
- package/dist/core/combine/index.mjs +4 -0
- package/dist/core/combine/index.mjs.map +1 -0
- package/dist/core/combine/merge.d.mts +28 -0
- package/dist/core/combine/merge.d.mts.map +1 -0
- package/dist/core/combine/merge.mjs +52 -0
- package/dist/core/combine/merge.mjs.map +1 -0
- package/dist/core/combine/zip.d.mts +26 -0
- package/dist/core/combine/zip.d.mts.map +1 -0
- package/dist/core/combine/zip.mjs +63 -0
- package/dist/core/combine/zip.mjs.map +1 -0
- package/dist/core/create/from-array.d.mts +21 -0
- package/dist/core/create/from-array.d.mts.map +1 -0
- package/dist/core/create/from-array.mjs +47 -0
- package/dist/core/create/from-array.mjs.map +1 -0
- package/dist/core/create/from-promise.d.mts +25 -0
- package/dist/core/create/from-promise.d.mts.map +1 -0
- package/dist/core/create/from-promise.mjs +51 -0
- package/dist/core/create/from-promise.mjs.map +1 -0
- package/dist/core/create/from-subscribable.d.mts +3 -0
- package/dist/core/create/from-subscribable.d.mts.map +1 -0
- package/dist/core/create/from-subscribable.mjs +22 -0
- package/dist/core/create/from-subscribable.mjs.map +1 -0
- package/dist/core/create/index.d.mts +8 -0
- package/dist/core/create/index.d.mts.map +1 -0
- package/dist/core/create/index.mjs +8 -0
- package/dist/core/create/index.mjs.map +1 -0
- package/dist/core/create/interval.d.mts +21 -0
- package/dist/core/create/interval.d.mts.map +1 -0
- package/dist/core/create/interval.mjs +74 -0
- package/dist/core/create/interval.mjs.map +1 -0
- package/dist/core/create/of.d.mts +20 -0
- package/dist/core/create/of.d.mts.map +1 -0
- package/dist/core/create/of.mjs +44 -0
- package/dist/core/create/of.mjs.map +1 -0
- package/dist/core/create/source.d.mts +29 -0
- package/dist/core/create/source.d.mts.map +1 -0
- package/dist/core/create/source.mjs +29 -0
- package/dist/core/create/source.mjs.map +1 -0
- package/dist/core/create/timer.d.mts +20 -0
- package/dist/core/create/timer.d.mts.map +1 -0
- package/dist/core/create/timer.mjs +64 -0
- package/dist/core/create/timer.mjs.map +1 -0
- package/dist/core/index.d.mts +7 -0
- package/dist/core/index.d.mts.map +1 -0
- package/dist/core/index.mjs +37 -0
- package/dist/core/index.mjs.map +1 -0
- package/dist/core/operators/audit-time.d.mts +3 -0
- package/dist/core/operators/audit-time.d.mts.map +1 -0
- package/dist/core/operators/audit-time.mjs +50 -0
- package/dist/core/operators/audit-time.mjs.map +1 -0
- package/dist/core/operators/debounce-time.d.mts +31 -0
- package/dist/core/operators/debounce-time.d.mts.map +1 -0
- package/dist/core/operators/debounce-time.mjs +73 -0
- package/dist/core/operators/debounce-time.mjs.map +1 -0
- package/dist/core/operators/filter.d.mts +28 -0
- package/dist/core/operators/filter.d.mts.map +1 -0
- package/dist/core/operators/filter.mjs +38 -0
- package/dist/core/operators/filter.mjs.map +1 -0
- package/dist/core/operators/index.d.mts +18 -0
- package/dist/core/operators/index.d.mts.map +1 -0
- package/dist/core/operators/index.mjs +18 -0
- package/dist/core/operators/index.mjs.map +1 -0
- package/dist/core/operators/map-with-index.d.mts +39 -0
- package/dist/core/operators/map-with-index.d.mts.map +1 -0
- package/dist/core/operators/map-with-index.mjs +73 -0
- package/dist/core/operators/map-with-index.mjs.map +1 -0
- package/dist/core/operators/merge-map.d.mts +34 -0
- package/dist/core/operators/merge-map.d.mts.map +1 -0
- package/dist/core/operators/merge-map.mjs +75 -0
- package/dist/core/operators/merge-map.mjs.map +1 -0
- package/dist/core/operators/pairwise.d.mts +27 -0
- package/dist/core/operators/pairwise.d.mts.map +1 -0
- package/dist/core/operators/pairwise.mjs +59 -0
- package/dist/core/operators/pairwise.mjs.map +1 -0
- package/dist/core/operators/scan.d.mts +30 -0
- package/dist/core/operators/scan.d.mts.map +1 -0
- package/dist/core/operators/scan.mjs +56 -0
- package/dist/core/operators/scan.mjs.map +1 -0
- package/dist/core/operators/skip-if-no-change.d.mts +33 -0
- package/dist/core/operators/skip-if-no-change.d.mts.map +1 -0
- package/dist/core/operators/skip-if-no-change.mjs +68 -0
- package/dist/core/operators/skip-if-no-change.mjs.map +1 -0
- package/dist/core/operators/skip-until.d.mts +3 -0
- package/dist/core/operators/skip-until.d.mts.map +1 -0
- package/dist/core/operators/skip-until.mjs +33 -0
- package/dist/core/operators/skip-until.mjs.map +1 -0
- package/dist/core/operators/skip-while.d.mts +4 -0
- package/dist/core/operators/skip-while.d.mts.map +1 -0
- package/dist/core/operators/skip-while.mjs +40 -0
- package/dist/core/operators/skip-while.mjs.map +1 -0
- package/dist/core/operators/switch-map.d.mts +31 -0
- package/dist/core/operators/switch-map.d.mts.map +1 -0
- package/dist/core/operators/switch-map.mjs +70 -0
- package/dist/core/operators/switch-map.mjs.map +1 -0
- package/dist/core/operators/take-until.d.mts +32 -0
- package/dist/core/operators/take-until.d.mts.map +1 -0
- package/dist/core/operators/take-until.mjs +60 -0
- package/dist/core/operators/take-until.mjs.map +1 -0
- package/dist/core/operators/take-while.d.mts +4 -0
- package/dist/core/operators/take-while.d.mts.map +1 -0
- package/dist/core/operators/take-while.mjs +42 -0
- package/dist/core/operators/take-while.mjs.map +1 -0
- package/dist/core/operators/throttle-time.d.mts +23 -0
- package/dist/core/operators/throttle-time.d.mts.map +1 -0
- package/dist/core/operators/throttle-time.mjs +68 -0
- package/dist/core/operators/throttle-time.mjs.map +1 -0
- package/dist/core/operators/with-buffered-from.d.mts +4 -0
- package/dist/core/operators/with-buffered-from.d.mts.map +1 -0
- package/dist/core/operators/with-buffered-from.mjs +45 -0
- package/dist/core/operators/with-buffered-from.mjs.map +1 -0
- package/dist/core/operators/with-current-value-from.d.mts +4 -0
- package/dist/core/operators/with-current-value-from.d.mts.map +1 -0
- package/dist/core/operators/with-current-value-from.mjs +37 -0
- package/dist/core/operators/with-current-value-from.mjs.map +1 -0
- package/dist/core/operators/with-initial-value.d.mts +26 -0
- package/dist/core/operators/with-initial-value.d.mts.map +1 -0
- package/dist/core/operators/with-initial-value.mjs +47 -0
- package/dist/core/operators/with-initial-value.mjs.map +1 -0
- package/dist/core/types/id.d.mts +4 -0
- package/dist/core/types/id.d.mts.map +1 -0
- package/dist/core/types/id.mjs +2 -0
- package/dist/core/types/id.mjs.map +1 -0
- package/dist/core/types/index.d.mts +6 -0
- package/dist/core/types/index.d.mts.map +1 -0
- package/dist/core/types/index.mjs +3 -0
- package/dist/core/types/index.mjs.map +1 -0
- package/dist/core/types/observable-family.d.mts +68 -0
- package/dist/core/types/observable-family.d.mts.map +1 -0
- package/dist/core/types/observable-family.mjs +2 -0
- package/dist/core/types/observable-family.mjs.map +1 -0
- package/dist/core/types/observable-kind.d.mts +4 -0
- package/dist/core/types/observable-kind.d.mts.map +1 -0
- package/dist/core/types/observable-kind.mjs +2 -0
- package/dist/core/types/observable-kind.mjs.map +1 -0
- package/dist/core/types/observable.d.mts +83 -0
- package/dist/core/types/observable.d.mts.map +1 -0
- package/dist/core/types/observable.mjs +10 -0
- package/dist/core/types/observable.mjs.map +1 -0
- package/dist/core/types/types.d.mts +16 -0
- package/dist/core/types/types.d.mts.map +1 -0
- package/dist/core/types/types.mjs +2 -0
- package/dist/core/types/types.mjs.map +1 -0
- package/dist/core/utils/id-maker.d.mts +5 -0
- package/dist/core/utils/id-maker.d.mts.map +1 -0
- package/dist/core/utils/id-maker.mjs +17 -0
- package/dist/core/utils/id-maker.mjs.map +1 -0
- package/dist/core/utils/index.d.mts +5 -0
- package/dist/core/utils/index.d.mts.map +1 -0
- package/dist/core/utils/index.mjs +5 -0
- package/dist/core/utils/index.mjs.map +1 -0
- package/dist/core/utils/max-depth.d.mts +3 -0
- package/dist/core/utils/max-depth.d.mts.map +1 -0
- package/dist/core/utils/max-depth.mjs +8 -0
- package/dist/core/utils/max-depth.mjs.map +1 -0
- package/dist/core/utils/observable-utils.d.mts +3 -0
- package/dist/core/utils/observable-utils.d.mts.map +1 -0
- package/dist/core/utils/observable-utils.mjs +7 -0
- package/dist/core/utils/observable-utils.mjs.map +1 -0
- package/dist/core/utils/utils.d.mts +4 -0
- package/dist/core/utils/utils.d.mts.map +1 -0
- package/dist/core/utils/utils.mjs +38 -0
- package/dist/core/utils/utils.mjs.map +1 -0
- package/dist/entry-point.d.mts +2 -0
- package/dist/entry-point.d.mts.map +1 -0
- package/dist/entry-point.mjs +40 -0
- package/dist/entry-point.mjs.map +1 -0
- package/dist/globals.d.mts +4 -0
- package/dist/index.d.mts +3 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +40 -0
- package/dist/index.mjs.map +1 -0
- package/dist/tsconfig.json +1 -0
- package/dist/types.d.mts +2 -0
- package/dist/utils/create-event-emitter.d.mts +39 -0
- package/dist/utils/create-event-emitter.d.mts.map +1 -0
- package/dist/utils/create-event-emitter.mjs +57 -0
- package/dist/utils/create-event-emitter.mjs.map +1 -0
- package/dist/utils/create-reducer.d.mts +34 -0
- package/dist/utils/create-reducer.d.mts.map +1 -0
- package/dist/utils/create-reducer.mjs +49 -0
- package/dist/utils/create-reducer.mjs.map +1 -0
- package/dist/utils/create-state.d.mts +61 -0
- package/dist/utils/create-state.d.mts.map +1 -0
- package/dist/utils/create-state.mjs +92 -0
- package/dist/utils/create-state.mjs.map +1 -0
- package/dist/utils/index.d.mts +4 -0
- package/dist/utils/index.d.mts.map +1 -0
- package/dist/utils/index.mjs +4 -0
- package/dist/utils/index.mjs.map +1 -0
- package/package.json +71 -0
- package/src/core/class/child-observable-class.mts +232 -0
- package/src/core/class/index.mts +3 -0
- package/src/core/class/observable-base-class.mts +186 -0
- package/src/core/class/observable.class.test.mts +89 -0
- package/src/core/class/root-observable-class.mts +68 -0
- package/src/core/combine/combine.mts +144 -0
- package/src/core/combine/index.mts +3 -0
- package/src/core/combine/merge.mts +84 -0
- package/src/core/combine/zip.mts +149 -0
- package/src/core/create/from-array.mts +58 -0
- package/src/core/create/from-promise.mts +58 -0
- package/src/core/create/from-subscribable.mts +37 -0
- package/src/core/create/index.mts +7 -0
- package/src/core/create/interval.mts +99 -0
- package/src/core/create/of.mts +54 -0
- package/src/core/create/source.mts +59 -0
- package/src/core/create/timer.mts +84 -0
- package/src/core/index.mts +6 -0
- package/src/core/operators/audit-time.mts +77 -0
- package/src/core/operators/debounce-time.mts +96 -0
- package/src/core/operators/filter.mts +125 -0
- package/src/core/operators/index.mts +17 -0
- package/src/core/operators/map-with-index.mts +168 -0
- package/src/core/operators/merge-map.mts +108 -0
- package/src/core/operators/pairwise.mts +77 -0
- package/src/core/operators/scan.mts +81 -0
- package/src/core/operators/skip-if-no-change.mts +91 -0
- package/src/core/operators/skip-until.mts +54 -0
- package/src/core/operators/skip-while.mts +77 -0
- package/src/core/operators/switch-map.mts +101 -0
- package/src/core/operators/take-until.mts +80 -0
- package/src/core/operators/take-while.mts +103 -0
- package/src/core/operators/throttle-time.mts +95 -0
- package/src/core/operators/with-buffered-from.mts +68 -0
- package/src/core/operators/with-current-value-from.mts +58 -0
- package/src/core/operators/with-initial-value.mts +76 -0
- package/src/core/types/id.mts +5 -0
- package/src/core/types/index.mts +5 -0
- package/src/core/types/observable-family.mts +259 -0
- package/src/core/types/observable-kind.mts +5 -0
- package/src/core/types/observable.mts +218 -0
- package/src/core/types/types.mts +40 -0
- package/src/core/utils/id-maker.mts +31 -0
- package/src/core/utils/index.mts +4 -0
- package/src/core/utils/max-depth.mts +7 -0
- package/src/core/utils/observable-utils.mts +10 -0
- package/src/core/utils/utils.mts +51 -0
- package/src/core/utils/utils.test.mts +88 -0
- package/src/entry-point.mts +1 -0
- package/src/globals.d.mts +4 -0
- package/src/index.mts +2 -0
- package/src/utils/create-event-emitter.mts +62 -0
- package/src/utils/create-reducer.mts +55 -0
- package/src/utils/create-state.mts +138 -0
- package/src/utils/index.mts +3 -0
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { Optional, Arr } from 'ts-data-forge';
|
|
2
|
+
import { AsyncChildObservableClass } from '../class/child-observable-class.mjs';
|
|
3
|
+
import '../utils/id-maker.mjs';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Projects each source value to an observable and merges all inner observables.
|
|
7
|
+
* Unlike `switchMap`, does not cancel previous inner observables.
|
|
8
|
+
*
|
|
9
|
+
* @template A - The type of values from the source
|
|
10
|
+
* @template B - The type of values from the projected observable
|
|
11
|
+
* @param mapToObservable - A function that maps each source value to an observable
|
|
12
|
+
* @returns An operator that merges mapped observables
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* const ids$ = source<number>();
|
|
17
|
+
*
|
|
18
|
+
* const users$ = ids$.pipe(mergeMap((id) => fromPromise(fetchUser(id))));
|
|
19
|
+
*
|
|
20
|
+
* users$.subscribe((user) => {
|
|
21
|
+
* console.log(user);
|
|
22
|
+
* });
|
|
23
|
+
* // All requests run in parallel, results merged as they arrive
|
|
24
|
+
*
|
|
25
|
+
* const fetchUser = async (id: number): Promise<unknown> => ({ id });
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* @note To improve code readability, consider using `createState` instead of `mergeMap`,
|
|
29
|
+
* subscribing to `parentObservable` and calling `setState` within it.
|
|
30
|
+
*/
|
|
31
|
+
const mergeMap = (mapToObservable) => (parentObservable) => new MergeMapObservableClass(parentObservable, mapToObservable);
|
|
32
|
+
/**
|
|
33
|
+
* Alias for `mergeMap()`.
|
|
34
|
+
* @see mergeMap
|
|
35
|
+
*/
|
|
36
|
+
const flatMap = mergeMap;
|
|
37
|
+
class MergeMapObservableClass extends AsyncChildObservableClass {
|
|
38
|
+
#mapToObservable;
|
|
39
|
+
#mut_observables;
|
|
40
|
+
#mut_subscriptions;
|
|
41
|
+
constructor(parentObservable, mapToObservable) {
|
|
42
|
+
super({
|
|
43
|
+
parents: [parentObservable],
|
|
44
|
+
initialValue: Optional.none,
|
|
45
|
+
});
|
|
46
|
+
this.#mapToObservable = mapToObservable;
|
|
47
|
+
this.#mut_observables = [];
|
|
48
|
+
this.#mut_subscriptions = [];
|
|
49
|
+
}
|
|
50
|
+
tryUpdate(updaterSymbol) {
|
|
51
|
+
const par = this.parents[0];
|
|
52
|
+
const sn = par.getSnapshot();
|
|
53
|
+
if (par.updaterSymbol !== updaterSymbol || Optional.isNone(sn)) {
|
|
54
|
+
return; // skip update
|
|
55
|
+
}
|
|
56
|
+
const observable = this.#mapToObservable(sn.value);
|
|
57
|
+
this.#mut_observables = Arr.toPushed(this.#mut_observables, observable);
|
|
58
|
+
const subscription = observable.subscribe((curr) => {
|
|
59
|
+
this.startUpdate(curr);
|
|
60
|
+
});
|
|
61
|
+
this.#mut_subscriptions = Arr.toPushed(this.#mut_subscriptions, subscription);
|
|
62
|
+
}
|
|
63
|
+
complete() {
|
|
64
|
+
for (const s of this.#mut_subscriptions) {
|
|
65
|
+
s.unsubscribe();
|
|
66
|
+
}
|
|
67
|
+
for (const o of this.#mut_observables) {
|
|
68
|
+
o.complete();
|
|
69
|
+
}
|
|
70
|
+
super.complete();
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export { flatMap, mergeMap };
|
|
75
|
+
//# sourceMappingURL=merge-map.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"merge-map.mjs","sources":["../../../src/core/operators/merge-map.mts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAUA;;;;;;;;;;;;;;;;;;;;;;;;;AAyBG;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,aAA4B,EAAA;QAC7C,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;AAE3B,QAAA,MAAM,EAAE,GAAG,GAAG,CAAC,WAAW,EAAE;AAE5B,QAAA,IAAI,GAAG,CAAC,aAAa,KAAK,aAAa,IAAI,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE;AAC9D,YAAA,OAAO;QACT;QAEA,MAAM,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;;;;"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type DropInitialValueOperator } from '../types/index.mjs';
|
|
2
|
+
/**
|
|
3
|
+
* Emits the previous and current values as a pair.
|
|
4
|
+
* Does not emit until the source has emitted at least twice.
|
|
5
|
+
*
|
|
6
|
+
* @template A - The type of values from the source
|
|
7
|
+
* @returns An operator that pairs consecutive values
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* const num$ = source<number>();
|
|
12
|
+
*
|
|
13
|
+
* const pairs$ = num$.pipe(pairwise());
|
|
14
|
+
*
|
|
15
|
+
* pairs$.subscribe(([prev, curr]) => {
|
|
16
|
+
* console.log(prev, curr);
|
|
17
|
+
* });
|
|
18
|
+
*
|
|
19
|
+
* num$.next(1); // nothing logged
|
|
20
|
+
*
|
|
21
|
+
* num$.next(2); // logs: 1, 2
|
|
22
|
+
*
|
|
23
|
+
* num$.next(3); // logs: 2, 3
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export declare const pairwise: <A>() => DropInitialValueOperator<A, readonly [A, A]>;
|
|
27
|
+
//# sourceMappingURL=pairwise.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pairwise.d.mts","sourceRoot":"","sources":["../../../src/core/operators/pairwise.mts"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,wBAAwB,EAI9B,MAAM,oBAAoB,CAAC;AAE5B;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,eAAO,MAAM,QAAQ,GAAI,CAAC,OAAM,wBAAwB,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CACxE,CAAC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
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 previous and current values as a pair.
|
|
7
|
+
* Does not emit until the source has emitted at least twice.
|
|
8
|
+
*
|
|
9
|
+
* @template A - The type of values from the source
|
|
10
|
+
* @returns An operator that pairs consecutive values
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* const num$ = source<number>();
|
|
15
|
+
*
|
|
16
|
+
* const pairs$ = num$.pipe(pairwise());
|
|
17
|
+
*
|
|
18
|
+
* pairs$.subscribe(([prev, curr]) => {
|
|
19
|
+
* console.log(prev, curr);
|
|
20
|
+
* });
|
|
21
|
+
*
|
|
22
|
+
* num$.next(1); // nothing logged
|
|
23
|
+
*
|
|
24
|
+
* num$.next(2); // logs: 1, 2
|
|
25
|
+
*
|
|
26
|
+
* num$.next(3); // logs: 2, 3
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
const pairwise = () => f;
|
|
30
|
+
const f = (parentObservable) => new PairwiseObservableClass(parentObservable);
|
|
31
|
+
class PairwiseObservableClass extends SyncChildObservableClass {
|
|
32
|
+
#mut_previousValue;
|
|
33
|
+
constructor(parentObservable) {
|
|
34
|
+
super({
|
|
35
|
+
parents: [parentObservable],
|
|
36
|
+
initialValue: Optional.none,
|
|
37
|
+
});
|
|
38
|
+
// parentObservable.snapshot has value
|
|
39
|
+
// if parentObservable is InitializedObservable
|
|
40
|
+
this.#mut_previousValue = parentObservable.getSnapshot();
|
|
41
|
+
}
|
|
42
|
+
tryUpdate(updaterSymbol) {
|
|
43
|
+
const par = this.parents[0];
|
|
44
|
+
const sn = par.getSnapshot();
|
|
45
|
+
if (par.updaterSymbol !== updaterSymbol || Optional.isNone(sn)) {
|
|
46
|
+
return; // skip update
|
|
47
|
+
}
|
|
48
|
+
const prev = this.#mut_previousValue;
|
|
49
|
+
const cond = !Optional.isNone(prev);
|
|
50
|
+
// NOTE: Must update before setNext, otherwise Optional.isNone(prev) remains true when tryUpdate is called consecutively
|
|
51
|
+
this.#mut_previousValue = par.getSnapshot();
|
|
52
|
+
if (cond) {
|
|
53
|
+
this.setNext([prev.value, sn.value], updaterSymbol);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export { pairwise };
|
|
59
|
+
//# sourceMappingURL=pairwise.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pairwise.mjs","sources":["../../../src/core/operators/pairwise.mts"],"sourcesContent":[null],"names":[],"mappings":";;;;AASA;;;;;;;;;;;;;;;;;;;;;;;AAuBG;MACU,QAAQ,GAAG,MACtB;AAEF,MAAM,CAAC,GAAG,CAAK,gBAA+B,KAC5C,IAAI,uBAAuB,CAAC,gBAAgB,CAAC;AAE/C,MAAM,uBACJ,SAAQ,wBAAuD,CAAA;AAG/D,IAAA,kBAAkB;AAElB,IAAA,WAAA,CAAY,gBAA+B,EAAA;AACzC,QAAA,KAAK,CAAC;YACJ,OAAO,EAAE,CAAC,gBAAgB,CAAC;YAC3B,YAAY,EAAE,QAAQ,CAAC,IAAI;AAC5B,SAAA,CAAC;;;AAIF,QAAA,IAAI,CAAC,kBAAkB,GAAG,gBAAgB,CAAC,WAAW,EAAE;IAC1D;AAES,IAAA,SAAS,CAAC,aAA4B,EAAA;QAC7C,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;AAE3B,QAAA,MAAM,EAAE,GAAG,GAAG,CAAC,WAAW,EAAE;AAE5B,QAAA,IAAI,GAAG,CAAC,aAAa,KAAK,aAAa,IAAI,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE;AAC9D,YAAA,OAAO;QACT;AAEA,QAAA,MAAM,IAAI,GAAG,IAAI,CAAC,kBAAkB;QAEpC,MAAM,IAAI,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC;;AAGnC,QAAA,IAAI,CAAC,kBAAkB,GAAG,GAAG,CAAC,WAAW,EAAE;QAE3C,IAAI,IAAI,EAAE;AACR,YAAA,IAAI,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,aAAa,CAAC;QACrD;IACF;AACD;;;;"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { type WithInitialValueOperator } from '../types/index.mjs';
|
|
2
|
+
/**
|
|
3
|
+
* Applies an accumulator function over the source observable and emits each intermediate result.
|
|
4
|
+
* Similar to Array.reduce but emits accumulated value after each source emission.
|
|
5
|
+
*
|
|
6
|
+
* @template A - The type of values from the source
|
|
7
|
+
* @template B - The type of the accumulated value
|
|
8
|
+
* @param reducer - The accumulator function
|
|
9
|
+
* @param initialValue - The initial accumulated value (seed)
|
|
10
|
+
* @returns An operator that accumulates values
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* const num$ = source<number>();
|
|
15
|
+
*
|
|
16
|
+
* const sum$ = num$.pipe(scan((acc, curr) => acc + curr, 0));
|
|
17
|
+
*
|
|
18
|
+
* sum$.subscribe((x) => {
|
|
19
|
+
* console.log(x);
|
|
20
|
+
* });
|
|
21
|
+
*
|
|
22
|
+
* num$.next(1); // logs: 1
|
|
23
|
+
*
|
|
24
|
+
* num$.next(2); // logs: 3
|
|
25
|
+
*
|
|
26
|
+
* num$.next(3); // logs: 6
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export declare const scan: <A, B>(reducer: (acc: B, curr: A) => B, initialValue: B) => WithInitialValueOperator<A, B>;
|
|
30
|
+
//# sourceMappingURL=scan.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scan.d.mts","sourceRoot":"","sources":["../../../src/core/operators/scan.mts"],"names":[],"mappings":"AAEA,OAAO,EAIL,KAAK,wBAAwB,EAC9B,MAAM,oBAAoB,CAAC;AAE5B;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,eAAO,MAAM,IAAI,GACd,CAAC,EAAE,CAAC,EACH,SAAS,CAAC,GAAG,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,KAAK,CAAC,EAC/B,cAAc,CAAC,KACd,wBAAwB,CAAC,CAAC,EAAE,CAAC,CAEkC,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { Optional } from 'ts-data-forge';
|
|
2
|
+
import { InitializedSyncChildObservableClass } from '../class/child-observable-class.mjs';
|
|
3
|
+
import '../utils/id-maker.mjs';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Applies an accumulator function over the source observable and emits each intermediate result.
|
|
7
|
+
* Similar to Array.reduce but emits accumulated value after each source emission.
|
|
8
|
+
*
|
|
9
|
+
* @template A - The type of values from the source
|
|
10
|
+
* @template B - The type of the accumulated value
|
|
11
|
+
* @param reducer - The accumulator function
|
|
12
|
+
* @param initialValue - The initial accumulated value (seed)
|
|
13
|
+
* @returns An operator that accumulates values
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* const num$ = source<number>();
|
|
18
|
+
*
|
|
19
|
+
* const sum$ = num$.pipe(scan((acc, curr) => acc + curr, 0));
|
|
20
|
+
*
|
|
21
|
+
* sum$.subscribe((x) => {
|
|
22
|
+
* console.log(x);
|
|
23
|
+
* });
|
|
24
|
+
*
|
|
25
|
+
* num$.next(1); // logs: 1
|
|
26
|
+
*
|
|
27
|
+
* num$.next(2); // logs: 3
|
|
28
|
+
*
|
|
29
|
+
* num$.next(3); // logs: 6
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
const scan = (reducer, initialValue) => (parentObservable) => new ScanObservableClass(parentObservable, reducer, initialValue);
|
|
33
|
+
class ScanObservableClass extends InitializedSyncChildObservableClass {
|
|
34
|
+
#reducer;
|
|
35
|
+
constructor(parentObservable, reducer, initialValue) {
|
|
36
|
+
super({
|
|
37
|
+
parents: [parentObservable],
|
|
38
|
+
initialValue: Optional.some(initialValue),
|
|
39
|
+
});
|
|
40
|
+
this.#reducer = reducer;
|
|
41
|
+
}
|
|
42
|
+
tryUpdate(updaterSymbol) {
|
|
43
|
+
const par = this.parents[0];
|
|
44
|
+
const psn = par.getSnapshot();
|
|
45
|
+
const sn = this.getSnapshot();
|
|
46
|
+
if (par.updaterSymbol !== updaterSymbol ||
|
|
47
|
+
Optional.isNone(psn) ||
|
|
48
|
+
Optional.isNone(sn)) {
|
|
49
|
+
return; // skip update
|
|
50
|
+
}
|
|
51
|
+
this.setNext(this.#reducer(sn.value, psn.value), updaterSymbol);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export { scan };
|
|
56
|
+
//# sourceMappingURL=scan.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scan.mjs","sources":["../../../src/core/operators/scan.mts"],"sourcesContent":[null],"names":[],"mappings":";;;;AASA;;;;;;;;;;;;;;;;;;;;;;;;;;AA0BG;AACI,MAAM,IAAI,GACf,CACE,OAA+B,EAC/B,YAAe,KAEjB,CAAC,gBAAgB,KACf,IAAI,mBAAmB,CAAC,gBAAgB,EAAE,OAAO,EAAE,YAAY;AAEnE,MAAM,mBACJ,SAAQ,mCAAoD,CAAA;AAGnD,IAAA,QAAQ;AAEjB,IAAA,WAAA,CACE,gBAA+B,EAC/B,OAA+B,EAC/B,YAAe,EAAA;AAEf,QAAA,KAAK,CAAC;YACJ,OAAO,EAAE,CAAC,gBAAgB,CAAC;AAC3B,YAAA,YAAY,EAAE,QAAQ,CAAC,IAAI,CAAC,YAAY,CAAC;AAC1C,SAAA,CAAC;AAEF,QAAA,IAAI,CAAC,QAAQ,GAAG,OAAO;IACzB;AAES,IAAA,SAAS,CAAC,aAA4B,EAAA;QAC7C,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;AAE3B,QAAA,MAAM,GAAG,GAAG,GAAG,CAAC,WAAW,EAAE;AAE7B,QAAA,MAAM,EAAE,GAAG,IAAI,CAAC,WAAW,EAAE;AAE7B,QAAA,IACE,GAAG,CAAC,aAAa,KAAK,aAAa;AACnC,YAAA,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC;AACpB,YAAA,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,EACnB;AACA,YAAA,OAAO;QACT;AAEA,QAAA,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,CAAC,KAAK,CAAC,EAAE,aAAa,CAAC;IACjE;AACD;;;;"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { type KeepInitialValueOperator } from '../types/index.mjs';
|
|
2
|
+
/**
|
|
3
|
+
* Skips emissions if the value hasn't changed from the previous emission.
|
|
4
|
+
* Uses a custom equality function or Object.is by default.
|
|
5
|
+
*
|
|
6
|
+
* @template A - The type of values from the source
|
|
7
|
+
* @param eq - Equality comparison function (default: Object.is)
|
|
8
|
+
* @returns An operator that skips duplicate consecutive values
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* const num$ = source<number>();
|
|
13
|
+
*
|
|
14
|
+
* const distinct$ = num$.pipe(skipIfNoChange());
|
|
15
|
+
*
|
|
16
|
+
* distinct$.subscribe((x) => {
|
|
17
|
+
* console.log(x);
|
|
18
|
+
* });
|
|
19
|
+
*
|
|
20
|
+
* num$.next(1); // logs: 1
|
|
21
|
+
*
|
|
22
|
+
* num$.next(1); // nothing logged
|
|
23
|
+
*
|
|
24
|
+
* num$.next(2); // logs: 2
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export declare const skipIfNoChange: <A>(eq?: (x: A, y: A) => boolean) => KeepInitialValueOperator<A, A>;
|
|
28
|
+
/**
|
|
29
|
+
* Alias for `skipIfNoChange()`.
|
|
30
|
+
* @see skipIfNoChange
|
|
31
|
+
*/
|
|
32
|
+
export declare const distinctUntilChanged: <A>(eq?: (x: A, y: A) => boolean) => KeepInitialValueOperator<A, A>;
|
|
33
|
+
//# sourceMappingURL=skip-if-no-change.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"skip-if-no-change.d.mts","sourceRoot":"","sources":["../../../src/core/operators/skip-if-no-change.mts"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,wBAAwB,EAI9B,MAAM,oBAAoB,CAAC;AAE5B;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,eAAO,MAAM,cAAc,GAAI,CAAC,EAC9B,KAAI,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,OAAmC,KACtD,wBAAwB,CAAC,CAAC,EAAE,CAAC,CAMQ,CAAC;AAEzC;;;GAGG;AACH,eAAO,MAAM,oBAAoB,GAdF,CAAC,OAC1B,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,OAAO,KAC1B,wBAAwB,CAAC,CAAC,EAAE,CAAC,CAYkB,CAAC"}
|
|
@@ -0,0 +1,68 @@
|
|
|
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
|
+
* Skips emissions if the value hasn't changed from the previous emission.
|
|
7
|
+
* Uses a custom equality function or Object.is by default.
|
|
8
|
+
*
|
|
9
|
+
* @template A - The type of values from the source
|
|
10
|
+
* @param eq - Equality comparison function (default: Object.is)
|
|
11
|
+
* @returns An operator that skips duplicate consecutive values
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* const num$ = source<number>();
|
|
16
|
+
*
|
|
17
|
+
* const distinct$ = num$.pipe(skipIfNoChange());
|
|
18
|
+
*
|
|
19
|
+
* distinct$.subscribe((x) => {
|
|
20
|
+
* console.log(x);
|
|
21
|
+
* });
|
|
22
|
+
*
|
|
23
|
+
* num$.next(1); // logs: 1
|
|
24
|
+
*
|
|
25
|
+
* num$.next(1); // nothing logged
|
|
26
|
+
*
|
|
27
|
+
* num$.next(2); // logs: 2
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
const skipIfNoChange = (eq = (x, y) => Object.is(x, y)) =>
|
|
31
|
+
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
32
|
+
((parentObservable) => new SkipIfNoChangeObservableClass(parentObservable, eq));
|
|
33
|
+
/**
|
|
34
|
+
* Alias for `skipIfNoChange()`.
|
|
35
|
+
* @see skipIfNoChange
|
|
36
|
+
*/
|
|
37
|
+
const distinctUntilChanged = skipIfNoChange; // alias
|
|
38
|
+
class SkipIfNoChangeObservableClass extends SyncChildObservableClass {
|
|
39
|
+
#eq;
|
|
40
|
+
#mut_previousValue;
|
|
41
|
+
constructor(parentObservable, eq) {
|
|
42
|
+
super({
|
|
43
|
+
parents: [parentObservable],
|
|
44
|
+
initialValue: parentObservable.getSnapshot(),
|
|
45
|
+
});
|
|
46
|
+
// parentObservable.snapshot has value
|
|
47
|
+
// if parentObservable is InitializedObservable
|
|
48
|
+
this.#mut_previousValue = parentObservable.getSnapshot();
|
|
49
|
+
this.#eq = eq;
|
|
50
|
+
}
|
|
51
|
+
tryUpdate(updaterSymbol) {
|
|
52
|
+
const par = this.parents[0];
|
|
53
|
+
const sn = par.getSnapshot();
|
|
54
|
+
if (par.updaterSymbol !== updaterSymbol || Optional.isNone(sn)) {
|
|
55
|
+
return; // skip update
|
|
56
|
+
}
|
|
57
|
+
const prev = this.#mut_previousValue;
|
|
58
|
+
const cond = Optional.isNone(prev) || !this.#eq(prev.value, sn.value);
|
|
59
|
+
// NOTE: Must update before setNext, otherwise Optional.isNone(prev) remains true when tryUpdate is called consecutively
|
|
60
|
+
this.#mut_previousValue = sn;
|
|
61
|
+
if (cond) {
|
|
62
|
+
this.setNext(sn.value, updaterSymbol);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export { distinctUntilChanged, skipIfNoChange };
|
|
68
|
+
//# sourceMappingURL=skip-if-no-change.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"skip-if-no-change.mjs","sources":["../../../src/core/operators/skip-if-no-change.mts"],"sourcesContent":[null],"names":[],"mappings":";;;;AASA;;;;;;;;;;;;;;;;;;;;;;;;AAwBG;MACU,cAAc,GAAG,CAC5B,EAAA,GAA8B,CAAC,CAAC,EAAE,CAAC,KAAK,MAAM,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;AAEvD;AACA,CAAC,CAAC,gBAAgB,KAChB,IAAI,6BAA6B,CAC/B,gBAAgB,EAChB,EAAE,CACH;AAEL;;;AAGG;AACI,MAAM,oBAAoB,GAAG,eAAe;AAEnD,MAAM,6BACJ,SAAQ,wBAAyC,CAAA;AAGxC,IAAA,GAAG;AACZ,IAAA,kBAAkB;IAElB,WAAA,CAAY,gBAA+B,EAAE,EAA2B,EAAA;AACtE,QAAA,KAAK,CAAC;YACJ,OAAO,EAAE,CAAC,gBAAgB,CAAC;AAC3B,YAAA,YAAY,EAAE,gBAAgB,CAAC,WAAW,EAAE;AAC7C,SAAA,CAAC;;;AAIF,QAAA,IAAI,CAAC,kBAAkB,GAAG,gBAAgB,CAAC,WAAW,EAAE;AAExD,QAAA,IAAI,CAAC,GAAG,GAAG,EAAE;IACf;AAES,IAAA,SAAS,CAAC,aAA4B,EAAA;QAC7C,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;AAE3B,QAAA,MAAM,EAAE,GAAG,GAAG,CAAC,WAAW,EAAE;AAE5B,QAAA,IAAI,GAAG,CAAC,aAAa,KAAK,aAAa,IAAI,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE;AAC9D,YAAA,OAAO;QACT;AAEA,QAAA,MAAM,IAAI,GAAG,IAAI,CAAC,kBAAkB;QAEpC,MAAM,IAAI,GAAG,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC;;AAGrE,QAAA,IAAI,CAAC,kBAAkB,GAAG,EAAE;QAE5B,IAAI,IAAI,EAAE;YACR,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,aAAa,CAAC;QACvC;IACF;AACD;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"skip-until.d.mts","sourceRoot":"","sources":["../../../src/core/operators/skip-until.mts"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,wBAAwB,EAC7B,KAAK,UAAU,EAGhB,MAAM,oBAAoB,CAAC;AAE5B,eAAO,MAAM,SAAS,GACnB,CAAC,EAAG,UAAU,UAAU,CAAC,OAAO,CAAC,KAAG,wBAAwB,CAAC,CAAC,EAAE,CAAC,CAER,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Optional } from 'ts-data-forge';
|
|
2
|
+
import { SyncChildObservableClass } from '../class/child-observable-class.mjs';
|
|
3
|
+
import '../utils/id-maker.mjs';
|
|
4
|
+
|
|
5
|
+
const skipUntil = (notifier) => (parentObservable) => new SkipUntilObservableClass(parentObservable, notifier);
|
|
6
|
+
class SkipUntilObservableClass extends SyncChildObservableClass {
|
|
7
|
+
#mut_isSkipping;
|
|
8
|
+
constructor(parentObservable, notifier) {
|
|
9
|
+
super({
|
|
10
|
+
parents: [parentObservable],
|
|
11
|
+
initialValue: Optional.none,
|
|
12
|
+
});
|
|
13
|
+
this.#mut_isSkipping = true;
|
|
14
|
+
notifier.subscribe(() => {
|
|
15
|
+
this.#mut_isSkipping = false;
|
|
16
|
+
}, () => {
|
|
17
|
+
this.#mut_isSkipping = false;
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
tryUpdate(updaterSymbol) {
|
|
21
|
+
const par = this.parents[0];
|
|
22
|
+
const sn = par.getSnapshot();
|
|
23
|
+
if (par.updaterSymbol !== updaterSymbol ||
|
|
24
|
+
Optional.isNone(sn) ||
|
|
25
|
+
this.#mut_isSkipping) {
|
|
26
|
+
return; // skip update
|
|
27
|
+
}
|
|
28
|
+
this.setNext(sn.value, updaterSymbol);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export { skipUntil };
|
|
33
|
+
//# sourceMappingURL=skip-until.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"skip-until.mjs","sources":["../../../src/core/operators/skip-until.mts"],"sourcesContent":[null],"names":[],"mappings":";;;;MASa,SAAS,GACpB,CAAK,QAA6B,KAClC,CAAC,gBAAgB,KACf,IAAI,wBAAwB,CAAC,gBAAgB,EAAE,QAAQ;AAE3D,MAAM,wBACJ,SAAQ,wBAAyC,CAAA;AAGjD,IAAA,eAAe;IAEf,WAAA,CAAY,gBAA+B,EAAE,QAA6B,EAAA;AACxE,QAAA,KAAK,CAAC;YACJ,OAAO,EAAE,CAAC,gBAAgB,CAAC;YAC3B,YAAY,EAAE,QAAQ,CAAC,IAAI;AAC5B,SAAA,CAAC;AAEF,QAAA,IAAI,CAAC,eAAe,GAAG,IAAI;AAE3B,QAAA,QAAQ,CAAC,SAAS,CAChB,MAAK;AACH,YAAA,IAAI,CAAC,eAAe,GAAG,KAAK;QAC9B,CAAC,EACD,MAAK;AACH,YAAA,IAAI,CAAC,eAAe,GAAG,KAAK;AAC9B,QAAA,CAAC,CACF;IACH;AAES,IAAA,SAAS,CAAC,aAA4B,EAAA;QAC7C,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;AAE3B,QAAA,MAAM,EAAE,GAAG,GAAG,CAAC,WAAW,EAAE;AAE5B,QAAA,IACE,GAAG,CAAC,aAAa,KAAK,aAAa;AACnC,YAAA,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;YACnB,IAAI,CAAC,eAAe,EACpB;AACA,YAAA,OAAO;QACT;QAEA,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,aAAa,CAAC;IACvC;AACD;;;;"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type DropInitialValueOperator } from '../types/index.mjs';
|
|
2
|
+
export declare const skipWhile: <A>(predicate: (value: A, index: SafeUint | -1) => boolean) => DropInitialValueOperator<A, A>;
|
|
3
|
+
export declare const skip: <A>(n: PositiveSafeIntWithSmallInt) => DropInitialValueOperator<A, A>;
|
|
4
|
+
//# sourceMappingURL=skip-while.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"skip-while.d.mts","sourceRoot":"","sources":["../../../src/core/operators/skip-while.mts"],"names":[],"mappings":"AAQA,OAAO,EACL,KAAK,wBAAwB,EAI9B,MAAM,oBAAoB,CAAC;AAE5B,eAAO,MAAM,SAAS,GACnB,CAAC,EACA,WAAW,CAAC,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,QAAQ,GAAG,CAAC,CAAC,KAAK,OAAO,KACrD,wBAAwB,CAAC,CAAC,EAAE,CAAC,CAE2B,CAAC;AAI9D,eAAO,MAAM,IAAI,GAAI,CAAC,EACpB,GAAG,2BAA2B,KAC7B,wBAAwB,CAAC,CAAC,EAAE,CAAC,CACyC,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { PositiveSafeInt, pipe, Optional, asSafeUint, SafeUint } from 'ts-data-forge';
|
|
2
|
+
import { SyncChildObservableClass } from '../class/child-observable-class.mjs';
|
|
3
|
+
import '../utils/id-maker.mjs';
|
|
4
|
+
|
|
5
|
+
const skipWhile = (predicate) => (parentObservable) => new SkipWhileObservableClass(parentObservable, predicate);
|
|
6
|
+
/* Specialized operators */
|
|
7
|
+
const skip = (n) => !PositiveSafeInt.is(n) ? idFn : skipWhile((_, index) => index + 1 <= n);
|
|
8
|
+
const idFn = (value) => value;
|
|
9
|
+
/* implementation */
|
|
10
|
+
class SkipWhileObservableClass extends SyncChildObservableClass {
|
|
11
|
+
#predicate;
|
|
12
|
+
#mut_index;
|
|
13
|
+
constructor(parentObservable, predicate) {
|
|
14
|
+
super({
|
|
15
|
+
parents: [parentObservable],
|
|
16
|
+
initialValue: pipe(parentObservable.getSnapshot()).map((sn) => Optional.isNone(sn)
|
|
17
|
+
? Optional.none
|
|
18
|
+
: predicate(sn.value, -1)
|
|
19
|
+
? Optional.none
|
|
20
|
+
: sn).value,
|
|
21
|
+
});
|
|
22
|
+
this.#mut_index = -1;
|
|
23
|
+
this.#predicate = predicate;
|
|
24
|
+
}
|
|
25
|
+
tryUpdate(updaterSymbol) {
|
|
26
|
+
const par = this.parents[0];
|
|
27
|
+
const sn = par.getSnapshot();
|
|
28
|
+
if (par.updaterSymbol !== updaterSymbol || Optional.isNone(sn)) {
|
|
29
|
+
return; // skip update
|
|
30
|
+
}
|
|
31
|
+
this.#mut_index =
|
|
32
|
+
this.#mut_index === -1 ? asSafeUint(0) : SafeUint.add(1, this.#mut_index);
|
|
33
|
+
if (!this.#predicate(sn.value, this.#mut_index)) {
|
|
34
|
+
this.setNext(sn.value, updaterSymbol);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export { skip, skipWhile };
|
|
40
|
+
//# sourceMappingURL=skip-while.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"skip-while.mjs","sources":["../../../src/core/operators/skip-while.mts"],"sourcesContent":[null],"names":[],"mappings":";;;;MAea,SAAS,GACpB,CACE,SAAsD,KAExD,CAAC,gBAAgB,KACf,IAAI,wBAAwB,CAAC,gBAAgB,EAAE,SAAS;AAE5D;AAEO,MAAM,IAAI,GAAG,CAClB,CAA8B,KAE9B,CAAC,eAAe,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,KAAK,KAAK,GAAG,CAAC,IAAI,CAAC;AAExE,MAAM,IAAI,GAAG,CAAK,KAAQ,KAAQ,KAAK;AAEvC;AAEA,MAAM,wBACJ,SAAQ,wBAAyC,CAAA;AAGxC,IAAA,UAAU;AACnB,IAAA,UAAU;IAEV,WAAA,CACE,gBAA+B,EAC/B,SAAsD,EAAA;AAEtD,QAAA,KAAK,CAAC;YACJ,OAAO,EAAE,CAAC,gBAAgB,CAAC;YAC3B,YAAY,EAAE,IAAI,CAAC,gBAAgB,CAAC,WAAW,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,KACxD,QAAQ,CAAC,MAAM,CAAC,EAAE;kBACd,QAAQ,CAAC;kBACT,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,EAAE;sBACpB,QAAQ,CAAC;AACX,sBAAE,EAAE,CACT,CAAC,KAAK;AACR,SAAA,CAAC;AAEF,QAAA,IAAI,CAAC,UAAU,GAAG,EAAE;AAEpB,QAAA,IAAI,CAAC,UAAU,GAAG,SAAS;IAC7B;AAES,IAAA,SAAS,CAAC,aAA4B,EAAA;QAC7C,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;AAE3B,QAAA,MAAM,EAAE,GAAG,GAAG,CAAC,WAAW,EAAE;AAE5B,QAAA,IAAI,GAAG,CAAC,aAAa,KAAK,aAAa,IAAI,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE;AAC9D,YAAA,OAAO;QACT;AAEA,QAAA,IAAI,CAAC,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,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC,KAAK,EAAE,IAAI,CAAC,UAAU,CAAC,EAAE;YAC/C,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,aAAa,CAAC;QACvC;IACF;AACD;;;;"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type DropInitialValueOperator, type Observable } from '../types/index.mjs';
|
|
2
|
+
/**
|
|
3
|
+
* Projects each source value to an observable, subscribes to it, and emits its values.
|
|
4
|
+
* When a new value arrives from the source, the previous inner observable is unsubscribed.
|
|
5
|
+
*
|
|
6
|
+
* @template A - The type of values from the source
|
|
7
|
+
* @template B - The type of values from the projected observable
|
|
8
|
+
* @param mapToObservable - A function that maps each source value to an observable
|
|
9
|
+
* @returns An operator that switches to new observables
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* const searchQuery$ = source<string>();
|
|
14
|
+
*
|
|
15
|
+
* const results$ = searchQuery$.pipe(
|
|
16
|
+
* switchMap((query) => fromPromise(fetchResults(query))),
|
|
17
|
+
* );
|
|
18
|
+
*
|
|
19
|
+
* results$.subscribe((results) => {
|
|
20
|
+
* console.log(results);
|
|
21
|
+
* });
|
|
22
|
+
* // Only the latest search results are emitted, previous searches are cancelled
|
|
23
|
+
*
|
|
24
|
+
* const fetchResults = async (_query: string): Promise<readonly unknown[]> => [];
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @note To improve code readability, consider using `createState` instead of `switchMap`,
|
|
28
|
+
* subscribe to `parentObservable` and call `setState` within it.
|
|
29
|
+
*/
|
|
30
|
+
export declare const switchMap: <A, B>(mapToObservable: (curr: A) => Observable<B>) => DropInitialValueOperator<A, B>;
|
|
31
|
+
//# sourceMappingURL=switch-map.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"switch-map.d.mts","sourceRoot":"","sources":["../../../src/core/operators/switch-map.mts"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,wBAAwB,EAC7B,KAAK,UAAU,EAIhB,MAAM,oBAAoB,CAAC;AAE5B;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,eAAO,MAAM,SAAS,GACnB,CAAC,EAAE,CAAC,EACH,iBAAiB,CAAC,IAAI,EAAE,CAAC,KAAK,UAAU,CAAC,CAAC,CAAC,KAC1C,wBAAwB,CAAC,CAAC,EAAE,CAAC,CAEiC,CAAC"}
|
|
@@ -0,0 +1,70 @@
|
|
|
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
|
+
* Projects each source value to an observable, subscribes to it, and emits its values.
|
|
7
|
+
* When a new value arrives from the source, the previous inner observable is unsubscribed.
|
|
8
|
+
*
|
|
9
|
+
* @template A - The type of values from the source
|
|
10
|
+
* @template B - The type of values from the projected observable
|
|
11
|
+
* @param mapToObservable - A function that maps each source value to an observable
|
|
12
|
+
* @returns An operator that switches to new observables
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* const searchQuery$ = source<string>();
|
|
17
|
+
*
|
|
18
|
+
* const results$ = searchQuery$.pipe(
|
|
19
|
+
* switchMap((query) => fromPromise(fetchResults(query))),
|
|
20
|
+
* );
|
|
21
|
+
*
|
|
22
|
+
* results$.subscribe((results) => {
|
|
23
|
+
* console.log(results);
|
|
24
|
+
* });
|
|
25
|
+
* // Only the latest search results are emitted, previous searches are cancelled
|
|
26
|
+
*
|
|
27
|
+
* const fetchResults = async (_query: string): Promise<readonly unknown[]> => [];
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* @note To improve code readability, consider using `createState` instead of `switchMap`,
|
|
31
|
+
* subscribe to `parentObservable` and call `setState` within it.
|
|
32
|
+
*/
|
|
33
|
+
const switchMap = (mapToObservable) => (parentObservable) => new SwitchMapObservableClass(parentObservable, mapToObservable);
|
|
34
|
+
class SwitchMapObservableClass extends AsyncChildObservableClass {
|
|
35
|
+
#mapToObservable;
|
|
36
|
+
#mut_observable;
|
|
37
|
+
#mut_subscription;
|
|
38
|
+
constructor(parentObservable, mapToObservable) {
|
|
39
|
+
super({
|
|
40
|
+
parents: [parentObservable],
|
|
41
|
+
initialValue: Optional.none,
|
|
42
|
+
});
|
|
43
|
+
this.#mapToObservable = mapToObservable;
|
|
44
|
+
this.#mut_observable = undefined;
|
|
45
|
+
this.#mut_subscription = undefined;
|
|
46
|
+
}
|
|
47
|
+
tryUpdate(updaterSymbol) {
|
|
48
|
+
const par = this.parents[0];
|
|
49
|
+
const sn = par.getSnapshot();
|
|
50
|
+
if (par.updaterSymbol !== updaterSymbol || Optional.isNone(sn)) {
|
|
51
|
+
return; // skip update
|
|
52
|
+
}
|
|
53
|
+
this.#mut_observable?.complete();
|
|
54
|
+
this.#mut_subscription?.unsubscribe();
|
|
55
|
+
const observable = this.#mapToObservable(sn.value);
|
|
56
|
+
this.#mut_observable = observable;
|
|
57
|
+
const subscription = observable.subscribe((curr) => {
|
|
58
|
+
this.startUpdate(curr);
|
|
59
|
+
});
|
|
60
|
+
this.#mut_subscription = subscription;
|
|
61
|
+
}
|
|
62
|
+
complete() {
|
|
63
|
+
this.#mut_subscription?.unsubscribe();
|
|
64
|
+
this.#mut_observable?.complete();
|
|
65
|
+
super.complete();
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export { switchMap };
|
|
70
|
+
//# sourceMappingURL=switch-map.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"switch-map.mjs","sources":["../../../src/core/operators/switch-map.mts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAUA;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BG;MACU,SAAS,GACpB,CACE,eAA2C,KAE7C,CAAC,gBAAgB,KACf,IAAI,wBAAwB,CAAC,gBAAgB,EAAE,eAAe;AAElE,MAAM,wBACJ,SAAQ,yBAA0C,CAAA;AAGzC,IAAA,gBAAgB;AACzB,IAAA,eAAe;AACf,IAAA,iBAAiB;IAEjB,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,eAAe,GAAG,SAAS;AAEhC,QAAA,IAAI,CAAC,iBAAiB,GAAG,SAAS;IACpC;AAES,IAAA,SAAS,CAAC,aAA4B,EAAA;QAC7C,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;AAE3B,QAAA,MAAM,EAAE,GAAG,GAAG,CAAC,WAAW,EAAE;AAE5B,QAAA,IAAI,GAAG,CAAC,aAAa,KAAK,aAAa,IAAI,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE;AAC9D,YAAA,OAAO;QACT;AAEA,QAAA,IAAI,CAAC,eAAe,EAAE,QAAQ,EAAE;AAEhC,QAAA,IAAI,CAAC,iBAAiB,EAAE,WAAW,EAAE;QAErC,MAAM,UAAU,GAAG,IAAI,CAAC,gBAAgB,CAAC,EAAE,CAAC,KAAK,CAAC;AAElD,QAAA,IAAI,CAAC,eAAe,GAAG,UAAU;QAEjC,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,iBAAiB,GAAG,YAAY;IACvC;IAES,QAAQ,GAAA;AACf,QAAA,IAAI,CAAC,iBAAiB,EAAE,WAAW,EAAE;AAErC,QAAA,IAAI,CAAC,eAAe,EAAE,QAAQ,EAAE;QAEhC,KAAK,CAAC,QAAQ,EAAE;IAClB;AACD;;;;"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { type KeepInitialValueOperator, type Observable } from '../types/index.mjs';
|
|
2
|
+
/**
|
|
3
|
+
* Emits values from the source until the notifier observable emits.
|
|
4
|
+
* When the notifier emits, this observable completes.
|
|
5
|
+
*
|
|
6
|
+
* @template A - The type of values from the source
|
|
7
|
+
* @param notifier - An observable that signals when to complete
|
|
8
|
+
* @returns An operator that takes values until notifier emits
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* const num$ = source<number>();
|
|
13
|
+
*
|
|
14
|
+
* const [stopNotifier, stop_] = createEventEmitter();
|
|
15
|
+
*
|
|
16
|
+
* const limited$ = num$.pipe(takeUntil(stopNotifier));
|
|
17
|
+
*
|
|
18
|
+
* limited$.subscribe((x) => {
|
|
19
|
+
* console.log(x);
|
|
20
|
+
* });
|
|
21
|
+
*
|
|
22
|
+
* num$.next(1); // logs: 1
|
|
23
|
+
*
|
|
24
|
+
* num$.next(2); // logs: 2
|
|
25
|
+
*
|
|
26
|
+
* stop_();
|
|
27
|
+
*
|
|
28
|
+
* num$.next(3); // nothing logged (completed)
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export declare const takeUntil: <A>(notifier: Observable<unknown>) => KeepInitialValueOperator<A, A>;
|
|
32
|
+
//# sourceMappingURL=take-until.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"take-until.d.mts","sourceRoot":"","sources":["../../../src/core/operators/take-until.mts"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,wBAAwB,EAC7B,KAAK,UAAU,EAGhB,MAAM,oBAAoB,CAAC;AAE5B;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,eAAO,MAAM,SAAS,GAAI,CAAC,EACzB,UAAU,UAAU,CAAC,OAAO,CAAC,KAC5B,wBAAwB,CAAC,CAAC,EAAE,CAAC,CAMQ,CAAC"}
|