@cascateer/core 2.1.20 → 2.1.22
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 +21 -31
- package/src/observable/ProxyObservable.ts +15 -27
- package/src/observable/Signal.ts +1 -1
- package/src/types.ts +6 -8
package/package.json
CHANGED
package/src/api.ts
CHANGED
|
@@ -5,11 +5,9 @@ import {
|
|
|
5
5
|
isEqual,
|
|
6
6
|
isFunction,
|
|
7
7
|
memoize,
|
|
8
|
-
thru,
|
|
9
8
|
} from "lodash";
|
|
10
9
|
import objectHash from "object-hash";
|
|
11
10
|
import {
|
|
12
|
-
BehaviorSubject,
|
|
13
11
|
combineLatest,
|
|
14
12
|
filter,
|
|
15
13
|
finalize,
|
|
@@ -52,35 +50,27 @@ class Memoizable<Args, Result> {
|
|
|
52
50
|
this.subscribe = (invalidatedTags) => {
|
|
53
51
|
const memoizedEffect: ProxyEffect<Args, Result> = memoize(
|
|
54
52
|
(args) =>
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
),
|
|
77
|
-
),
|
|
78
|
-
),
|
|
79
|
-
}),
|
|
80
|
-
shareReplay({ bufferSize: 1, refCount: false }),
|
|
81
|
-
),
|
|
82
|
-
pending,
|
|
83
|
-
})),
|
|
53
|
+
new ProxyObservable((pending) =>
|
|
54
|
+
this.predicate(args).pipe(
|
|
55
|
+
tap({
|
|
56
|
+
subscribe: () => pending.next(true),
|
|
57
|
+
}),
|
|
58
|
+
finalize(() => pending.next(false)),
|
|
59
|
+
repeat({
|
|
60
|
+
delay: () =>
|
|
61
|
+
combineLatest([
|
|
62
|
+
memoizedEffect(args).pipe(
|
|
63
|
+
map((result) => this.tags(args, result)),
|
|
64
|
+
),
|
|
65
|
+
invalidatedTags,
|
|
66
|
+
]).pipe(
|
|
67
|
+
filter(([tags, invalidatedTags]) =>
|
|
68
|
+
isEqual(tags, intersectionWith(tags, invalidatedTags)),
|
|
69
|
+
),
|
|
70
|
+
),
|
|
71
|
+
}),
|
|
72
|
+
shareReplay({ bufferSize: 1, refCount: false }),
|
|
73
|
+
),
|
|
84
74
|
),
|
|
85
75
|
(args) => objectHash(args ?? null),
|
|
86
76
|
);
|
|
@@ -1,46 +1,31 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { constant, once, tap } from "lodash";
|
|
2
2
|
import {
|
|
3
|
+
BehaviorSubject,
|
|
3
4
|
isObservable,
|
|
4
5
|
map,
|
|
6
|
+
NextObserver,
|
|
5
7
|
Observable,
|
|
6
|
-
of,
|
|
7
8
|
ReplaySubject,
|
|
8
9
|
scan,
|
|
9
10
|
Subscriber,
|
|
10
11
|
UnaryFunction,
|
|
11
12
|
} from "rxjs";
|
|
12
13
|
|
|
13
|
-
export
|
|
14
|
-
(target: T):
|
|
15
|
-
| U
|
|
16
|
-
| {
|
|
17
|
-
value: U;
|
|
18
|
-
pending?: Observable<boolean>;
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export class ProxyObservable<
|
|
23
|
-
X,
|
|
24
|
-
Y = X,
|
|
25
|
-
T extends Observable<X> = Observable<X>,
|
|
26
|
-
> extends Observable<Y> {
|
|
14
|
+
export class ProxyObservable<T> extends Observable<T> {
|
|
27
15
|
pending: Observable<boolean>;
|
|
28
16
|
refCount: Observable<number>;
|
|
29
17
|
|
|
30
18
|
constructor(
|
|
31
|
-
target: T,
|
|
32
|
-
|
|
19
|
+
target: Observable<T> | ((pending: NextObserver<boolean>) => Observable<T>),
|
|
20
|
+
pendingFactory?: UnaryFunction<ProxyObservable<T>, Observable<boolean>>,
|
|
33
21
|
) {
|
|
34
|
-
const { value, pending = of(false) } = thru(
|
|
35
|
-
descriptor(target),
|
|
36
|
-
(descriptor) =>
|
|
37
|
-
isObservable(descriptor) ? { value: descriptor } : descriptor,
|
|
38
|
-
);
|
|
39
|
-
|
|
40
22
|
const subscribers = new ReplaySubject<
|
|
41
|
-
UnaryFunction<Set<Subscriber<
|
|
23
|
+
UnaryFunction<Set<Subscriber<T>>, void>
|
|
42
24
|
>();
|
|
43
25
|
|
|
26
|
+
const project = once(isObservable(target) ? constant(target) : target);
|
|
27
|
+
const pending = new BehaviorSubject(false);
|
|
28
|
+
|
|
44
29
|
super((subscriber) => {
|
|
45
30
|
subscribers.next((subscribers) => subscribers.add(subscriber));
|
|
46
31
|
|
|
@@ -48,12 +33,15 @@ export class ProxyObservable<
|
|
|
48
33
|
subscribers.next((subscribers) => subscribers.delete(subscriber)),
|
|
49
34
|
);
|
|
50
35
|
|
|
51
|
-
return
|
|
36
|
+
return project(pending).subscribe(subscriber);
|
|
52
37
|
});
|
|
53
38
|
|
|
39
|
+
console.log(pendingFactory, this);
|
|
40
|
+
pendingFactory?.call(null, this).subscribe(pending);
|
|
41
|
+
|
|
54
42
|
this.pending = pending;
|
|
55
43
|
this.refCount = subscribers.pipe(
|
|
56
|
-
scan(tap, new Set<Subscriber<
|
|
44
|
+
scan(tap, new Set<Subscriber<T>>()),
|
|
57
45
|
map((subscribers) => subscribers.size),
|
|
58
46
|
);
|
|
59
47
|
}
|
package/src/observable/Signal.ts
CHANGED
package/src/types.ts
CHANGED
|
@@ -45,12 +45,11 @@ export class ProxyEffectInterceptor extends ReplaySubject<
|
|
|
45
45
|
effects,
|
|
46
46
|
(effect) => (args) =>
|
|
47
47
|
tap(
|
|
48
|
-
new ProxyObservable(effect(args), (target) =>
|
|
49
|
-
|
|
50
|
-
pending: combineLatest([target.pending, target.refCount]).pipe(
|
|
48
|
+
new ProxyObservable(effect(args), (target) =>
|
|
49
|
+
combineLatest([target.pending, target.refCount]).pipe(
|
|
51
50
|
map((values) => values.every(Boolean)),
|
|
52
51
|
),
|
|
53
|
-
|
|
52
|
+
),
|
|
54
53
|
(source) => this.next(source),
|
|
55
54
|
),
|
|
56
55
|
);
|
|
@@ -58,9 +57,8 @@ export class ProxyEffectInterceptor extends ReplaySubject<
|
|
|
58
57
|
|
|
59
58
|
proxy<Args, Result>(effect: Effect<Args, Result>): ProxyEffect<Args, Result> {
|
|
60
59
|
return (args) =>
|
|
61
|
-
new ProxyObservable(effect(args), (
|
|
62
|
-
|
|
63
|
-
pending: this.pipe(
|
|
60
|
+
new ProxyObservable(effect(args), () =>
|
|
61
|
+
this.pipe(
|
|
64
62
|
distinct(),
|
|
65
63
|
concat(),
|
|
66
64
|
switchMap((sources) =>
|
|
@@ -68,7 +66,7 @@ export class ProxyEffectInterceptor extends ReplaySubject<
|
|
|
68
66
|
),
|
|
69
67
|
map((values) => values.some(Boolean)),
|
|
70
68
|
),
|
|
71
|
-
|
|
69
|
+
);
|
|
72
70
|
}
|
|
73
71
|
}
|
|
74
72
|
|