@cascateer/core 2.0.23 → 2.0.25

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.0.23",
3
+ "version": "2.0.25",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/cascateer/core.git"
package/src/api.ts CHANGED
@@ -8,7 +8,6 @@ import {
8
8
  } from "lodash";
9
9
  import objectHash from "object-hash";
10
10
  import {
11
- BehaviorSubject,
12
11
  combineLatest,
13
12
  filter,
14
13
  lastValueFrom,
@@ -18,19 +17,11 @@ import {
18
17
  repeat,
19
18
  shareReplay,
20
19
  Subject,
21
- tap,
22
20
  UnaryFunction,
23
21
  } from "rxjs";
24
22
  import { asObservable, ExtendableDictionary, property } from "./lib";
25
23
  import { TapObservable } from "./observable";
26
- import { tapSubscription } from "./operators";
27
- import {
28
- Action,
29
- Effect,
30
- MaybeArray,
31
- MaybeObservable,
32
- TapEffect,
33
- } from "./types";
24
+ import { Action, MaybeArray, MaybeObservable, TapEffect } from "./types";
34
25
 
35
26
  interface TagsConstructor<Args, Result> {
36
27
  (args: Args, result: Result): string[];
@@ -55,35 +46,30 @@ class Memoizable<Args, Result> {
55
46
  this.tags = isFunction(tags) ? tags : constant([tags ?? []].flat());
56
47
 
57
48
  this.subscribe = (invalidatedTags) => {
58
- const loading = new BehaviorSubject(false);
59
-
60
- const effect: Effect<Args, Result> = memoize(
49
+ const memoizedEffect: TapEffect<Args, Result> = memoize(
61
50
  (args) =>
62
- this.predicate(args).pipe(
63
- tapSubscription(loading),
64
- tap({
65
- complete: () => loading.next(false),
66
- }),
67
- repeat({
68
- delay: () =>
69
- combineLatest([
70
- effect(args).pipe(map((result) => this.tags(args, result))),
71
- invalidatedTags,
72
- ]).pipe(
73
- filter(([tags, invalidatedTags]) =>
74
- isEqual(tags, intersectionWith(tags, invalidatedTags)),
51
+ new TapObservable(
52
+ this.predicate(args).pipe(
53
+ repeat({
54
+ delay: () =>
55
+ combineLatest([
56
+ memoizedEffect(args).pipe(
57
+ map((result) => this.tags(args, result)),
58
+ ),
59
+ invalidatedTags,
60
+ ]).pipe(
61
+ filter(([tags, invalidatedTags]) =>
62
+ isEqual(tags, intersectionWith(tags, invalidatedTags)),
63
+ ),
75
64
  ),
76
- ),
77
- }),
78
- shareReplay({ bufferSize: 1, refCount: false }),
65
+ }),
66
+ shareReplay({ bufferSize: 1, refCount: false }),
67
+ ),
79
68
  ),
80
69
  (args) => objectHash(args ?? null),
81
70
  );
82
71
 
83
- return memoize(
84
- (args) => new TapObservable(effect(args), loading),
85
- (args) => objectHash(args ?? null),
86
- );
72
+ return memoizedEffect;
87
73
  };
88
74
 
89
75
  this.share = (invalidatedTags) => (args) =>
@@ -1,11 +1,4 @@
1
- import {
2
- BehaviorSubject,
3
- combineLatest,
4
- distinctUntilChanged,
5
- map,
6
- Observable,
7
- } from "rxjs";
8
- import { tapSubscription } from "../operators";
1
+ import { BehaviorSubject, defer, finalize, Observable } from "rxjs";
9
2
  import { ProxyObservable } from "./ProxyObservable";
10
3
 
11
4
  export interface TapObservable<T> {
@@ -13,14 +6,15 @@ export interface TapObservable<T> {
13
6
  }
14
7
 
15
8
  export class TapObservable<T> extends ProxyObservable<T> {
16
- constructor(source: Observable<T>, loading: Observable<boolean>) {
17
- const subscribed = new BehaviorSubject(false);
9
+ constructor(source: Observable<T>) {
10
+ const loading = new BehaviorSubject(false);
18
11
 
19
- super(source, (source) => source.pipe(tapSubscription(subscribed)));
20
-
21
- this.loading = combineLatest([loading, subscribed]).pipe(
22
- map((values) => values.every(Boolean)),
23
- distinctUntilChanged(),
12
+ super(source, (source) =>
13
+ defer(() => (loading.next(true), source)).pipe(
14
+ finalize(() => loading.next(false)),
15
+ ),
24
16
  );
17
+
18
+ this.loading = loading;
25
19
  }
26
20
  }
package/src/store.ts CHANGED
@@ -1,9 +1,8 @@
1
- import { constant, Dictionary, mapValues, memoize, tap, thru } from "lodash";
1
+ import { constant, Dictionary, mapValues, tap, thru } from "lodash";
2
2
  import {
3
3
  identity,
4
4
  merge,
5
5
  mergeMap,
6
- NextObserver,
7
6
  Observable,
8
7
  ReplaySubject,
9
8
  shareReplay,
@@ -33,11 +32,8 @@ export type StoreEffects<Signals extends Dictionary<ComputedSignal<any>>> = {
33
32
 
34
33
  export const asStoreEffects = <Signals extends Dictionary<ComputedSignal<any>>>(
35
34
  signals: Signals,
36
- observer?: NextObserver<Signal<any>>,
37
35
  ): StoreEffects<Signals> =>
38
- mapValues(signals, (signal) =>
39
- memoize(() => tap(signal.clone(), (value) => observer?.next(value))),
40
- );
36
+ mapValues(signals, (signal) => () => signal.clone());
41
37
 
42
38
  export class StoreAdapter<
43
39
  Signals extends Dictionary<ComputedSignal<any>>,
package/src/terminal.ts CHANGED
@@ -1,11 +1,10 @@
1
1
  import { Dictionary, thru } from "lodash";
2
- import { combineLatest, distinct, map, switchMap, UnaryFunction } from "rxjs";
2
+ import { UnaryFunction } from "rxjs";
3
3
  import { ApiAdapter, ApiEffect } from "./api";
4
4
  import { ExtendableDictionary } from "./lib";
5
5
  import { ComputedSignal, TapObservable } from "./observable";
6
- import { concat, proxyReplaySubject } from "./operators";
7
6
  import { asStoreEffects, StoreAdapter, StoreEffects } from "./store";
8
- import { Action, asTapEffects, Effect, TapEffect, TapEffects } from "./types";
7
+ import { Action, Effect, TapEffect, TapEffects } from "./types";
9
8
 
10
9
  export interface TerminalEffect<Args, Result> extends TapEffect<Args, Result> {}
11
10
 
@@ -75,31 +74,19 @@ export class ExtendableTerminalAdapter<
75
74
  (currentEffects) => () =>
76
75
  effects({
77
76
  effect: (constructor) => {
78
- const deps = proxyReplaySubject<TapObservable<any>, boolean>(
79
- (deps) =>
80
- deps.pipe(
81
- distinct(),
82
- concat(),
83
- switchMap((dep) =>
84
- combineLatest(dep.map((dep) => dep.loading)),
85
- ),
86
- map((values) => values.some(Boolean)),
87
- ),
88
- );
89
-
90
77
  return thru(
91
78
  constructor({
92
79
  store: {
93
- effects: asStoreEffects(this.context.store.signals, deps),
80
+ effects: asStoreEffects(this.context.store.signals),
94
81
  },
95
82
  api: {
96
- effects: asTapEffects(this.context.api.effects, deps),
83
+ effects: this.context.api.effects,
97
84
  },
98
85
  terminal: {
99
- effects: asTapEffects(currentEffects, deps),
86
+ effects: currentEffects,
100
87
  },
101
88
  }),
102
- (effect) => (args) => new TapObservable(effect(args), deps),
89
+ (effect) => (args) => new TapObservable(effect(args)),
103
90
  );
104
91
  },
105
92
  }),
package/src/types.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { Dictionary, mapValues, memoize, tap } from "lodash";
1
+ import { Dictionary } from "lodash";
2
2
  import { UnaryFunction } from "rxjs";
3
3
  import { Observable } from "rxjs/internal/Observable";
4
- import { NextObserver, ObservableInput } from "rxjs/internal/types";
4
+ import { ObservableInput } from "rxjs/internal/types";
5
5
  import { TapObservable } from "./observable";
6
6
 
7
7
  export interface Effect<Args, Result> extends UnaryFunction<
@@ -27,14 +27,6 @@ export type TapEffects<Effects extends Dictionary<TapEffect<any, any>>> = {
27
27
  >;
28
28
  };
29
29
 
30
- export const asTapEffects = <Effects extends Dictionary<TapEffect<any, any>>>(
31
- effects: Effects,
32
- observer?: NextObserver<TapObservable<any>>,
33
- ): TapEffects<Effects> =>
34
- mapValues(effects, (effect) =>
35
- memoize((args) => tap(effect(args), (source) => observer?.next(source))),
36
- );
37
-
38
30
  export interface Action<Args, Result> extends UnaryFunction<
39
31
  Args,
40
32
  Promise<Result>