@cascateer/core 2.0.11 → 2.0.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 +1 -1
- package/src/fragment.ts +3 -5
- package/src/jsx-runtime.ts +2 -2
- package/src/multicast.ts +31 -32
- package/src/observable/{TransformSubject.ts → ProxySubject.ts} +8 -5
- package/src/observable/Signal.ts +1 -1
- package/src/observable/TapObservable.ts +1 -2
- package/src/observable/index.ts +1 -1
- package/src/operators/index.ts +1 -1
- package/src/operators/multicast.ts +4 -4
- package/src/operators/proxy.ts +8 -0
- package/src/store.ts +1 -1
- package/src/terminal.ts +2 -2
- package/src/operators/transform.ts +0 -7
package/package.json
CHANGED
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
|
|
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
|
|
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
|
-
|
|
106
|
-
? new Text(element?.toString())
|
|
107
|
-
: element,
|
|
105
|
+
isLeaf(element) ? new Text(element?.toString()) : element,
|
|
108
106
|
),
|
|
109
107
|
),
|
|
110
108
|
startWith(),
|
package/src/jsx-runtime.ts
CHANGED
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
Observer,
|
|
9
9
|
UnaryFunction,
|
|
10
10
|
} from "rxjs";
|
|
11
|
-
import {
|
|
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 |
|
|
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
|
|
24
|
+
const memoizedSliceActions = memoize(
|
|
25
25
|
<Seed>({ seed }: MulticastConnectMessageData<Seed>) =>
|
|
26
|
-
|
|
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
|
-
|
|
46
|
-
(
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
action
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
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
|
-
|
|
70
|
-
|
|
68
|
+
return [];
|
|
69
|
+
}
|
|
71
70
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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
|
|
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
|
-
|
|
35
|
+
handler: ProxySubjectHandler<T, U>,
|
|
33
36
|
private target: Subject<T> = new ReplaySubject(),
|
|
34
37
|
) {
|
|
35
|
-
|
|
38
|
+
handler = once(handler);
|
|
36
39
|
|
|
37
|
-
super((subscriber) =>
|
|
40
|
+
super((subscriber) => handler(target, this).subscribe(subscriber));
|
|
38
41
|
}
|
|
39
42
|
}
|
package/src/observable/Signal.ts
CHANGED
|
@@ -5,7 +5,6 @@ import {
|
|
|
5
5
|
map,
|
|
6
6
|
MonoTypeOperatorFunction,
|
|
7
7
|
Observable,
|
|
8
|
-
share,
|
|
9
8
|
} from "rxjs";
|
|
10
9
|
import { tapSubscription } from "../operators";
|
|
11
10
|
|
|
@@ -18,7 +17,7 @@ export class TapObservable<T> extends Observable<T> {
|
|
|
18
17
|
const subscribed = new BehaviorSubject(false);
|
|
19
18
|
|
|
20
19
|
const intercept: MonoTypeOperatorFunction<T> = once((source) =>
|
|
21
|
-
source.pipe(tapSubscription(subscribed)
|
|
20
|
+
source.pipe(tapSubscription(subscribed)),
|
|
22
21
|
);
|
|
23
22
|
|
|
24
23
|
super((subscriber) => source.pipe(intercept).subscribe(subscriber));
|
package/src/observable/index.ts
CHANGED
package/src/operators/index.ts
CHANGED
|
@@ -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,
|
|
4
|
-
import { exchangeWith,
|
|
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
|
|
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
|
-
|
|
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.
|
|
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,
|
|
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 =
|
|
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);
|