synstate 2.0.1 → 3.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 +2 -2
- package/dist/core/base/create-child-observable.d.mts +65 -0
- package/dist/core/base/create-child-observable.d.mts.map +1 -0
- package/dist/core/base/create-child-observable.mjs +157 -0
- package/dist/core/base/create-child-observable.mjs.map +1 -0
- package/dist/core/base/create-observable-base.d.mts +82 -0
- package/dist/core/base/create-observable-base.d.mts.map +1 -0
- package/dist/core/base/create-observable-base.mjs +160 -0
- package/dist/core/base/create-observable-base.mjs.map +1 -0
- package/dist/core/base/create-root-observable.d.mts +37 -0
- package/dist/core/base/create-root-observable.d.mts.map +1 -0
- package/dist/core/base/create-root-observable.mjs +36 -0
- package/dist/core/base/create-root-observable.mjs.map +1 -0
- package/dist/core/base/index.d.mts +3 -0
- package/dist/core/base/index.d.mts.map +1 -0
- package/dist/core/base/index.mjs +3 -0
- package/dist/core/{class → base}/index.mjs.map +1 -1
- package/dist/core/combine/combine.d.mts.map +1 -1
- package/dist/core/combine/combine.mjs +28 -27
- package/dist/core/combine/combine.mjs.map +1 -1
- package/dist/core/combine/merge.d.mts.map +1 -1
- package/dist/core/combine/merge.mjs +11 -13
- package/dist/core/combine/merge.mjs.map +1 -1
- package/dist/core/combine/zip.d.mts.map +1 -1
- package/dist/core/combine/zip.mjs +32 -31
- package/dist/core/combine/zip.mjs.map +1 -1
- package/dist/core/create/counter.d.mts.map +1 -1
- package/dist/core/create/counter.mjs +39 -50
- 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 +33 -32
- 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 +12 -12
- 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 +10 -10
- 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 -4
- package/dist/core/create/just.mjs.map +1 -1
- package/dist/core/create/source.mjs +11 -12
- 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 -38
- package/dist/core/create/timer.mjs.map +1 -1
- package/dist/core/index.d.mts +0 -1
- package/dist/core/index.d.mts.map +1 -1
- package/dist/core/index.mjs +0 -3
- package/dist/core/index.mjs.map +1 -1
- package/dist/core/operators/audit.d.mts.map +1 -1
- package/dist/core/operators/audit.mjs +28 -36
- 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 +26 -33
- package/dist/core/operators/debounce.mjs.map +1 -1
- package/dist/core/operators/filter.d.mts.map +1 -1
- package/dist/core/operators/filter.mjs +23 -27
- 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 +21 -28
- package/dist/core/operators/map.mjs.map +1 -1
- package/dist/core/operators/merge-map.d.mts.map +1 -1
- package/dist/core/operators/merge-map.mjs +30 -39
- package/dist/core/operators/merge-map.mjs.map +1 -1
- package/dist/core/operators/pairwise.d.mts.map +1 -1
- package/dist/core/operators/pairwise.mjs +22 -24
- 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 +13 -18
- package/dist/core/operators/scan.mjs.map +1 -1
- package/dist/core/operators/skip-if-no-change.d.mts.map +1 -1
- package/dist/core/operators/skip-if-no-change.mjs +22 -26
- 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 -24
- 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 +27 -32
- 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 +28 -34
- 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 +22 -22
- 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 +25 -29
- 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 +27 -35
- package/dist/core/operators/throttle.mjs.map +1 -1
- package/dist/core/operators/with-buffered-from.d.mts.map +1 -1
- package/dist/core/operators/with-buffered-from.mjs +24 -24
- package/dist/core/operators/with-buffered-from.mjs.map +1 -1
- package/dist/core/operators/with-current-value-from.d.mts.map +1 -1
- package/dist/core/operators/with-current-value-from.mjs +20 -25
- 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 +12 -15
- package/dist/core/operators/with-initial-value.mjs.map +1 -1
- package/dist/entry-point.mjs +0 -3
- package/dist/entry-point.mjs.map +1 -1
- package/dist/index.mjs +0 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +25 -18
- package/src/core/{class → base}/circular-dependency-comparison.test.mts +28 -18
- package/src/core/base/circular-dependency.test.mts +322 -0
- package/src/core/base/create-child-observable.mts +340 -0
- package/src/core/base/create-observable-base.mts +358 -0
- package/src/core/base/create-root-observable.mts +102 -0
- package/src/core/base/index.mts +2 -0
- package/src/core/{class/observable.class.test.mts → base/observable-base.test.mts} +25 -17
- package/src/core/combine/combine.mts +51 -53
- package/src/core/combine/merge.mts +21 -23
- package/src/core/combine/zip.mts +54 -58
- package/src/core/create/counter.mts +42 -59
- package/src/core/create/from-abortable-promise.mts +38 -45
- package/src/core/create/from-promise.mts +25 -28
- package/src/core/create/from-subscribable.mts +23 -27
- package/src/core/create/just.mts +5 -4
- package/src/core/create/source.mts +11 -17
- package/src/core/create/timer.mts +32 -47
- package/src/core/index.mts +0 -1
- package/src/core/operators/audit.mts +43 -57
- package/src/core/operators/debounce.mts +35 -45
- package/src/core/operators/filter.mts +31 -39
- package/src/core/operators/map.mts +32 -40
- package/src/core/operators/merge-map.mts +44 -59
- package/src/core/operators/pairwise.mts +30 -33
- package/src/core/operators/scan.mts +24 -35
- package/src/core/operators/skip-if-no-change.mts +31 -36
- package/src/core/operators/skip-until.mts +32 -35
- package/src/core/operators/skip-while.mts +31 -40
- package/src/core/operators/switch-map.mts +36 -48
- package/src/core/operators/take-until.mts +31 -29
- package/src/core/operators/take-while.mts +33 -41
- package/src/core/operators/throttle.mts +37 -51
- package/src/core/operators/with-buffered-from.mts +35 -30
- package/src/core/operators/with-current-value-from.mts +23 -28
- package/src/core/operators/with-initial-value.mts +21 -22
- package/dist/core/class/child-observable-class.d.mts +0 -39
- package/dist/core/class/child-observable-class.d.mts.map +0 -1
- package/dist/core/class/child-observable-class.mjs +0 -173
- package/dist/core/class/child-observable-class.mjs.map +0 -1
- package/dist/core/class/index.d.mts +0 -4
- package/dist/core/class/index.d.mts.map +0 -1
- package/dist/core/class/index.mjs +0 -4
- package/dist/core/class/observable-base-class.d.mts +0 -28
- package/dist/core/class/observable-base-class.d.mts.map +0 -1
- package/dist/core/class/observable-base-class.mjs +0 -120
- package/dist/core/class/observable-base-class.mjs.map +0 -1
- package/dist/core/class/root-observable-class.d.mts +0 -14
- package/dist/core/class/root-observable-class.d.mts.map +0 -1
- package/dist/core/class/root-observable-class.mjs +0 -43
- package/dist/core/class/root-observable-class.mjs.map +0 -1
- package/src/core/class/child-observable-class.mts +0 -286
- package/src/core/class/circular-dependency.test.mts +0 -251
- package/src/core/class/index.mts +0 -3
- package/src/core/class/observable-base-class.mts +0 -187
- package/src/core/class/root-observable-class.mts +0 -73
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { Optional } from 'ts-data-forge';
|
|
2
2
|
import { type FixedLengthTuple } from 'ts-type-forge';
|
|
3
|
-
import {
|
|
3
|
+
import { createSyncChildObservable } from '../base/index.mjs';
|
|
4
4
|
import {
|
|
5
5
|
type DropInitialValueOperator,
|
|
6
6
|
type Observable,
|
|
7
7
|
type PairwiseOperatorObservable,
|
|
8
|
-
type UpdateToken,
|
|
9
8
|
} from '../types/index.mjs';
|
|
10
9
|
|
|
11
10
|
/**
|
|
@@ -69,43 +68,41 @@ export const pairwise = <A,>(): DropInitialValueOperator<
|
|
|
69
68
|
const f = <A,>(
|
|
70
69
|
parentObservable: Observable<A>,
|
|
71
70
|
): Observable<FixedLengthTuple<2, A>> =>
|
|
72
|
-
|
|
71
|
+
createPairwiseObservable(parentObservable);
|
|
73
72
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
constructor(parentObservable: Observable<A>) {
|
|
81
|
-
super({
|
|
73
|
+
const createPairwiseObservable = <A,>(
|
|
74
|
+
parentObservable: Observable<A>,
|
|
75
|
+
): PairwiseOperatorObservable<A> =>
|
|
76
|
+
createSyncChildObservable<FixedLengthTuple<2, A>, readonly [A]>(
|
|
77
|
+
{
|
|
82
78
|
parents: [parentObservable],
|
|
83
79
|
initialValue: Optional.none,
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
override tryUpdate(updateToken: UpdateToken): void {
|
|
92
|
-
const par = this.parents[0];
|
|
80
|
+
},
|
|
81
|
+
({ setNext }) => {
|
|
82
|
+
// parentObservable.snapshot has value
|
|
83
|
+
// if parentObservable is InitializedObservable
|
|
84
|
+
let mut_previousValue: Optional<A> = parentObservable.getSnapshot();
|
|
93
85
|
|
|
94
|
-
|
|
86
|
+
return (updateToken) => {
|
|
87
|
+
const sn = parentObservable.getSnapshot();
|
|
95
88
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
89
|
+
if (
|
|
90
|
+
parentObservable.updateToken !== updateToken ||
|
|
91
|
+
Optional.isNone(sn)
|
|
92
|
+
) {
|
|
93
|
+
return; // skip update
|
|
94
|
+
}
|
|
99
95
|
|
|
100
|
-
|
|
96
|
+
const prev = mut_previousValue;
|
|
101
97
|
|
|
102
|
-
|
|
98
|
+
const cond = !Optional.isNone(prev);
|
|
103
99
|
|
|
104
|
-
|
|
105
|
-
|
|
100
|
+
// NOTE: Must update before setNext, otherwise Optional.isNone(prev) remains true when tryUpdate is called consecutively
|
|
101
|
+
mut_previousValue = parentObservable.getSnapshot();
|
|
106
102
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
}
|
|
103
|
+
if (cond) {
|
|
104
|
+
setNext([prev.value, sn.value], updateToken);
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
},
|
|
108
|
+
);
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { Optional } from 'ts-data-forge';
|
|
2
|
-
import {
|
|
2
|
+
import { createInitializedSyncChildObservable } from '../base/index.mjs';
|
|
3
3
|
import {
|
|
4
4
|
type Observable,
|
|
5
5
|
type ScanOperatorObservable,
|
|
6
|
-
type UpdateToken,
|
|
7
6
|
type WithInitialValueOperator,
|
|
8
7
|
} from '../types/index.mjs';
|
|
9
8
|
|
|
@@ -62,42 +61,32 @@ export const scan =
|
|
|
62
61
|
initialValue: B,
|
|
63
62
|
): WithInitialValueOperator<A, B> =>
|
|
64
63
|
(parentObservable) =>
|
|
65
|
-
|
|
64
|
+
createScanObservable(parentObservable, reducer, initialValue);
|
|
66
65
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
parentObservable: Observable<A>,
|
|
75
|
-
reducer: (acc: B, curr: A) => B,
|
|
76
|
-
initialValue: B,
|
|
77
|
-
) {
|
|
78
|
-
super({
|
|
66
|
+
const createScanObservable = <A, B>(
|
|
67
|
+
parentObservable: Observable<A>,
|
|
68
|
+
reducer: (acc: B, curr: A) => B,
|
|
69
|
+
initialValue: B,
|
|
70
|
+
): ScanOperatorObservable<A, B> =>
|
|
71
|
+
createInitializedSyncChildObservable(
|
|
72
|
+
{
|
|
79
73
|
parents: [parentObservable],
|
|
80
74
|
initialValue: Optional.some(initialValue),
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
override tryUpdate(updateToken: UpdateToken): void {
|
|
87
|
-
const par = this.parents[0];
|
|
88
|
-
|
|
89
|
-
const psn = par.getSnapshot();
|
|
75
|
+
},
|
|
76
|
+
({ setNext, getSnapshot }) =>
|
|
77
|
+
(updateToken) => {
|
|
78
|
+
const psn = parentObservable.getSnapshot();
|
|
90
79
|
|
|
91
|
-
|
|
80
|
+
const sn = getSnapshot();
|
|
92
81
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
82
|
+
if (
|
|
83
|
+
parentObservable.updateToken !== updateToken ||
|
|
84
|
+
Optional.isNone(psn) ||
|
|
85
|
+
Optional.isNone(sn)
|
|
86
|
+
) {
|
|
87
|
+
return; // skip update
|
|
88
|
+
}
|
|
100
89
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
90
|
+
setNext(reducer(sn.value, psn.value), updateToken);
|
|
91
|
+
},
|
|
92
|
+
);
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { Optional } from 'ts-data-forge';
|
|
2
|
-
import {
|
|
2
|
+
import { createSyncChildObservable } from '../base/index.mjs';
|
|
3
3
|
import {
|
|
4
4
|
type KeepInitialValueOperator,
|
|
5
5
|
type Observable,
|
|
6
6
|
type SkipIfNoChangeOperatorObservable,
|
|
7
|
-
type UpdateToken,
|
|
8
7
|
} from '../types/index.mjs';
|
|
9
8
|
|
|
10
9
|
/**
|
|
@@ -73,7 +72,7 @@ export const skipIfNoChange = <A,>(
|
|
|
73
72
|
): KeepInitialValueOperator<A, A> =>
|
|
74
73
|
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
75
74
|
((parentObservable) =>
|
|
76
|
-
|
|
75
|
+
createSkipIfNoChangeObservable(
|
|
77
76
|
parentObservable,
|
|
78
77
|
eq,
|
|
79
78
|
)) as KeepInitialValueOperator<A, A>;
|
|
@@ -84,44 +83,40 @@ export const skipIfNoChange = <A,>(
|
|
|
84
83
|
*/
|
|
85
84
|
export const distinctUntilChanged = skipIfNoChange;
|
|
86
85
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
constructor(parentObservable: Observable<A>, eq: (x: A, y: A) => boolean) {
|
|
95
|
-
super({
|
|
86
|
+
const createSkipIfNoChangeObservable = <A,>(
|
|
87
|
+
parentObservable: Observable<A>,
|
|
88
|
+
eq: (x: A, y: A) => boolean,
|
|
89
|
+
): SkipIfNoChangeOperatorObservable<A> =>
|
|
90
|
+
createSyncChildObservable(
|
|
91
|
+
{
|
|
96
92
|
parents: [parentObservable],
|
|
97
93
|
initialValue: parentObservable.getSnapshot(),
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
this.#eq = eq;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
override tryUpdate(updateToken: UpdateToken): void {
|
|
108
|
-
const par = this.parents[0];
|
|
94
|
+
},
|
|
95
|
+
({ setNext }) => {
|
|
96
|
+
// parentObservable.snapshot has value
|
|
97
|
+
// if parentObservable is InitializedObservable
|
|
98
|
+
let mut_previousValue: Optional<A> = parentObservable.getSnapshot();
|
|
109
99
|
|
|
110
|
-
|
|
100
|
+
return (updateToken) => {
|
|
101
|
+
const sn = parentObservable.getSnapshot();
|
|
111
102
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
103
|
+
if (
|
|
104
|
+
parentObservable.updateToken !== updateToken ||
|
|
105
|
+
Optional.isNone(sn)
|
|
106
|
+
) {
|
|
107
|
+
return; // skip update
|
|
108
|
+
}
|
|
115
109
|
|
|
116
|
-
|
|
110
|
+
const prev = mut_previousValue;
|
|
117
111
|
|
|
118
|
-
|
|
112
|
+
const cond = Optional.isNone(prev) || !eq(prev.value, sn.value);
|
|
119
113
|
|
|
120
|
-
|
|
121
|
-
|
|
114
|
+
// NOTE: Must update before setNext, otherwise Optional.isNone(prev) remains true when tryUpdate is called consecutively
|
|
115
|
+
mut_previousValue = sn;
|
|
122
116
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
}
|
|
117
|
+
if (cond) {
|
|
118
|
+
setNext(sn.value, updateToken);
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
},
|
|
122
|
+
);
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { Optional } from 'ts-data-forge';
|
|
2
|
-
import {
|
|
2
|
+
import { createSyncChildObservable } from '../base/index.mjs';
|
|
3
3
|
import {
|
|
4
4
|
type DropInitialValueOperator,
|
|
5
5
|
type Observable,
|
|
6
6
|
type SkipUntilOperatorObservable,
|
|
7
|
-
type UpdateToken,
|
|
8
7
|
} from '../types/index.mjs';
|
|
9
8
|
|
|
10
9
|
/**
|
|
@@ -60,45 +59,43 @@ import {
|
|
|
60
59
|
export const skipUntil =
|
|
61
60
|
<A,>(notifier: Observable<unknown>): DropInitialValueOperator<A, A> =>
|
|
62
61
|
(parentObservable) =>
|
|
63
|
-
|
|
62
|
+
createSkipUntilObservable(parentObservable, notifier);
|
|
64
63
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
{
|
|
69
|
-
|
|
64
|
+
const createSkipUntilObservable = <A,>(
|
|
65
|
+
parentObservable: Observable<A>,
|
|
66
|
+
notifier: Observable<unknown>,
|
|
67
|
+
): SkipUntilOperatorObservable<A> => {
|
|
68
|
+
let mut_isSkipping = true;
|
|
70
69
|
|
|
71
|
-
|
|
72
|
-
|
|
70
|
+
const observable = createSyncChildObservable<A, readonly [A]>(
|
|
71
|
+
{
|
|
73
72
|
parents: [parentObservable],
|
|
74
73
|
initialValue: Optional.none,
|
|
75
|
-
}
|
|
74
|
+
},
|
|
75
|
+
({ setNext }) =>
|
|
76
|
+
(updateToken) => {
|
|
77
|
+
const sn = parentObservable.getSnapshot();
|
|
76
78
|
|
|
77
|
-
|
|
79
|
+
if (
|
|
80
|
+
mut_isSkipping ||
|
|
81
|
+
parentObservable.updateToken !== updateToken ||
|
|
82
|
+
Optional.isNone(sn)
|
|
83
|
+
) {
|
|
84
|
+
return; // skip update
|
|
85
|
+
}
|
|
78
86
|
|
|
79
|
-
|
|
80
|
-
() => {
|
|
81
|
-
this.#mut_isSkipping = false;
|
|
87
|
+
setNext(sn.value, updateToken);
|
|
82
88
|
},
|
|
83
|
-
|
|
84
|
-
this.#mut_isSkipping = false;
|
|
85
|
-
},
|
|
86
|
-
);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
override tryUpdate(updateToken: UpdateToken): void {
|
|
90
|
-
const par = this.parents[0];
|
|
91
|
-
|
|
92
|
-
const sn = par.getSnapshot();
|
|
89
|
+
);
|
|
93
90
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
) {
|
|
99
|
-
|
|
100
|
-
}
|
|
91
|
+
notifier.subscribe(
|
|
92
|
+
() => {
|
|
93
|
+
mut_isSkipping = false;
|
|
94
|
+
},
|
|
95
|
+
() => {
|
|
96
|
+
mut_isSkipping = false;
|
|
97
|
+
},
|
|
98
|
+
);
|
|
101
99
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
}
|
|
100
|
+
return observable;
|
|
101
|
+
};
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { Optional, SafeUint, asSafeUint, pipe } from 'ts-data-forge';
|
|
2
|
-
import {
|
|
2
|
+
import { createSyncChildObservable } from '../base/index.mjs';
|
|
3
3
|
import {
|
|
4
4
|
type DropInitialValueOperator,
|
|
5
5
|
type Observable,
|
|
6
6
|
type SkipWhileOperatorObservable,
|
|
7
|
-
type UpdateToken,
|
|
8
7
|
} from '../types/index.mjs';
|
|
9
8
|
|
|
10
9
|
/**
|
|
@@ -70,54 +69,46 @@ export const skipWhile =
|
|
|
70
69
|
predicate: (value: A, index: SafeUint | -1) => boolean,
|
|
71
70
|
): DropInitialValueOperator<A, A> =>
|
|
72
71
|
(parentObservable) =>
|
|
73
|
-
|
|
72
|
+
createSkipWhileObservable(parentObservable, predicate);
|
|
74
73
|
|
|
75
74
|
/* implementation */
|
|
76
75
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
#mut_skipping: boolean;
|
|
84
|
-
|
|
85
|
-
constructor(
|
|
86
|
-
parentObservable: Observable<A>,
|
|
87
|
-
predicate: (value: A, index: SafeUint | -1) => boolean,
|
|
88
|
-
) {
|
|
89
|
-
super({
|
|
76
|
+
const createSkipWhileObservable = <A,>(
|
|
77
|
+
parentObservable: Observable<A>,
|
|
78
|
+
predicate: (value: A, index: SafeUint | -1) => boolean,
|
|
79
|
+
): SkipWhileOperatorObservable<A> =>
|
|
80
|
+
createSyncChildObservable(
|
|
81
|
+
{
|
|
90
82
|
parents: [parentObservable],
|
|
91
83
|
initialValue: pipe(parentObservable.getSnapshot()).map((sn) =>
|
|
92
84
|
Optional.isNone(sn) || predicate(sn.value, -1) ? Optional.none : sn,
|
|
93
85
|
).value,
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
this.#predicate = predicate;
|
|
99
|
-
|
|
100
|
-
this.#mut_skipping = true;
|
|
101
|
-
}
|
|
86
|
+
},
|
|
87
|
+
({ setNext }) => {
|
|
88
|
+
let mut_index: SafeUint | -1 = -1;
|
|
102
89
|
|
|
103
|
-
|
|
104
|
-
const par = this.parents[0];
|
|
90
|
+
let mut_skipping = true;
|
|
105
91
|
|
|
106
|
-
|
|
92
|
+
return (updateToken) => {
|
|
93
|
+
const sn = parentObservable.getSnapshot();
|
|
107
94
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
95
|
+
if (
|
|
96
|
+
parentObservable.updateToken !== updateToken ||
|
|
97
|
+
Optional.isNone(sn)
|
|
98
|
+
) {
|
|
99
|
+
return; // skip update
|
|
100
|
+
}
|
|
111
101
|
|
|
112
|
-
|
|
113
|
-
|
|
102
|
+
mut_index =
|
|
103
|
+
mut_index === -1 ? asSafeUint(0) : SafeUint.add(1, mut_index);
|
|
114
104
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
105
|
+
if (!predicate(sn.value, mut_index)) {
|
|
106
|
+
mut_skipping = false;
|
|
107
|
+
}
|
|
118
108
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
}
|
|
109
|
+
if (!mut_skipping) {
|
|
110
|
+
setNext(sn.value, updateToken);
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
},
|
|
114
|
+
);
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { Optional } from 'ts-data-forge';
|
|
2
|
-
import {
|
|
2
|
+
import { createAsyncChildObservable } from '../base/index.mjs';
|
|
3
3
|
import {
|
|
4
4
|
type DropInitialValueOperator,
|
|
5
5
|
type Observable,
|
|
6
6
|
type Subscription,
|
|
7
7
|
type SwitchMapOperatorObservable,
|
|
8
|
-
type UpdateToken,
|
|
9
8
|
} from '../types/index.mjs';
|
|
10
9
|
|
|
11
10
|
/**
|
|
@@ -106,61 +105,50 @@ export const switchMap =
|
|
|
106
105
|
mapToObservable: (curr: A) => Observable<B>,
|
|
107
106
|
): DropInitialValueOperator<A, B> =>
|
|
108
107
|
(parentObservable) =>
|
|
109
|
-
|
|
108
|
+
createSwitchMapObservable(parentObservable, mapToObservable);
|
|
110
109
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
{
|
|
115
|
-
|
|
116
|
-
#mut_observable: Observable<B> | undefined;
|
|
117
|
-
#mut_subscription: Subscription | undefined;
|
|
110
|
+
const createSwitchMapObservable = <A, B>(
|
|
111
|
+
parentObservable: Observable<A>,
|
|
112
|
+
mapToObservable: (curr: A) => Observable<B>,
|
|
113
|
+
): SwitchMapOperatorObservable<A, B> => {
|
|
114
|
+
let mut_observable: Observable<B> | undefined = undefined;
|
|
118
115
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
super({
|
|
116
|
+
let mut_subscription: Subscription | undefined = undefined;
|
|
117
|
+
|
|
118
|
+
return createAsyncChildObservable(
|
|
119
|
+
{
|
|
124
120
|
parents: [parentObservable],
|
|
125
121
|
initialValue: Optional.none,
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
this.#mapToObservable = mapToObservable;
|
|
129
|
-
|
|
130
|
-
this.#mut_observable = undefined;
|
|
131
|
-
|
|
132
|
-
this.#mut_subscription = undefined;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
override tryUpdate(updateToken: UpdateToken): void {
|
|
136
|
-
const par = this.parents[0];
|
|
137
|
-
|
|
138
|
-
const sn = par.getSnapshot();
|
|
139
|
-
|
|
140
|
-
if (par.updateToken !== updateToken || Optional.isNone(sn)) {
|
|
141
|
-
return; // skip update
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
this.#mut_observable?.complete();
|
|
122
|
+
onComplete: () => {
|
|
123
|
+
mut_subscription?.unsubscribe();
|
|
145
124
|
|
|
146
|
-
|
|
125
|
+
mut_observable?.complete();
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
({ startUpdate }) =>
|
|
129
|
+
(updateToken) => {
|
|
130
|
+
const sn = parentObservable.getSnapshot();
|
|
147
131
|
|
|
148
|
-
|
|
132
|
+
if (
|
|
133
|
+
parentObservable.updateToken !== updateToken ||
|
|
134
|
+
Optional.isNone(sn)
|
|
135
|
+
) {
|
|
136
|
+
return; // skip update
|
|
137
|
+
}
|
|
149
138
|
|
|
150
|
-
|
|
139
|
+
mut_observable?.complete();
|
|
151
140
|
|
|
152
|
-
|
|
153
|
-
this.startUpdate(curr);
|
|
154
|
-
});
|
|
141
|
+
mut_subscription?.unsubscribe();
|
|
155
142
|
|
|
156
|
-
|
|
157
|
-
}
|
|
143
|
+
const observable = mapToObservable(sn.value);
|
|
158
144
|
|
|
159
|
-
|
|
160
|
-
this.#mut_subscription?.unsubscribe();
|
|
145
|
+
mut_observable = observable;
|
|
161
146
|
|
|
162
|
-
|
|
147
|
+
const subscription = observable.subscribe((curr) => {
|
|
148
|
+
startUpdate(curr);
|
|
149
|
+
});
|
|
163
150
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
151
|
+
mut_subscription = subscription;
|
|
152
|
+
},
|
|
153
|
+
);
|
|
154
|
+
};
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { Optional } from 'ts-data-forge';
|
|
2
|
-
import {
|
|
2
|
+
import { createSyncChildObservable } from '../base/index.mjs';
|
|
3
3
|
import {
|
|
4
4
|
type KeepInitialValueOperator,
|
|
5
5
|
type Observable,
|
|
6
6
|
type TakeUntilOperatorObservable,
|
|
7
|
-
type UpdateToken,
|
|
8
7
|
} from '../types/index.mjs';
|
|
9
8
|
|
|
10
9
|
/**
|
|
@@ -60,40 +59,43 @@ export const takeUntil = <A,>(
|
|
|
60
59
|
): KeepInitialValueOperator<A, A> =>
|
|
61
60
|
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
62
61
|
((parentObservable) =>
|
|
63
|
-
|
|
62
|
+
createTakeUntilObservable(
|
|
64
63
|
parentObservable,
|
|
65
64
|
notifier,
|
|
66
65
|
)) as KeepInitialValueOperator<A, A>;
|
|
67
66
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
{
|
|
72
|
-
|
|
73
|
-
|
|
67
|
+
const createTakeUntilObservable = <A,>(
|
|
68
|
+
parentObservable: Observable<A>,
|
|
69
|
+
notifier: Observable<unknown>,
|
|
70
|
+
): TakeUntilOperatorObservable<A> => {
|
|
71
|
+
const observable = createSyncChildObservable<A, readonly [A]>(
|
|
72
|
+
{
|
|
74
73
|
parents: [parentObservable],
|
|
75
74
|
initialValue: parentObservable.getSnapshot(),
|
|
76
|
-
}
|
|
75
|
+
},
|
|
76
|
+
({ setNext }) =>
|
|
77
|
+
(updateToken) => {
|
|
78
|
+
const sn = parentObservable.getSnapshot();
|
|
77
79
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
},
|
|
85
|
-
);
|
|
86
|
-
}
|
|
80
|
+
if (
|
|
81
|
+
parentObservable.updateToken !== updateToken ||
|
|
82
|
+
Optional.isNone(sn)
|
|
83
|
+
) {
|
|
84
|
+
return; // skip update
|
|
85
|
+
}
|
|
87
86
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
const sn = par.getSnapshot();
|
|
87
|
+
setNext(sn.value, updateToken);
|
|
88
|
+
},
|
|
89
|
+
);
|
|
92
90
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
91
|
+
notifier.subscribe(
|
|
92
|
+
() => {
|
|
93
|
+
observable.complete();
|
|
94
|
+
},
|
|
95
|
+
() => {
|
|
96
|
+
observable.complete();
|
|
97
|
+
},
|
|
98
|
+
);
|
|
96
99
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
}
|
|
100
|
+
return observable;
|
|
101
|
+
};
|