@cascateer/core 2.1.30 → 2.1.32

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.30",
3
+ "version": "2.1.32",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/cascateer/core.git"
@@ -20,14 +20,14 @@ export class ProxyObservable<
20
20
 
21
21
  constructor(
22
22
  target: U | ((pending: NextObserver<boolean>) => U),
23
- pendingFactory?: UnaryFunction<U, Observable<boolean>>,
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 source = once(() =>
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 source().subscribe(subscriber);
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
- pendingFactory?.call(null, source()).subscribe(pending);
50
+ handler?.call(null, memoizedTarget(), this).subscribe(pending);
51
51
  }
52
52
  }
@@ -0,0 +1,4 @@
1
+ import { map, OperatorFunction } from "rxjs";
2
+
3
+ export const every = (): OperatorFunction<any[], boolean> => (source) =>
4
+ source.pipe(map((values) => values.every(Boolean)));
@@ -1,4 +1,5 @@
1
1
  export { concat } from "./concat";
2
+ export { every } from "./every";
2
3
  export { exchangeWith } from "./exchangeWith";
3
4
  export { flatMap } from "./flatMap";
4
5
  export {
@@ -12,4 +13,4 @@ export {
12
13
  } from "./multicast";
13
14
  export { proxyReplaySubject } from "./proxyReplaySubject";
14
15
  export { sequence } from "./sequence";
15
- export { tapSubscription } from "./tapSubscription";
16
+ export { some } from "./some";
@@ -0,0 +1,4 @@
1
+ import { map, OperatorFunction } from "rxjs";
2
+
3
+ export const some = (): OperatorFunction<any[], boolean> => (source) =>
4
+ source.pipe(map((values) => values.some(Boolean)));
package/src/terminal.ts CHANGED
@@ -79,24 +79,27 @@ export class ExtendableTerminalAdapter<
79
79
  ) {
80
80
  return new ExtendableTerminalAdapter(
81
81
  this.context,
82
- this.extendableEffects.extend((currentEffects) => () => {
83
- const interceptor = new ProxyEffectInterceptor();
84
- const source = {
85
- store: {
86
- effects: asStoreEffects(this.context.store.signals),
87
- },
88
- api: {
89
- effects: interceptor.intercept(this.context.api.effects),
90
- },
91
- terminal: {
92
- effects: interceptor.intercept(currentEffects),
93
- },
94
- };
82
+ this.extendableEffects.extend(
83
+ (currentEffects) => () =>
84
+ effects({
85
+ effect: (constructor) => {
86
+ const interceptor = new ProxyEffectInterceptor();
87
+ const source = {
88
+ store: {
89
+ effects: asStoreEffects(this.context.store.signals),
90
+ },
91
+ api: {
92
+ effects: interceptor.intercept(this.context.api.effects),
93
+ },
94
+ terminal: {
95
+ effects: interceptor.intercept(currentEffects),
96
+ },
97
+ };
95
98
 
96
- return effects({
97
- effect: (constructor) => interceptor.proxy(constructor(source)),
98
- });
99
- }),
99
+ return interceptor.proxy(constructor(source));
100
+ },
101
+ }),
102
+ ),
100
103
  this.extendableActions,
101
104
  );
102
105
  }
package/src/types.ts CHANGED
@@ -2,7 +2,6 @@ import { Dictionary, mapValues, tap } from "lodash";
2
2
  import {
3
3
  combineLatest,
4
4
  distinct,
5
- map,
6
5
  ReplaySubject,
7
6
  switchMap,
8
7
  UnaryFunction,
@@ -11,7 +10,7 @@ import { Observable } from "rxjs/internal/Observable";
11
10
  import { ObservableInput } from "rxjs/internal/types";
12
11
  import { memoizeHashed } from "./lib";
13
12
  import { ProxyObservable } from "./observable";
14
- import { concat } from "./operators";
13
+ import { concat, every, some } from "./operators";
15
14
 
16
15
  export interface Effect<Args, Result> extends UnaryFunction<
17
16
  Args,
@@ -45,10 +44,8 @@ export class ProxyEffectInterceptor extends ReplaySubject<
45
44
  return mapValues(effects, (effect) =>
46
45
  memoizeHashed((args) =>
47
46
  tap(
48
- new ProxyObservable(effect(args), (target) =>
49
- combineLatest([target.pending, target.refCount]).pipe(
50
- map((values) => values.every(Boolean)),
51
- ),
47
+ new ProxyObservable(effect(args), (target, receiver) =>
48
+ combineLatest([target.pending, receiver.refCount]).pipe(every()),
52
49
  ),
53
50
  (source) => this.next(source),
54
51
  ),
@@ -65,7 +62,7 @@ export class ProxyEffectInterceptor extends ReplaySubject<
65
62
  switchMap((sources) =>
66
63
  combineLatest(sources.map((source) => source.pending)),
67
64
  ),
68
- map((values) => values.some(Boolean)),
65
+ some(),
69
66
  ),
70
67
  );
71
68
  }
@@ -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
- };