@cascateer/core 2.1.29 → 2.1.31
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 +7 -5
- package/src/observable/ProxyObservable.ts +4 -4
- package/src/operators/index.ts +0 -1
- package/src/types.ts +9 -11
- package/src/operators/tapSubscription.ts +0 -14
package/package.json
CHANGED
package/src/api.ts
CHANGED
|
@@ -4,9 +4,7 @@ import {
|
|
|
4
4
|
intersectionWith,
|
|
5
5
|
isEqual,
|
|
6
6
|
isFunction,
|
|
7
|
-
memoize,
|
|
8
7
|
} from "lodash";
|
|
9
|
-
import objectHash from "object-hash";
|
|
10
8
|
import {
|
|
11
9
|
combineLatest,
|
|
12
10
|
filter,
|
|
@@ -21,7 +19,12 @@ import {
|
|
|
21
19
|
tap,
|
|
22
20
|
UnaryFunction,
|
|
23
21
|
} from "rxjs";
|
|
24
|
-
import {
|
|
22
|
+
import {
|
|
23
|
+
asObservable,
|
|
24
|
+
ExtendableDictionary,
|
|
25
|
+
memoizeHashed,
|
|
26
|
+
property,
|
|
27
|
+
} from "./lib";
|
|
25
28
|
import { ProxyObservable } from "./observable";
|
|
26
29
|
import { Action, MaybeArray, MaybeObservable, ProxyEffect } from "./types";
|
|
27
30
|
|
|
@@ -48,7 +51,7 @@ class Memoizable<Args, Result> {
|
|
|
48
51
|
this.tags = isFunction(tags) ? tags : constant([tags ?? []].flat());
|
|
49
52
|
|
|
50
53
|
this.subscribe = (invalidatedTags) => {
|
|
51
|
-
const memoizedEffect: ProxyEffect<Args, Result> =
|
|
54
|
+
const memoizedEffect: ProxyEffect<Args, Result> = memoizeHashed(
|
|
52
55
|
(args) =>
|
|
53
56
|
new ProxyObservable((pending) =>
|
|
54
57
|
this.predicate(args).pipe(
|
|
@@ -72,7 +75,6 @@ class Memoizable<Args, Result> {
|
|
|
72
75
|
shareReplay({ bufferSize: 1, refCount: false }),
|
|
73
76
|
),
|
|
74
77
|
),
|
|
75
|
-
(args) => objectHash(args ?? null),
|
|
76
78
|
);
|
|
77
79
|
|
|
78
80
|
return memoizedEffect;
|
|
@@ -20,14 +20,14 @@ export class ProxyObservable<
|
|
|
20
20
|
|
|
21
21
|
constructor(
|
|
22
22
|
target: U | ((pending: NextObserver<boolean>) => U),
|
|
23
|
-
|
|
23
|
+
handler?: (target: U, receiver: ProxyObservable<T>) => Observable<boolean>,
|
|
24
24
|
) {
|
|
25
25
|
const subscribers = new ReplaySubject<
|
|
26
26
|
UnaryFunction<Set<Subscriber<T>>, void>
|
|
27
27
|
>();
|
|
28
28
|
|
|
29
29
|
const pending = new BehaviorSubject(false);
|
|
30
|
-
const
|
|
30
|
+
const memoizedTarget = once(() =>
|
|
31
31
|
isObservable(target) ? target : target(pending),
|
|
32
32
|
);
|
|
33
33
|
|
|
@@ -38,7 +38,7 @@ export class ProxyObservable<
|
|
|
38
38
|
subscribers.next((subscribers) => subscribers.delete(subscriber)),
|
|
39
39
|
);
|
|
40
40
|
|
|
41
|
-
return
|
|
41
|
+
return memoizedTarget().subscribe(subscriber);
|
|
42
42
|
});
|
|
43
43
|
|
|
44
44
|
this.pending = pending;
|
|
@@ -47,6 +47,6 @@ export class ProxyObservable<
|
|
|
47
47
|
map((subscribers) => subscribers.size),
|
|
48
48
|
);
|
|
49
49
|
|
|
50
|
-
|
|
50
|
+
handler?.call(null, memoizedTarget(), this).subscribe(pending);
|
|
51
51
|
}
|
|
52
52
|
}
|
package/src/operators/index.ts
CHANGED
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,
|
|
@@ -10,6 +9,7 @@ import {
|
|
|
10
9
|
} from "rxjs";
|
|
11
10
|
import { Observable } from "rxjs/internal/Observable";
|
|
12
11
|
import { ObservableInput } from "rxjs/internal/types";
|
|
12
|
+
import { memoizeHashed } from "./lib";
|
|
13
13
|
import { ProxyObservable } from "./observable";
|
|
14
14
|
import { concat } from "./operators";
|
|
15
15
|
|
|
@@ -43,17 +43,15 @@ export class ProxyEffectInterceptor extends ReplaySubject<
|
|
|
43
43
|
effects: Effects,
|
|
44
44
|
): ProxyEffects<Effects> {
|
|
45
45
|
return mapValues(effects, (effect) =>
|
|
46
|
-
|
|
47
|
-
(
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
map((values) => values.every(Boolean)),
|
|
52
|
-
),
|
|
46
|
+
memoizeHashed((args) =>
|
|
47
|
+
tap(
|
|
48
|
+
new ProxyObservable(effect(args), (target, receiver) =>
|
|
49
|
+
combineLatest([target.pending, receiver.refCount]).pipe(
|
|
50
|
+
map((values) => values.every(Boolean)),
|
|
53
51
|
),
|
|
54
|
-
(source) => this.next(source),
|
|
55
52
|
),
|
|
56
|
-
|
|
53
|
+
(source) => this.next(source),
|
|
54
|
+
),
|
|
57
55
|
),
|
|
58
56
|
);
|
|
59
57
|
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { MonoTypeOperatorFunction, NextObserver, tap } from "rxjs";
|
|
2
|
-
|
|
3
|
-
export const tapSubscription =
|
|
4
|
-
<T>(observer?: NextObserver<boolean>): MonoTypeOperatorFunction<T> =>
|
|
5
|
-
(source) => {
|
|
6
|
-
let subscriptions = 0;
|
|
7
|
-
|
|
8
|
-
return source.pipe(
|
|
9
|
-
tap({
|
|
10
|
-
subscribe: () => observer?.next(++subscriptions > 0),
|
|
11
|
-
unsubscribe: () => observer?.next(--subscriptions > 0),
|
|
12
|
-
}),
|
|
13
|
-
);
|
|
14
|
-
};
|