@cascateer/core 2.1.10 → 2.1.12

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/types.ts +28 -22
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cascateer/core",
3
- "version": "2.1.10",
3
+ "version": "2.1.12",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/cascateer/core.git"
package/src/types.ts CHANGED
@@ -1,4 +1,5 @@
1
- import { Dictionary, mapValues, tap } from "lodash";
1
+ import { Dictionary, mapValues, memoize, tap } from "lodash";
2
+ import objectHash from "object-hash";
2
3
  import {
3
4
  combineLatest,
4
5
  distinct,
@@ -42,35 +43,40 @@ export class AsyncEffectInterceptor extends ReplaySubject<
42
43
  intercept<Effects extends Dictionary<AsyncEffect<any, any>>>(
43
44
  effects: Effects,
44
45
  ): AsyncEffects<Effects> {
45
- return mapValues(
46
- effects,
47
- (effect) => (args) => tap(effect(args), (source) => this.next(source)),
46
+ return mapValues(effects, (effect) =>
47
+ memoize(
48
+ (args) => tap(effect(args), (source) => this.next(source)),
49
+ (args) => objectHash(args ?? null),
50
+ ),
48
51
  );
49
52
  }
50
53
 
51
54
  toAsyncEffect<Args, Result>(
52
55
  effect: Effect<Args, Result>,
53
56
  ): AsyncEffect<Args, Result> {
54
- return (args) =>
55
- new (class
56
- extends ProxyObservable<Result>
57
- implements AsyncObservable<Result>
58
- {
59
- pending: Observable<boolean>;
57
+ return memoize(
58
+ (args) =>
59
+ new (class
60
+ extends ProxyObservable<Result>
61
+ implements AsyncObservable<Result>
62
+ {
63
+ pending: Observable<boolean>;
60
64
 
61
- constructor(interceptor: AsyncEffectInterceptor) {
62
- super(effect(args), identity);
65
+ constructor(interceptor: AsyncEffectInterceptor) {
66
+ super(effect(args), identity);
63
67
 
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);
68
+ this.pending = interceptor.pipe(
69
+ distinct(),
70
+ concat(),
71
+ switchMap((sources) =>
72
+ combineLatest(sources.map((source) => source.pending)),
73
+ ),
74
+ map((values) => values.some(Boolean)),
75
+ );
76
+ }
77
+ })(this),
78
+ (args) => objectHash(args ?? null),
79
+ );
74
80
  }
75
81
  }
76
82