@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.
@@ -0,0 +1,4 @@
1
+ {
2
+ "workbench.editor.customLabels.enabled": true,
3
+ "eslint.rules.customizations": [{ "rule": "*", "severity": "warn" }]
4
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cascateer/core",
3
- "version": "2.4.15",
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.9",
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
@@ -1,5 +1,5 @@
1
1
  import { asArray, asObservable } from "@cascateer/lib";
2
- import { flatMap } from "@cascateer/lib/operators";
2
+ import { flatMap } from "@cascateer/lib/observables";
3
3
  import { tap } from "lodash";
4
4
  import {
5
5
  combineLatest,
@@ -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
- sequence(([style], [previousStyle]) => {
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/operators";
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
- sequence(([action, previousAction]) =>
87
+ chain(([action, previousAction]) =>
89
88
  action.type === "seedAction"
90
89
  ? action
91
90
  : { ...action, previousId: previousAction!.id },
@@ -11,5 +11,4 @@ export {
11
11
  type MulticastSubject,
12
12
  } from "./multicast";
13
13
  export { proxyReplaySubject } from "./proxyReplaySubject";
14
- export { sequence } from "./sequence";
15
14
  export { some } from "./some";
@@ -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/operators";
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, sequence } from "./operators";
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
- args: unknown;
64
- callback: UnaryFunction<unknown, void>;
65
- sameOrigin?: boolean;
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
- transform.register((args) =>
142
- signal.pull(predicate(args)),
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({ args, callback, ...config }),
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: ({ args, callback, sameOrigin }) =>
186
- actions.next(
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(async (event) => {
204
- if (
205
- event.type === "transformAction" &&
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
- sequence<MulticastAction<Data>, Data>(
228
- ([action, previousAction], [previousState]) => {
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
- previousState == null
250
+ !(0 in previousStates)
238
251
  ) {
239
252
  throw new Error();
240
253
  }
241
254
 
242
- return tap(action.predicate(previousState), (state) =>
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
- );