@cascateer/core 2.4.15 → 2.4.16
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/.vscode/settings.json +4 -0
- package/package.json +2 -2
- package/src/fragment.ts +1 -1
- package/src/jsx-runtime.ts +2 -2
- package/src/multicast.ts +2 -3
- package/src/operators/index.ts +0 -1
- package/src/operators/multicast.ts +1 -1
- package/src/store.ts +61 -48
- package/src/operators/sequence.ts +0 -23
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cascateer/core",
|
|
3
|
-
"version": "2.4.
|
|
3
|
+
"version": "2.4.16",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/cascateer/core.git"
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"vitest": "^4.1.9"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@cascateer/lib": "^1.0.
|
|
31
|
+
"@cascateer/lib": "^1.0.21",
|
|
32
32
|
"lodash": "^4.18.1",
|
|
33
33
|
"object-hash": "^3.0.0",
|
|
34
34
|
"rxjs": "^7.8.2",
|
package/src/fragment.ts
CHANGED
package/src/jsx-runtime.ts
CHANGED
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
MaybeObservable,
|
|
7
7
|
MaybeObservableInputTuple,
|
|
8
8
|
} from "@cascateer/lib";
|
|
9
|
+
import { chain } from "@cascateer/lib/observables";
|
|
9
10
|
import { bind, camelCase, isFunction, isObject } from "lodash";
|
|
10
11
|
import React, { CSSProperties } from "react";
|
|
11
12
|
import {
|
|
@@ -17,7 +18,6 @@ import {
|
|
|
17
18
|
UnaryFunction,
|
|
18
19
|
} from "rxjs";
|
|
19
20
|
import { Leaf, ObservableFragment } from "./fragment";
|
|
20
|
-
import { sequence } from "./operators";
|
|
21
21
|
|
|
22
22
|
type DocumentEventListener<EventName extends keyof DocumentEventMap> =
|
|
23
23
|
| Partial<Observer<DocumentEventMap[EventName]>>
|
|
@@ -151,7 +151,7 @@ export const createElement = (
|
|
|
151
151
|
),
|
|
152
152
|
)
|
|
153
153
|
.pipe(
|
|
154
|
-
|
|
154
|
+
chain(([style], [previousStyle]) => {
|
|
155
155
|
if (previousStyle != null) {
|
|
156
156
|
for (const name in previousStyle) {
|
|
157
157
|
element.style.removeProperty(name);
|
package/src/multicast.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { property } from "@cascateer/lib";
|
|
2
|
-
import { flatMap } from "@cascateer/lib/
|
|
2
|
+
import { chain, flatMap } from "@cascateer/lib/observables";
|
|
3
3
|
import { partition, thru, uniq, uniqBy } from "lodash";
|
|
4
4
|
import {
|
|
5
5
|
distinct,
|
|
@@ -19,7 +19,6 @@ import {
|
|
|
19
19
|
MulticastActionMessage,
|
|
20
20
|
MulticastClientMessage,
|
|
21
21
|
proxyReplaySubject,
|
|
22
|
-
sequence,
|
|
23
22
|
} from "./operators";
|
|
24
23
|
import { MulticastConnectMessage } from "./operators/multicast";
|
|
25
24
|
|
|
@@ -85,7 +84,7 @@ self.addEventListener("connect", ({ ports }) => {
|
|
|
85
84
|
flatMap(({ ports, actions }) => (ports.includes(port) ? actions : [])),
|
|
86
85
|
distinct(property("id")),
|
|
87
86
|
filter((message) => !message.sameOrigin || message.origin === port),
|
|
88
|
-
|
|
87
|
+
chain(([action, previousAction]) =>
|
|
89
88
|
action.type === "seedAction"
|
|
90
89
|
? action
|
|
91
90
|
: { ...action, previousId: previousAction!.id },
|
package/src/operators/index.ts
CHANGED
|
@@ -70,7 +70,7 @@ export type MulticastClientMessage =
|
|
|
70
70
|
|
|
71
71
|
type MulticastMessage = MulticastHostMessage | MulticastClientMessage;
|
|
72
72
|
|
|
73
|
-
type MulticastMessageConstructor<Message extends MulticastMessage> =
|
|
73
|
+
export type MulticastMessageConstructor<Message extends MulticastMessage> =
|
|
74
74
|
UnaryFunction<Record<"key" | "id", string>, Promise<Message>>;
|
|
75
75
|
|
|
76
76
|
export interface MulticastSubject extends ProxySubject<
|
package/src/store.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { EndoFunction, ExtendableDictionary } from "@cascateer/lib";
|
|
2
|
-
import { flatMap } from "@cascateer/lib/
|
|
2
|
+
import { chain, flatMap } from "@cascateer/lib/observables";
|
|
3
3
|
import { constant, Dictionary, mapValues, tap, thru } from "lodash";
|
|
4
4
|
import {
|
|
5
5
|
identity,
|
|
@@ -10,7 +10,12 @@ import {
|
|
|
10
10
|
shareReplay,
|
|
11
11
|
UnaryFunction,
|
|
12
12
|
} from "rxjs";
|
|
13
|
-
import { MulticastAction, MulticastSubject
|
|
13
|
+
import { MulticastAction, MulticastSubject } from "./operators";
|
|
14
|
+
import {
|
|
15
|
+
MulticastClientMessage,
|
|
16
|
+
MulticastHostMessage,
|
|
17
|
+
MulticastMessageConstructor,
|
|
18
|
+
} from "./operators/multicast";
|
|
14
19
|
import { Serializable } from "./serializable";
|
|
15
20
|
import { ComputedSignal, Signal } from "./signal";
|
|
16
21
|
import { Action } from "./types";
|
|
@@ -59,14 +64,16 @@ export class ExtendableStoreAdapter<
|
|
|
59
64
|
Promise<string>,
|
|
60
65
|
{
|
|
61
66
|
share: UnaryFunction<
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
+
MulticastMessageConstructor<MulticastClientMessage>,
|
|
68
|
+
void
|
|
69
|
+
>;
|
|
70
|
+
register: UnaryFunction<
|
|
71
|
+
UnaryFunction<
|
|
72
|
+
MulticastHostMessage,
|
|
73
|
+
Promise<MulticastAction<any, "transformAction"> | undefined>
|
|
74
|
+
>,
|
|
67
75
|
void
|
|
68
76
|
>;
|
|
69
|
-
register: UnaryFunction<(args: any) => EndoFunction<any>, void>;
|
|
70
77
|
}
|
|
71
78
|
>;
|
|
72
79
|
},
|
|
@@ -138,13 +145,46 @@ export class ExtendableStoreAdapter<
|
|
|
138
145
|
(signal) => ({
|
|
139
146
|
update: (predicate, config = {}) =>
|
|
140
147
|
thru(this.context.transform(key), (transform) => {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
148
|
+
const callbacks = new Map<
|
|
149
|
+
string,
|
|
150
|
+
UnaryFunction<unknown, void>
|
|
151
|
+
>();
|
|
152
|
+
|
|
153
|
+
transform.register(async (event) => {
|
|
154
|
+
if (
|
|
155
|
+
event.type === "transformAction" &&
|
|
156
|
+
event.data.key === (await key)
|
|
157
|
+
) {
|
|
158
|
+
return {
|
|
159
|
+
...event,
|
|
160
|
+
predicate: signal.pull(
|
|
161
|
+
predicate(
|
|
162
|
+
Serializable.parse(
|
|
163
|
+
event.data.args ?? null,
|
|
164
|
+
),
|
|
165
|
+
),
|
|
166
|
+
),
|
|
167
|
+
callback: callbacks.get(event.id),
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
});
|
|
144
171
|
|
|
145
172
|
return (args) =>
|
|
146
173
|
new Promise<unknown>((callback) =>
|
|
147
|
-
transform.share(
|
|
174
|
+
transform.share(
|
|
175
|
+
async ({ id }) => (
|
|
176
|
+
callbacks.set(id, callback),
|
|
177
|
+
{
|
|
178
|
+
id,
|
|
179
|
+
type: "transformAction",
|
|
180
|
+
data: {
|
|
181
|
+
key: await key,
|
|
182
|
+
args: JSON.stringify(args),
|
|
183
|
+
},
|
|
184
|
+
sameOrigin: config.sameOrigin,
|
|
185
|
+
}
|
|
186
|
+
),
|
|
187
|
+
),
|
|
148
188
|
);
|
|
149
189
|
}),
|
|
150
190
|
}),
|
|
@@ -182,40 +222,13 @@ export class StoreProvider<Data> extends ExtendableStoreAdapter<
|
|
|
182
222
|
super(
|
|
183
223
|
{
|
|
184
224
|
transform: (key) => ({
|
|
185
|
-
share: (
|
|
186
|
-
|
|
187
|
-
async ({ id }) => (
|
|
188
|
-
callbacks.set(id, callback),
|
|
189
|
-
{
|
|
190
|
-
id,
|
|
191
|
-
type: "transformAction",
|
|
192
|
-
data: {
|
|
193
|
-
key: await key,
|
|
194
|
-
args: JSON.stringify(args),
|
|
195
|
-
},
|
|
196
|
-
sameOrigin,
|
|
197
|
-
}
|
|
198
|
-
),
|
|
199
|
-
),
|
|
200
|
-
register: (transform) =>
|
|
225
|
+
share: (messageConstructor) => actions.next(messageConstructor),
|
|
226
|
+
register: (project) =>
|
|
201
227
|
actions
|
|
202
228
|
.pipe(
|
|
203
|
-
mergeMap(
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
event.data.key === (await key)
|
|
207
|
-
) {
|
|
208
|
-
return {
|
|
209
|
-
...event,
|
|
210
|
-
predicate: transform(
|
|
211
|
-
Serializable.parse(event.data.args ?? null),
|
|
212
|
-
),
|
|
213
|
-
callback: callbacks.get(event.id),
|
|
214
|
-
};
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
return [];
|
|
218
|
-
}),
|
|
229
|
+
mergeMap((event) =>
|
|
230
|
+
project(event).then((action) => action ?? []),
|
|
231
|
+
),
|
|
219
232
|
flatMap(identity),
|
|
220
233
|
)
|
|
221
234
|
.subscribe(transformActions),
|
|
@@ -224,8 +237,8 @@ export class StoreProvider<Data> extends ExtendableStoreAdapter<
|
|
|
224
237
|
new ExtendableDictionary({
|
|
225
238
|
data: new ComputedSignal({
|
|
226
239
|
value: merge(seedActions, transformActions).pipe(
|
|
227
|
-
|
|
228
|
-
([action, previousAction],
|
|
240
|
+
chain<MulticastAction<Data>, Data>(
|
|
241
|
+
([action, previousAction], previousStates) => {
|
|
229
242
|
console.log(action);
|
|
230
243
|
|
|
231
244
|
if (action.type === "seedAction") {
|
|
@@ -234,12 +247,12 @@ export class StoreProvider<Data> extends ExtendableStoreAdapter<
|
|
|
234
247
|
|
|
235
248
|
if (
|
|
236
249
|
action.previousId !== previousAction?.id ||
|
|
237
|
-
|
|
250
|
+
!(0 in previousStates)
|
|
238
251
|
) {
|
|
239
252
|
throw new Error();
|
|
240
253
|
}
|
|
241
254
|
|
|
242
|
-
return tap(action.predicate(
|
|
255
|
+
return tap(action.predicate(previousStates[0]), (state) =>
|
|
243
256
|
action.callback?.call(null, state),
|
|
244
257
|
);
|
|
245
258
|
},
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { map, OperatorFunction, scan } from "rxjs";
|
|
2
|
-
|
|
3
|
-
export const sequence =
|
|
4
|
-
<Input, Output>(
|
|
5
|
-
predicate: (inputs: [Input, ...Input[]], outputs: Output[]) => Output,
|
|
6
|
-
): OperatorFunction<Input, Output> =>
|
|
7
|
-
(source) =>
|
|
8
|
-
source.pipe(
|
|
9
|
-
scan(
|
|
10
|
-
({ inputs, outputs }, input) => ({
|
|
11
|
-
inputs: [input],
|
|
12
|
-
outputs: [predicate([input, ...inputs], outputs)],
|
|
13
|
-
}),
|
|
14
|
-
{ inputs: new Array<Input>(), outputs: new Array<Output>() },
|
|
15
|
-
),
|
|
16
|
-
map(({ outputs }) => {
|
|
17
|
-
if (!(0 in outputs)) {
|
|
18
|
-
throw new Error();
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
return outputs[0];
|
|
22
|
-
}),
|
|
23
|
-
);
|