@cascateer/core 2.0.10 → 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 +1 -1
- package/src/fragment.ts +3 -5
- package/src/jsx-runtime.ts +17 -17
- package/src/multicast.ts +31 -32
- package/src/observable/{TransformSubject.ts → ProxySubject.ts} +8 -5
- package/src/observable/Signal.ts +7 -15
- 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 +8 -8
- 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,22 +23,7 @@ type DocumentEventListener<EventName extends keyof DocumentEventMap> =
|
|
|
23
23
|
|
|
24
24
|
declare global {
|
|
25
25
|
namespace JSX {
|
|
26
|
-
type Element = MaybeObservable<Node |
|
|
27
|
-
|
|
28
|
-
export type CSSCustomPropertyDefinition = Omit<PropertyDefinition, "name">;
|
|
29
|
-
|
|
30
|
-
export type CSSCustomIntegerPropertyDefinition =
|
|
31
|
-
CSSCustomPropertyDefinition & { syntax: "<integer>" };
|
|
32
|
-
|
|
33
|
-
export interface CSSCustomPropertyDefinitions extends Record<
|
|
34
|
-
keyof {},
|
|
35
|
-
CSSCustomPropertyDefinition
|
|
36
|
-
> {}
|
|
37
|
-
|
|
38
|
-
type CSSCustomProperties = Record<
|
|
39
|
-
keyof CSSCustomPropertyDefinitions & `--${string}`,
|
|
40
|
-
string | number
|
|
41
|
-
>;
|
|
26
|
+
type Element = MaybeObservable<Node | Leaf>;
|
|
42
27
|
|
|
43
28
|
type Children = MaybeObservable<MaybeArray<Element>>;
|
|
44
29
|
|
|
@@ -72,6 +57,21 @@ declare global {
|
|
|
72
57
|
interface Component<P extends Props = Props> {
|
|
73
58
|
(props: IntrinsicAttributes & P): Element;
|
|
74
59
|
}
|
|
60
|
+
|
|
61
|
+
export type CSSCustomPropertyDefinition = Omit<PropertyDefinition, "name">;
|
|
62
|
+
|
|
63
|
+
export type CSSCustomIntegerPropertyDefinition =
|
|
64
|
+
CSSCustomPropertyDefinition & { syntax: "<integer>" };
|
|
65
|
+
|
|
66
|
+
export interface CSSCustomPropertyDefinitions extends Record<
|
|
67
|
+
keyof {},
|
|
68
|
+
CSSCustomPropertyDefinition
|
|
69
|
+
> {}
|
|
70
|
+
|
|
71
|
+
type CSSCustomProperties = Record<
|
|
72
|
+
keyof CSSCustomPropertyDefinitions & `--${string}`,
|
|
73
|
+
string | number
|
|
74
|
+
>;
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
77
|
|
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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { clone, isEqual, memoize } from "lodash";
|
|
1
|
+
import { clone, identity, isEqual, memoize } from "lodash";
|
|
2
2
|
import { distinctUntilChanged, map, Observable, of, UnaryFunction } from "rxjs";
|
|
3
3
|
import { TapObservable } from ".";
|
|
4
4
|
import {
|
|
@@ -22,29 +22,21 @@ class SignalEnumerator<T> {
|
|
|
22
22
|
|
|
23
23
|
class SignalReflector<T> {
|
|
24
24
|
constructor(
|
|
25
|
-
|
|
25
|
+
public predicate: (
|
|
26
26
|
transform: Transform<T>,
|
|
27
|
-
|
|
28
|
-
) => void = (transform, callback) => callback(transform),
|
|
27
|
+
) => Transform<unknown> = identity,
|
|
29
28
|
) {}
|
|
30
29
|
|
|
31
|
-
reflect =
|
|
32
|
-
new Promise<Transform<unknown>>((callback) =>
|
|
33
|
-
this.predicate(transform, callback),
|
|
34
|
-
);
|
|
35
|
-
|
|
36
|
-
lift = <U>(
|
|
30
|
+
reflect = <U>(
|
|
37
31
|
lift: UnaryFunction<Transform<U>, Transform<T>>,
|
|
38
32
|
): SignalReflector<U> =>
|
|
39
|
-
new SignalReflector((transform
|
|
40
|
-
this.predicate(lift(transform), callback),
|
|
41
|
-
);
|
|
33
|
+
new SignalReflector((transform) => this.predicate(lift(transform)));
|
|
42
34
|
}
|
|
43
35
|
|
|
44
36
|
export class Signal<T> extends Observable<T> implements TapObservable<T> {
|
|
45
37
|
loading = of(false);
|
|
46
38
|
|
|
47
|
-
|
|
39
|
+
clone(): Signal<T> {
|
|
48
40
|
return this;
|
|
49
41
|
}
|
|
50
42
|
|
|
@@ -78,7 +70,7 @@ export class Signal<T> extends Observable<T> implements TapObservable<T> {
|
|
|
78
70
|
return new Signal({
|
|
79
71
|
value: this.pipe(map(project), distinctUntilChanged()),
|
|
80
72
|
enumerator: new SignalEnumerator(enumerate),
|
|
81
|
-
reflector: this.reflector.
|
|
73
|
+
reflector: this.reflector.reflect(lift),
|
|
82
74
|
});
|
|
83
75
|
}
|
|
84
76
|
|
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<
|
|
@@ -73,7 +73,7 @@ export class ExtendableStoreAdapter<
|
|
|
73
73
|
},
|
|
74
74
|
void
|
|
75
75
|
>;
|
|
76
|
-
|
|
76
|
+
register: UnaryFunction<(args: any) => Transform<any>, void>;
|
|
77
77
|
}
|
|
78
78
|
>;
|
|
79
79
|
},
|
|
@@ -145,8 +145,8 @@ export class ExtendableStoreAdapter<
|
|
|
145
145
|
(signal) => ({
|
|
146
146
|
update: (predicate, config = {}) =>
|
|
147
147
|
thru(this.context.transform(key), (transform) => {
|
|
148
|
-
transform.
|
|
149
|
-
signal.reflector.
|
|
148
|
+
transform.register((args) =>
|
|
149
|
+
signal.reflector.predicate(predicate(args)),
|
|
150
150
|
);
|
|
151
151
|
|
|
152
152
|
return (args) =>
|
|
@@ -204,7 +204,7 @@ export class StoreProvider<Data> extends ExtendableStoreAdapter<
|
|
|
204
204
|
}
|
|
205
205
|
),
|
|
206
206
|
),
|
|
207
|
-
|
|
207
|
+
register: (transform) =>
|
|
208
208
|
actions
|
|
209
209
|
.pipe(
|
|
210
210
|
mergeMap(async (event) => {
|
|
@@ -212,11 +212,11 @@ export class StoreProvider<Data> extends ExtendableStoreAdapter<
|
|
|
212
212
|
event.type === "transformAction" &&
|
|
213
213
|
event.data.key === (await key)
|
|
214
214
|
) {
|
|
215
|
-
return
|
|
215
|
+
return {
|
|
216
216
|
...event,
|
|
217
|
-
predicate,
|
|
217
|
+
predicate: transform(event.data.args),
|
|
218
218
|
callback: callbacks.get(event.id),
|
|
219
|
-
}
|
|
219
|
+
};
|
|
220
220
|
}
|
|
221
221
|
|
|
222
222
|
return [];
|
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);
|