@cascateer/core 2.1.16 → 2.1.18
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/observable/ProxyObservable.ts +27 -3
- package/src/types.ts +10 -12
package/package.json
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
|
-
import { thru } from "lodash";
|
|
2
|
-
import {
|
|
1
|
+
import { tap, thru } from "lodash";
|
|
2
|
+
import {
|
|
3
|
+
isObservable,
|
|
4
|
+
map,
|
|
5
|
+
Observable,
|
|
6
|
+
of,
|
|
7
|
+
scan,
|
|
8
|
+
Subject,
|
|
9
|
+
Subscriber,
|
|
10
|
+
UnaryFunction,
|
|
11
|
+
} from "rxjs";
|
|
3
12
|
|
|
4
13
|
export interface ProxyObservableDescriptor<T, U> {
|
|
5
14
|
(target: T):
|
|
@@ -16,6 +25,7 @@ export class ProxyObservable<
|
|
|
16
25
|
T extends Observable<X> = Observable<X>,
|
|
17
26
|
> extends Observable<Y> {
|
|
18
27
|
pending: Observable<boolean>;
|
|
28
|
+
refCount: Observable<number>;
|
|
19
29
|
|
|
20
30
|
constructor(
|
|
21
31
|
target: T,
|
|
@@ -27,8 +37,22 @@ export class ProxyObservable<
|
|
|
27
37
|
isObservable(descriptor) ? { value: descriptor } : descriptor,
|
|
28
38
|
);
|
|
29
39
|
|
|
30
|
-
|
|
40
|
+
const subscribers = new Subject<UnaryFunction<Set<Subscriber<Y>>, void>>();
|
|
41
|
+
|
|
42
|
+
super((subscriber) => {
|
|
43
|
+
subscribers.next((subscribers) => subscribers.add(subscriber));
|
|
44
|
+
|
|
45
|
+
subscriber.add(() =>
|
|
46
|
+
subscribers.next((subscribers) => subscribers.delete(subscriber)),
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
return value.subscribe(subscriber);
|
|
50
|
+
});
|
|
31
51
|
|
|
32
52
|
this.pending = pending;
|
|
53
|
+
this.refCount = subscribers.pipe(
|
|
54
|
+
scan(tap, new Set<Subscriber<Y>>()),
|
|
55
|
+
map((subscribers) => subscribers.size),
|
|
56
|
+
);
|
|
33
57
|
}
|
|
34
58
|
}
|
package/src/types.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { Dictionary, mapValues,
|
|
1
|
+
import { Dictionary, mapValues, tap } from "lodash";
|
|
2
2
|
import {
|
|
3
|
-
BehaviorSubject,
|
|
4
3
|
combineLatest,
|
|
5
4
|
distinct,
|
|
6
5
|
map,
|
|
@@ -11,7 +10,7 @@ import {
|
|
|
11
10
|
import { Observable } from "rxjs/internal/Observable";
|
|
12
11
|
import { ObservableInput } from "rxjs/internal/types";
|
|
13
12
|
import { ProxyObservable } from "./observable";
|
|
14
|
-
import { concat
|
|
13
|
+
import { concat } from "./operators";
|
|
15
14
|
|
|
16
15
|
export interface Effect<Args, Result> extends UnaryFunction<
|
|
17
16
|
Args,
|
|
@@ -45,15 +44,14 @@ export class ProxyEffectInterceptor extends ReplaySubject<
|
|
|
45
44
|
return mapValues(
|
|
46
45
|
effects,
|
|
47
46
|
(effect) => (args) =>
|
|
48
|
-
|
|
49
|
-
new
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
})),
|
|
47
|
+
tap(
|
|
48
|
+
new ProxyObservable(effect(args), (target) => ({
|
|
49
|
+
value: target,
|
|
50
|
+
pending: combineLatest([target.pending, target.refCount]).pipe(
|
|
51
|
+
map((values) => values.every(Boolean)),
|
|
52
|
+
),
|
|
53
|
+
})),
|
|
54
|
+
(source) => this.next(source),
|
|
57
55
|
),
|
|
58
56
|
);
|
|
59
57
|
}
|