@cascateer/core 2.0.11 → 2.0.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cascateer/core",
3
- "version": "2.0.11",
3
+ "version": "2.0.12",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/cascateer/core.git"
package/src/fragment.ts CHANGED
@@ -15,7 +15,7 @@ import {
15
15
  import { asArray, asObservable } from "./lib";
16
16
  import { flatMap } from "./operators";
17
17
 
18
- export type Primitive =
18
+ export type Leaf =
19
19
  | string
20
20
  | number
21
21
  | bigint
@@ -24,7 +24,7 @@ export type Primitive =
24
24
  | null
25
25
  | undefined;
26
26
 
27
- const isPrimitive = (value: unknown): value is Primitive =>
27
+ const isLeaf = (value: unknown): value is Leaf =>
28
28
  ["string", "number", "bigint", "boolean", "symbol"].includes(typeof value) ||
29
29
  value == null;
30
30
 
@@ -102,9 +102,7 @@ export class ObservableFragment extends AnchorFragment {
102
102
  element instanceof ObservableFragment
103
103
  ? element.nodes
104
104
  : of(
105
- isPrimitive(element)
106
- ? new Text(element?.toString())
107
- : element,
105
+ isLeaf(element) ? new Text(element?.toString()) : element,
108
106
  ),
109
107
  ),
110
108
  startWith(),
@@ -8,7 +8,7 @@ import {
8
8
  Observer,
9
9
  UnaryFunction,
10
10
  } from "rxjs";
11
- import { ObservableFragment, Primitive } from "./fragment";
11
+ import { Leaf, ObservableFragment } from "./fragment";
12
12
  import { asArray, asObservable, keys } from "./lib";
13
13
  import { sequence } from "./operators";
14
14
  import {
@@ -23,7 +23,7 @@ type DocumentEventListener<EventName extends keyof DocumentEventMap> =
23
23
 
24
24
  declare global {
25
25
  namespace JSX {
26
- type Element = MaybeObservable<Node | Primitive>;
26
+ type Element = MaybeObservable<Node | Leaf>;
27
27
 
28
28
  type Children = MaybeObservable<MaybeArray<Element>>;
29
29
 
package/src/multicast.ts CHANGED
@@ -9,8 +9,8 @@ import {
9
9
  MulticastActionMessage,
10
10
  MulticastClientMessage,
11
11
  MulticastConnectMessageData,
12
+ proxy,
12
13
  sequence,
13
- transform,
14
14
  } from "./operators";
15
15
 
16
16
  declare var self: ServiceWorkerGlobalScope;
@@ -21,9 +21,9 @@ declare global {
21
21
  }
22
22
  }
23
23
 
24
- const sliceActionsSequence = memoize(
24
+ const memoizedSliceActions = memoize(
25
25
  <Seed>({ seed }: MulticastConnectMessageData<Seed>) =>
26
- transform<MulticastActionMessage<any>>((actions) =>
26
+ proxy<MulticastActionMessage<any>>((actions) =>
27
27
  actions.pipe(
28
28
  startWith({
29
29
  id: v4(),
@@ -42,37 +42,36 @@ self.addEventListener("connect", ({ ports }) => {
42
42
  thru(
43
43
  new Future<Observable<MulticastActionMessage<any>>>(),
44
44
  (sliceActions) =>
45
- transform<MulticastActionMessage<any>, MulticastClientMessage>(
46
- (actions) =>
47
- sliceActions.pipe(
48
- mergeAll(),
49
- flatMap(({ origin, ...message }) =>
50
- !message.sameOrigin || origin === port ? message : [],
51
- ),
52
- sequence(([action, previousAction]) =>
53
- action.type === "seedAction"
54
- ? action
55
- : {
56
- ...action,
57
- previousId: nonNullable(previousAction).id,
58
- },
59
- ),
60
- exchangeWith<MulticastClientMessage, MulticastActionMessage<any>>(
61
- port,
62
- ),
63
- flatMap((event) => {
64
- if (event.type === "connect") {
65
- actions.subscribe(
66
- sliceActions.completeWith(sliceActionsSequence(event.data)),
67
- );
45
+ proxy<MulticastActionMessage<any>, MulticastClientMessage>((actions) =>
46
+ sliceActions.pipe(
47
+ mergeAll(),
48
+ flatMap(({ origin, ...message }) =>
49
+ !message.sameOrigin || origin === port ? message : [],
50
+ ),
51
+ sequence(([action, previousAction]) =>
52
+ action.type === "seedAction"
53
+ ? action
54
+ : {
55
+ ...action,
56
+ previousId: nonNullable(previousAction).id,
57
+ },
58
+ ),
59
+ exchangeWith<MulticastClientMessage, MulticastActionMessage<any>>(
60
+ port,
61
+ ),
62
+ flatMap((event) => {
63
+ if (event.type === "connect") {
64
+ actions.subscribe(
65
+ sliceActions.completeWith(memoizedSliceActions(event.data)),
66
+ );
68
67
 
69
- return [];
70
- }
68
+ return [];
69
+ }
71
70
 
72
- return { ...event, origin: port };
73
- }),
74
- tap(actions),
75
- ),
71
+ return { ...event, origin: port };
72
+ }),
73
+ tap(actions),
74
+ ),
76
75
  ),
77
76
  ).subscribe();
78
77
  }
@@ -4,11 +4,14 @@ import {
4
4
  Observer,
5
5
  ReplaySubject,
6
6
  Subject,
7
- UnaryFunction,
8
7
  Unsubscribable,
9
8
  } from "rxjs";
10
9
 
11
- export class TransformSubject<T, U = T>
10
+ export interface ProxySubjectHandler<T, U> {
11
+ (target: Subject<T>, receiver: Observable<U>): Observable<U>;
12
+ }
13
+
14
+ export class ProxySubject<T, U = T>
12
15
  extends Observable<U>
13
16
  implements Observer<T>, Unsubscribable
14
17
  {
@@ -29,11 +32,11 @@ export class TransformSubject<T, U = T>
29
32
  }
30
33
 
31
34
  constructor(
32
- project: UnaryFunction<Subject<T>, Observable<U>>,
35
+ handler: ProxySubjectHandler<T, U>,
33
36
  private target: Subject<T> = new ReplaySubject(),
34
37
  ) {
35
- project = once(project);
38
+ handler = once(handler);
36
39
 
37
- super((subscriber) => project(target).subscribe(subscriber));
40
+ super((subscriber) => handler(target, this).subscribe(subscriber));
38
41
  }
39
42
  }
@@ -36,7 +36,7 @@ class SignalReflector<T> {
36
36
  export class Signal<T> extends Observable<T> implements TapObservable<T> {
37
37
  loading = of(false);
38
38
 
39
- capture(): Signal<T> {
39
+ clone(): Signal<T> {
40
40
  return this;
41
41
  }
42
42
 
@@ -1,4 +1,4 @@
1
1
  export { Future } from "./Future";
2
+ export { ProxySubject } from "./ProxySubject";
2
3
  export { ComputedSignal, Signal } from "./Signal";
3
4
  export { TapObservable } from "./TapObservable";
4
- export { TransformSubject } from "./TransformSubject";
@@ -10,6 +10,6 @@ export {
10
10
  type MulticastHostMessage,
11
11
  type MulticastSubject,
12
12
  } from "./multicast";
13
+ export { proxy } from "./proxy";
13
14
  export { sequence } from "./sequence";
14
15
  export { tapSubscription } from "./tapSubscription";
15
- export { transform } from "./transform";
@@ -1,7 +1,7 @@
1
1
  import { concatMap, shareReplay, startWith, UnaryFunction } from "rxjs";
2
2
  import { v4 } from "uuid";
3
- import { ComputedSignal, TransformSubject } from "../observable";
4
- import { exchangeWith, transform } from "../operators";
3
+ import { ComputedSignal, ProxySubject } from "../observable";
4
+ import { exchangeWith, proxy } from "../operators";
5
5
  import { Transform } from "../types";
6
6
 
7
7
  interface MulticastBaseMessage<Type, Data> {
@@ -71,7 +71,7 @@ type MulticastMessage = MulticastHostMessage | MulticastClientMessage;
71
71
  type MulticastMessageConstructor<Message extends MulticastMessage> =
72
72
  UnaryFunction<Record<"key" | "id", string>, Promise<Message>>;
73
73
 
74
- export interface MulticastSubject extends TransformSubject<
74
+ export interface MulticastSubject extends ProxySubject<
75
75
  MulticastMessageConstructor<MulticastClientMessage>,
76
76
  MulticastHostMessage
77
77
  > {}
@@ -80,7 +80,7 @@ export const multicast = <Seed>(
80
80
  key: Promise<string>,
81
81
  seed: Seed,
82
82
  ): MulticastSubject =>
83
- transform((messages) =>
83
+ proxy((messages) =>
84
84
  messages.pipe(
85
85
  startWith(
86
86
  ({ key, id }): MulticastConnectMessage => ({
@@ -0,0 +1,8 @@
1
+ import { Subject } from "rxjs";
2
+ import { ProxySubject } from "../observable";
3
+ import { ProxySubjectHandler } from "../observable/ProxySubject";
4
+
5
+ export const proxy = <T, U = T>(
6
+ handler: ProxySubjectHandler<T, U>,
7
+ target?: Subject<T>,
8
+ ) => new ProxySubject(handler, target);
package/src/store.ts CHANGED
@@ -36,7 +36,7 @@ export const asStoreEffects = <Signals extends Dictionary<ComputedSignal<any>>>(
36
36
  observer?: NextObserver<Signal<any>>,
37
37
  ): StoreEffects<Signals> =>
38
38
  mapValues(signals, (signal) =>
39
- memoize(() => tap(signal.capture(), (value) => observer?.next(value))),
39
+ memoize(() => tap(signal.clone(), (value) => observer?.next(value))),
40
40
  );
41
41
 
42
42
  export class StoreAdapter<
package/src/terminal.ts CHANGED
@@ -10,7 +10,7 @@ import {
10
10
  import { ApiAdapter, ApiEffect } from "./api";
11
11
  import { ExtendableDictionary } from "./lib";
12
12
  import { ComputedSignal, TapObservable } from "./observable";
13
- import { concat, transform } from "./operators";
13
+ import { concat, proxy } from "./operators";
14
14
  import { asStoreEffects, StoreAdapter, StoreEffects } from "./store";
15
15
  import { Action, Effect, TapEffect } from "./types";
16
16
 
@@ -103,7 +103,7 @@ export class ExtendableTerminalAdapter<
103
103
  (currentEffects) => () =>
104
104
  effects({
105
105
  effect: (constructor) => {
106
- const deps = transform<TapObservable<any>, boolean>((deps) =>
106
+ const deps = proxy<TapObservable<any>, boolean>((deps) =>
107
107
  deps.pipe(
108
108
  distinct(),
109
109
  concat(),
@@ -1,7 +0,0 @@
1
- import { Observable, Subject, UnaryFunction } from "rxjs";
2
- import { TransformSubject } from "../observable";
3
-
4
- export const transform = <T, U = T>(
5
- project: UnaryFunction<Subject<T>, Observable<U>>,
6
- target?: Subject<T>,
7
- ) => new TransformSubject(project, target);