@cascateer/core 2.1.11 → 2.1.13

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cascateer/core",
3
- "version": "2.1.11",
3
+ "version": "2.1.13",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/cascateer/core.git"
package/src/api.ts CHANGED
@@ -8,6 +8,7 @@ import {
8
8
  } from "lodash";
9
9
  import objectHash from "object-hash";
10
10
  import {
11
+ BehaviorSubject,
11
12
  combineLatest,
12
13
  filter,
13
14
  finalize,
@@ -48,26 +49,51 @@ class Memoizable<Args, Result> {
48
49
 
49
50
  this.subscribe = (invalidatedTags) => {
50
51
  const memoizedEffect: AsyncEffect<Args, Result> = memoize(
51
- (args) =>
52
- new AsyncObservable((complete) =>
53
- this.predicate(args).pipe(
54
- finalize(() => (console.log("completed"), complete())),
55
- repeat({
56
- delay: () =>
57
- combineLatest([
58
- memoizedEffect(args).pipe(
59
- map((result) => this.tags(args, result)),
60
- ),
61
- invalidatedTags,
62
- ]).pipe(
63
- filter(([tags, invalidatedTags]) =>
64
- isEqual(tags, intersectionWith(tags, invalidatedTags)),
65
- ),
66
- ),
67
- }),
68
- shareReplay({ bufferSize: 1, refCount: false }),
69
- ),
70
- ),
52
+ (args) => {
53
+ const pending = new BehaviorSubject(false);
54
+
55
+ return new (class
56
+ extends Observable<Result>
57
+ implements AsyncObservable<Result>
58
+ {
59
+ pending: Observable<boolean>;
60
+
61
+ constructor(
62
+ source: Observable<Result>,
63
+ tags: TagsConstructor<Args, Result>,
64
+ ) {
65
+ super(
66
+ (subscriber) => (
67
+ pending.next(true),
68
+ source
69
+ .pipe(
70
+ finalize(() => pending.next(false)),
71
+ repeat({
72
+ delay: () =>
73
+ combineLatest([
74
+ memoizedEffect(args).pipe(
75
+ map((result) => tags(args, result)),
76
+ ),
77
+ invalidatedTags,
78
+ ]).pipe(
79
+ filter(([tags, invalidatedTags]) =>
80
+ isEqual(
81
+ tags,
82
+ intersectionWith(tags, invalidatedTags),
83
+ ),
84
+ ),
85
+ ),
86
+ }),
87
+ shareReplay({ bufferSize: 1, refCount: false }),
88
+ )
89
+ .subscribe(subscriber)
90
+ ),
91
+ );
92
+
93
+ this.pending = pending;
94
+ }
95
+ })(this.predicate(args), this.tags);
96
+ },
71
97
  (args) => objectHash(args ?? null),
72
98
  );
73
99
 
@@ -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 Observable<T> {
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((subscriber) =>
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, memoize, tap } from "lodash";
2
- import objectHash from "object-hash";
1
+ import { Dictionary, mapValues, tap } from "lodash";
3
2
  import {
4
3
  combineLatest,
5
4
  distinct,
@@ -43,11 +42,9 @@ 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(effects, (effect) =>
47
- memoize(
48
- (args) => tap(effect(args), (source) => this.next(source)),
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