@cascateer/core 2.4.33 → 2.4.34
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/jsx-runtime.ts +19 -11
- package/src/multicast.ts +10 -10
- package/src/operators/multicast.ts +17 -4
- package/src/store.ts +15 -16
package/package.json
CHANGED
package/src/jsx-runtime.ts
CHANGED
|
@@ -6,8 +6,8 @@ import {
|
|
|
6
6
|
MaybeObservable,
|
|
7
7
|
MaybeObservableInputTuple,
|
|
8
8
|
} from "@cascateer/lib";
|
|
9
|
-
import {
|
|
10
|
-
import { bind, camelCase, isFunction, isObject } from "lodash";
|
|
9
|
+
import { reduce } from "@cascateer/lib/observables";
|
|
10
|
+
import { bind, camelCase, Dictionary, isFunction, isObject } from "lodash";
|
|
11
11
|
import React, { CSSProperties } from "react";
|
|
12
12
|
import {
|
|
13
13
|
combineLatest,
|
|
@@ -139,6 +139,17 @@ export const createElement = (
|
|
|
139
139
|
);
|
|
140
140
|
} else if (name === "style") {
|
|
141
141
|
if (isObject(propertyValue)) {
|
|
142
|
+
const assignStyles = (
|
|
143
|
+
target: CSSStyleDeclaration,
|
|
144
|
+
source: Dictionary<unknown>,
|
|
145
|
+
) => {
|
|
146
|
+
for (const [name, value] of Object.entries(source)) {
|
|
147
|
+
target.setProperty(name, String(value));
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
return source;
|
|
151
|
+
};
|
|
152
|
+
|
|
142
153
|
combineLatest(
|
|
143
154
|
Object.entries(propertyValue).reduce<
|
|
144
155
|
ObservableInputTuple<Record<string, unknown>>
|
|
@@ -151,19 +162,16 @@ export const createElement = (
|
|
|
151
162
|
),
|
|
152
163
|
)
|
|
153
164
|
.pipe(
|
|
154
|
-
|
|
155
|
-
|
|
165
|
+
reduce(
|
|
166
|
+
(previousStyle, style) => {
|
|
156
167
|
for (const name in previousStyle) {
|
|
157
168
|
element.style.removeProperty(name);
|
|
158
169
|
}
|
|
159
|
-
}
|
|
160
170
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
return style;
|
|
166
|
-
}),
|
|
171
|
+
return assignStyles(element.style, style);
|
|
172
|
+
},
|
|
173
|
+
(style) => assignStyles(element.style, style),
|
|
174
|
+
),
|
|
167
175
|
)
|
|
168
176
|
.subscribe();
|
|
169
177
|
}
|
package/src/multicast.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { property } from "@cascateer/lib";
|
|
2
2
|
import { flatMap, reduce } from "@cascateer/lib/observables";
|
|
3
|
-
import { partition, thru, uniq, uniqBy } from "lodash";
|
|
3
|
+
import { partition, tap, thru, uniq, uniqBy } from "lodash";
|
|
4
4
|
import {
|
|
5
5
|
distinct,
|
|
6
6
|
filter,
|
|
@@ -20,7 +20,11 @@ import {
|
|
|
20
20
|
MulticastClientMessage,
|
|
21
21
|
proxyReplaySubject,
|
|
22
22
|
} from "./operators";
|
|
23
|
-
import {
|
|
23
|
+
import {
|
|
24
|
+
assertIsMulticastSeedActionMessage,
|
|
25
|
+
isMulticastSeedActionMessage,
|
|
26
|
+
MulticastConnectMessage,
|
|
27
|
+
} from "./operators/multicast";
|
|
24
28
|
|
|
25
29
|
declare var self: ServiceWorkerGlobalScope;
|
|
26
30
|
|
|
@@ -86,14 +90,10 @@ self.addEventListener("connect", ({ ports }) => {
|
|
|
86
90
|
filter((message) => !message.sameOrigin || message.origin === port),
|
|
87
91
|
reduce(
|
|
88
92
|
({ id: previousId }, action) =>
|
|
89
|
-
action
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
throw new Error();
|
|
96
|
-
},
|
|
93
|
+
isMulticastSeedActionMessage(action)
|
|
94
|
+
? action
|
|
95
|
+
: { ...action, previousId },
|
|
96
|
+
(action) => tap(action, assertIsMulticastSeedActionMessage),
|
|
97
97
|
),
|
|
98
98
|
map(({ origin, ...message }) => message),
|
|
99
99
|
exchangeWith<MulticastClientMessage, MulticastActionMessage<any>>(port),
|
|
@@ -6,7 +6,7 @@ import { ComputedSignal } from "../signal";
|
|
|
6
6
|
import { exchangeWith } from "./exchangeWith";
|
|
7
7
|
import { proxyReplaySubject } from "./proxyReplaySubject";
|
|
8
8
|
|
|
9
|
-
interface MulticastBaseMessage<
|
|
9
|
+
interface MulticastBaseMessage<Data, Type> {
|
|
10
10
|
id: string;
|
|
11
11
|
previousId?: string;
|
|
12
12
|
type: Type;
|
|
@@ -34,12 +34,25 @@ interface MulticastActions<Data> {
|
|
|
34
34
|
export type MulticastBaseActionMessage<
|
|
35
35
|
Data,
|
|
36
36
|
Type extends keyof MulticastActions<Data>,
|
|
37
|
-
> = MulticastBaseMessage<
|
|
37
|
+
> = MulticastBaseMessage<MulticastActions<Data>[Type]["data"], Type>;
|
|
38
38
|
|
|
39
39
|
export type MulticastActionMessage<Data> =
|
|
40
40
|
| MulticastBaseActionMessage<Data, "seedAction">
|
|
41
41
|
| MulticastBaseActionMessage<Data, "transformAction">;
|
|
42
42
|
|
|
43
|
+
export const isMulticastSeedActionMessage = <Data>(
|
|
44
|
+
action: MulticastActionMessage<Data>,
|
|
45
|
+
): action is MulticastBaseActionMessage<Data, "seedAction"> =>
|
|
46
|
+
action.type === "seedAction";
|
|
47
|
+
|
|
48
|
+
export const assertIsMulticastSeedActionMessage = <Data>(
|
|
49
|
+
action: MulticastActionMessage<Data>,
|
|
50
|
+
): asserts action is MulticastBaseActionMessage<Data, "seedAction"> => {
|
|
51
|
+
if (!isMulticastSeedActionMessage(action)) {
|
|
52
|
+
throw new Error();
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
|
|
43
56
|
export type MulticastAction<
|
|
44
57
|
Data,
|
|
45
58
|
Type extends keyof MulticastActions<Data> = keyof MulticastActions<Data>,
|
|
@@ -59,8 +72,8 @@ export interface MulticastConnectMessageData {
|
|
|
59
72
|
}
|
|
60
73
|
|
|
61
74
|
export type MulticastConnectMessage = MulticastBaseMessage<
|
|
62
|
-
|
|
63
|
-
|
|
75
|
+
MulticastConnectMessageData,
|
|
76
|
+
"connect"
|
|
64
77
|
>;
|
|
65
78
|
|
|
66
79
|
export type MulticastHostMessage = MulticastActionMessage<any>;
|
package/src/store.ts
CHANGED
|
@@ -7,10 +7,13 @@ import {
|
|
|
7
7
|
Observable,
|
|
8
8
|
ReplaySubject,
|
|
9
9
|
shareReplay,
|
|
10
|
+
tap as tapOperator,
|
|
10
11
|
UnaryFunction,
|
|
11
12
|
} from "rxjs";
|
|
12
13
|
import { MulticastAction, MulticastSubject } from "./operators";
|
|
13
14
|
import {
|
|
15
|
+
assertIsMulticastSeedActionMessage,
|
|
16
|
+
isMulticastSeedActionMessage,
|
|
14
17
|
MulticastBaseActionMessage,
|
|
15
18
|
MulticastClientMessage,
|
|
16
19
|
MulticastMessageConstructor,
|
|
@@ -221,30 +224,26 @@ export class StoreProvider<Data> extends ExtendableStoreAdapter<
|
|
|
221
224
|
new ExtendableDictionary({
|
|
222
225
|
data: new ComputedSignal({
|
|
223
226
|
value: merge(seedActions, transformActions).pipe(
|
|
227
|
+
tapOperator((action) => console.log(action)),
|
|
224
228
|
reduce<MulticastAction<Data>, Data>(
|
|
225
229
|
(previousState, action, previousAction) => {
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
if (action.type === "seedAction") {
|
|
230
|
+
if (isMulticastSeedActionMessage(action)) {
|
|
229
231
|
return action.predicate();
|
|
230
232
|
}
|
|
231
233
|
|
|
232
|
-
if (action.previousId
|
|
233
|
-
|
|
234
|
-
action.predicate(previousState),
|
|
235
|
-
action.callback ?? noop,
|
|
236
|
-
);
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
throw new Error();
|
|
240
|
-
},
|
|
241
|
-
(action) => {
|
|
242
|
-
if (action.type === "seedAction") {
|
|
243
|
-
return action.predicate();
|
|
234
|
+
if (action.previousId !== previousAction?.id) {
|
|
235
|
+
throw new Error();
|
|
244
236
|
}
|
|
245
237
|
|
|
246
|
-
|
|
238
|
+
return tap(
|
|
239
|
+
action.predicate(previousState),
|
|
240
|
+
action.callback ?? noop,
|
|
241
|
+
);
|
|
247
242
|
},
|
|
243
|
+
(action) => (
|
|
244
|
+
assertIsMulticastSeedActionMessage(action),
|
|
245
|
+
action.predicate()
|
|
246
|
+
),
|
|
248
247
|
),
|
|
249
248
|
shareReplay(1),
|
|
250
249
|
),
|