@cascateer/core 2.1.15 → 2.1.16
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/package.json +1 -1
- package/src/api.ts +23 -25
- package/src/observable/ProxyObservable.ts +22 -10
- package/src/observable/ProxySubject.ts +9 -9
- package/src/observable/Signal.ts +2 -2
- package/src/operators/proxyReplaySubject.ts +4 -5
- package/src/types.ts +18 -9
package/package.json
CHANGED
package/src/api.ts
CHANGED
|
@@ -55,34 +55,32 @@ class Memoizable<Args, Result> {
|
|
|
55
55
|
thru(
|
|
56
56
|
new BehaviorSubject(false),
|
|
57
57
|
(pending) =>
|
|
58
|
-
new ProxyObservable(
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
tags,
|
|
77
|
-
intersectionWith(tags, invalidatedTags),
|
|
78
|
-
),
|
|
58
|
+
new ProxyObservable(this.predicate(args), (target) => ({
|
|
59
|
+
value: target.pipe(
|
|
60
|
+
tap({
|
|
61
|
+
subscribe: () => pending.next(true),
|
|
62
|
+
}),
|
|
63
|
+
finalize(() => pending.next(false)),
|
|
64
|
+
repeat({
|
|
65
|
+
delay: () =>
|
|
66
|
+
combineLatest([
|
|
67
|
+
memoizedEffect(args).pipe(
|
|
68
|
+
map((result) => this.tags(args, result)),
|
|
69
|
+
),
|
|
70
|
+
invalidatedTags,
|
|
71
|
+
]).pipe(
|
|
72
|
+
filter(([tags, invalidatedTags]) =>
|
|
73
|
+
isEqual(
|
|
74
|
+
tags,
|
|
75
|
+
intersectionWith(tags, invalidatedTags),
|
|
79
76
|
),
|
|
80
77
|
),
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
),
|
|
78
|
+
),
|
|
79
|
+
}),
|
|
80
|
+
shareReplay({ bufferSize: 1, refCount: false }),
|
|
81
|
+
),
|
|
84
82
|
pending,
|
|
85
|
-
),
|
|
83
|
+
})),
|
|
86
84
|
),
|
|
87
85
|
(args) => objectHash(args ?? null),
|
|
88
86
|
);
|
|
@@ -1,21 +1,33 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Observable } from "rxjs";
|
|
1
|
+
import { thru } from "lodash";
|
|
2
|
+
import { isObservable, Observable, of } from "rxjs";
|
|
3
3
|
|
|
4
|
-
export interface
|
|
5
|
-
(target:
|
|
4
|
+
export interface ProxyObservableDescriptor<T, U> {
|
|
5
|
+
(target: T):
|
|
6
|
+
| U
|
|
7
|
+
| {
|
|
8
|
+
value: U;
|
|
9
|
+
pending?: Observable<boolean>;
|
|
10
|
+
};
|
|
6
11
|
}
|
|
7
12
|
|
|
8
|
-
export class ProxyObservable<
|
|
13
|
+
export class ProxyObservable<
|
|
14
|
+
X,
|
|
15
|
+
Y = X,
|
|
16
|
+
T extends Observable<X> = Observable<X>,
|
|
17
|
+
> extends Observable<Y> {
|
|
9
18
|
pending: Observable<boolean>;
|
|
10
19
|
|
|
11
20
|
constructor(
|
|
12
|
-
target:
|
|
13
|
-
|
|
14
|
-
pending: Observable<boolean>,
|
|
21
|
+
target: T,
|
|
22
|
+
descriptor: ProxyObservableDescriptor<T, Observable<Y>>,
|
|
15
23
|
) {
|
|
16
|
-
|
|
24
|
+
const { value, pending = of(false) } = thru(
|
|
25
|
+
descriptor(target),
|
|
26
|
+
(descriptor) =>
|
|
27
|
+
isObservable(descriptor) ? { value: descriptor } : descriptor,
|
|
28
|
+
);
|
|
17
29
|
|
|
18
|
-
super((subscriber) =>
|
|
30
|
+
super((subscriber) => value.subscribe(subscriber));
|
|
19
31
|
|
|
20
32
|
this.pending = pending;
|
|
21
33
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { Observer, Subject, Unsubscribable } from "rxjs";
|
|
2
|
-
import { ProxyObservable,
|
|
1
|
+
import { Observable, Observer, Subject, Unsubscribable } from "rxjs";
|
|
2
|
+
import { ProxyObservable, ProxyObservableDescriptor } from "./ProxyObservable";
|
|
3
3
|
|
|
4
|
-
export class ProxySubject<
|
|
5
|
-
extends ProxyObservable<
|
|
6
|
-
implements Observer<
|
|
4
|
+
export class ProxySubject<X, Y = X, T extends Subject<X> = Subject<X>>
|
|
5
|
+
extends ProxyObservable<X, Y, T>
|
|
6
|
+
implements Observer<X>, Unsubscribable
|
|
7
7
|
{
|
|
8
|
-
next(value:
|
|
8
|
+
next(value: X): void {
|
|
9
9
|
this.target.next(value);
|
|
10
10
|
}
|
|
11
11
|
|
|
@@ -22,9 +22,9 @@ export class ProxySubject<T, U = T>
|
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
constructor(
|
|
25
|
-
private target:
|
|
26
|
-
|
|
25
|
+
private target: T,
|
|
26
|
+
descriptor: ProxyObservableDescriptor<T, Observable<Y>>,
|
|
27
27
|
) {
|
|
28
|
-
super(target,
|
|
28
|
+
super(target, descriptor);
|
|
29
29
|
}
|
|
30
30
|
}
|
package/src/observable/Signal.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { clone, identity, isEqual, memoize } from "lodash";
|
|
2
|
-
import { distinctUntilChanged, map, Observable,
|
|
2
|
+
import { distinctUntilChanged, map, Observable, UnaryFunction } from "rxjs";
|
|
3
3
|
import { ProxyObservable } from ".";
|
|
4
4
|
import {
|
|
5
5
|
asEnumerable,
|
|
@@ -54,7 +54,7 @@ export class Signal<T> extends ProxyObservable<T> {
|
|
|
54
54
|
enumerator?: SignalEnumerator<T>;
|
|
55
55
|
reflector?: SignalReflector<T>;
|
|
56
56
|
}) {
|
|
57
|
-
super(value, identity
|
|
57
|
+
super(value, identity);
|
|
58
58
|
|
|
59
59
|
this.enumerator = enumerator;
|
|
60
60
|
this.reflector = reflector;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { ReplaySubject } from "rxjs";
|
|
1
|
+
import { Observable, ReplaySubject, UnaryFunction } from "rxjs";
|
|
2
2
|
import { ProxySubject } from "../observable";
|
|
3
|
-
import { ProxyObservableHandler } from "../observable/ProxyObservable";
|
|
4
3
|
|
|
5
|
-
export const proxyReplaySubject = <
|
|
6
|
-
|
|
7
|
-
) => new ProxySubject<
|
|
4
|
+
export const proxyReplaySubject = <X, Y = X>(
|
|
5
|
+
descriptor: UnaryFunction<ReplaySubject<X>, Observable<Y>>,
|
|
6
|
+
) => new ProxySubject<X, Y, ReplaySubject<X>>(new ReplaySubject(), descriptor);
|
package/src/types.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Dictionary, mapValues,
|
|
1
|
+
import { Dictionary, mapValues, thru } from "lodash";
|
|
2
2
|
import {
|
|
3
|
+
BehaviorSubject,
|
|
3
4
|
combineLatest,
|
|
4
5
|
distinct,
|
|
5
|
-
identity,
|
|
6
6
|
map,
|
|
7
7
|
ReplaySubject,
|
|
8
8
|
switchMap,
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
import { Observable } from "rxjs/internal/Observable";
|
|
12
12
|
import { ObservableInput } from "rxjs/internal/types";
|
|
13
13
|
import { ProxyObservable } from "./observable";
|
|
14
|
-
import { concat } from "./operators";
|
|
14
|
+
import { concat, tapSubscription } from "./operators";
|
|
15
15
|
|
|
16
16
|
export interface Effect<Args, Result> extends UnaryFunction<
|
|
17
17
|
Args,
|
|
@@ -44,16 +44,25 @@ export class ProxyEffectInterceptor extends ReplaySubject<
|
|
|
44
44
|
): ProxyEffects<Effects> {
|
|
45
45
|
return mapValues(
|
|
46
46
|
effects,
|
|
47
|
-
(effect) => (args) =>
|
|
47
|
+
(effect) => (args) =>
|
|
48
|
+
thru(
|
|
49
|
+
new BehaviorSubject(false),
|
|
50
|
+
(subscribed) =>
|
|
51
|
+
new ProxyObservable(effect(args), (target) => ({
|
|
52
|
+
value: target.pipe(tapSubscription(subscribed)),
|
|
53
|
+
pending: combineLatest([target.pending, subscribed]).pipe(
|
|
54
|
+
map((values) => values.every(Boolean)),
|
|
55
|
+
),
|
|
56
|
+
})),
|
|
57
|
+
),
|
|
48
58
|
);
|
|
49
59
|
}
|
|
50
60
|
|
|
51
61
|
proxy<Args, Result>(effect: Effect<Args, Result>): ProxyEffect<Args, Result> {
|
|
52
62
|
return (args) =>
|
|
53
|
-
new ProxyObservable(
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
this.pipe(
|
|
63
|
+
new ProxyObservable(effect(args), (target) => ({
|
|
64
|
+
value: target,
|
|
65
|
+
pending: this.pipe(
|
|
57
66
|
distinct(),
|
|
58
67
|
concat(),
|
|
59
68
|
switchMap((sources) =>
|
|
@@ -61,7 +70,7 @@ export class ProxyEffectInterceptor extends ReplaySubject<
|
|
|
61
70
|
),
|
|
62
71
|
map((values) => values.some(Boolean)),
|
|
63
72
|
),
|
|
64
|
-
);
|
|
73
|
+
}));
|
|
65
74
|
}
|
|
66
75
|
}
|
|
67
76
|
|