@cascateer/core 2.1.12 → 2.1.14
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 +46 -19
- package/src/observable/AsyncObservable.ts +4 -5
- package/src/types.ts +22 -28
package/package.json
CHANGED
package/src/api.ts
CHANGED
|
@@ -8,7 +8,9 @@ import {
|
|
|
8
8
|
} from "lodash";
|
|
9
9
|
import objectHash from "object-hash";
|
|
10
10
|
import {
|
|
11
|
+
BehaviorSubject,
|
|
11
12
|
combineLatest,
|
|
13
|
+
defer,
|
|
12
14
|
filter,
|
|
13
15
|
finalize,
|
|
14
16
|
lastValueFrom,
|
|
@@ -48,26 +50,51 @@ class Memoizable<Args, Result> {
|
|
|
48
50
|
|
|
49
51
|
this.subscribe = (invalidatedTags) => {
|
|
50
52
|
const memoizedEffect: AsyncEffect<Args, Result> = memoize(
|
|
51
|
-
(args) =>
|
|
52
|
-
new
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
53
|
+
(args) => {
|
|
54
|
+
const pending = new BehaviorSubject(false);
|
|
55
|
+
|
|
56
|
+
return new (class
|
|
57
|
+
extends Observable<Result>
|
|
58
|
+
implements AsyncObservable<Result>
|
|
59
|
+
{
|
|
60
|
+
pending: Observable<boolean>;
|
|
61
|
+
|
|
62
|
+
constructor(
|
|
63
|
+
source: Observable<Result>,
|
|
64
|
+
tags: TagsConstructor<Args, Result>,
|
|
65
|
+
) {
|
|
66
|
+
super((subscriber) =>
|
|
67
|
+
defer(
|
|
68
|
+
() => (
|
|
69
|
+
pending.next(true),
|
|
70
|
+
source.pipe(
|
|
71
|
+
finalize(() => pending.next(false)),
|
|
72
|
+
repeat({
|
|
73
|
+
delay: () =>
|
|
74
|
+
combineLatest([
|
|
75
|
+
memoizedEffect(args).pipe(
|
|
76
|
+
map((result) => tags(args, result)),
|
|
77
|
+
),
|
|
78
|
+
invalidatedTags,
|
|
79
|
+
]).pipe(
|
|
80
|
+
filter(([tags, invalidatedTags]) =>
|
|
81
|
+
isEqual(
|
|
82
|
+
tags,
|
|
83
|
+
intersectionWith(tags, invalidatedTags),
|
|
84
|
+
),
|
|
85
|
+
),
|
|
86
|
+
),
|
|
87
|
+
}),
|
|
88
|
+
shareReplay({ bufferSize: 1, refCount: false }),
|
|
89
|
+
)
|
|
66
90
|
),
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
91
|
+
).subscribe(subscriber),
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
this.pending = pending;
|
|
95
|
+
}
|
|
96
|
+
})(this.predicate(args), this.tags);
|
|
97
|
+
},
|
|
71
98
|
(args) => objectHash(args ?? null),
|
|
72
99
|
);
|
|
73
100
|
|
|
@@ -7,12 +7,13 @@ import {
|
|
|
7
7
|
Observable,
|
|
8
8
|
UnaryFunction,
|
|
9
9
|
} from "rxjs";
|
|
10
|
+
import { ProxyObservable } from "./ProxyObservable";
|
|
10
11
|
|
|
11
12
|
export interface AsyncObservable<T> {
|
|
12
13
|
pending: Observable<boolean>;
|
|
13
14
|
}
|
|
14
15
|
|
|
15
|
-
export class AsyncObservable<T> extends
|
|
16
|
+
export class AsyncObservable<T> extends ProxyObservable<T> {
|
|
16
17
|
constructor(
|
|
17
18
|
source: Observable<T> | UnaryFunction<() => void, Observable<T>>,
|
|
18
19
|
) {
|
|
@@ -23,10 +24,8 @@ export class AsyncObservable<T> extends Observable<T> {
|
|
|
23
24
|
source = constant(source);
|
|
24
25
|
}
|
|
25
26
|
|
|
26
|
-
super((
|
|
27
|
-
defer(() => (pending.next(true), source(complete))
|
|
28
|
-
.pipe(finalize(complete))
|
|
29
|
-
.subscribe(subscriber),
|
|
27
|
+
super(source(complete), (source) =>
|
|
28
|
+
defer(() => (pending.next(true), source)).pipe(finalize(complete)),
|
|
30
29
|
);
|
|
31
30
|
|
|
32
31
|
this.pending = pending;
|
package/src/types.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { Dictionary, mapValues,
|
|
2
|
-
import objectHash from "object-hash";
|
|
1
|
+
import { Dictionary, mapValues, tap } from "lodash";
|
|
3
2
|
import {
|
|
4
3
|
combineLatest,
|
|
5
4
|
distinct,
|
|
@@ -43,40 +42,35 @@ export class AsyncEffectInterceptor extends ReplaySubject<
|
|
|
43
42
|
intercept<Effects extends Dictionary<AsyncEffect<any, any>>>(
|
|
44
43
|
effects: Effects,
|
|
45
44
|
): AsyncEffects<Effects> {
|
|
46
|
-
return mapValues(
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
(args) => objectHash(args ?? null),
|
|
50
|
-
),
|
|
45
|
+
return mapValues(
|
|
46
|
+
effects,
|
|
47
|
+
(effect) => (args) => tap(effect(args), (source) => this.next(source)),
|
|
51
48
|
);
|
|
52
49
|
}
|
|
53
50
|
|
|
54
51
|
toAsyncEffect<Args, Result>(
|
|
55
52
|
effect: Effect<Args, Result>,
|
|
56
53
|
): AsyncEffect<Args, Result> {
|
|
57
|
-
return
|
|
58
|
-
(
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
pending: Observable<boolean>;
|
|
54
|
+
return (args) =>
|
|
55
|
+
new (class
|
|
56
|
+
extends ProxyObservable<Result>
|
|
57
|
+
implements AsyncObservable<Result>
|
|
58
|
+
{
|
|
59
|
+
pending: Observable<boolean>;
|
|
64
60
|
|
|
65
|
-
|
|
66
|
-
|
|
61
|
+
constructor(interceptor: AsyncEffectInterceptor) {
|
|
62
|
+
super(effect(args), identity);
|
|
67
63
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
(args) => objectHash(args ?? null),
|
|
79
|
-
);
|
|
64
|
+
this.pending = interceptor.pipe(
|
|
65
|
+
distinct(),
|
|
66
|
+
concat(),
|
|
67
|
+
switchMap((sources) =>
|
|
68
|
+
combineLatest(sources.map((source) => source.pending)),
|
|
69
|
+
),
|
|
70
|
+
map((values) => values.some(Boolean)),
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
})(this);
|
|
80
74
|
}
|
|
81
75
|
}
|
|
82
76
|
|