@cascateer/core 2.4.15 → 2.4.17

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.17",
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,8 +1,7 @@
1
1
  import { EndoFunction, ExtendableDictionary } from "@cascateer/lib";
2
- import { flatMap } from "@cascateer/lib/operators";
3
- import { constant, Dictionary, mapValues, tap, thru } from "lodash";
2
+ import { chain, flatMap } from "@cascateer/lib/observables";
3
+ import { constant, Dictionary, mapValues, tap } from "lodash";
4
4
  import {
5
- identity,
6
5
  merge,
7
6
  mergeMap,
8
7
  Observable,
@@ -10,7 +9,12 @@ import {
10
9
  shareReplay,
11
10
  UnaryFunction,
12
11
  } from "rxjs";
13
- import { MulticastAction, MulticastSubject, sequence } from "./operators";
12
+ import { MulticastAction, MulticastSubject } from "./operators";
13
+ import {
14
+ MulticastClientMessage,
15
+ MulticastHostMessage,
16
+ MulticastMessageConstructor,
17
+ } from "./operators/multicast";
14
18
  import { Serializable } from "./serializable";
15
19
  import { ComputedSignal, Signal } from "./signal";
16
20
  import { Action } from "./types";
@@ -55,19 +59,16 @@ export class ExtendableStoreAdapter<
55
59
 
56
60
  constructor(
57
61
  public context: {
58
- transform: UnaryFunction<
59
- Promise<string>,
60
- {
61
- share: UnaryFunction<
62
- {
63
- args: unknown;
64
- callback: UnaryFunction<unknown, void>;
65
- sameOrigin?: boolean;
66
- },
67
- void
68
- >;
69
- register: UnaryFunction<(args: any) => EndoFunction<any>, void>;
70
- }
62
+ share: UnaryFunction<
63
+ MulticastMessageConstructor<MulticastClientMessage>,
64
+ void
65
+ >;
66
+ register: UnaryFunction<
67
+ UnaryFunction<
68
+ MulticastHostMessage,
69
+ Promise<MulticastAction<any, "transformAction"> | undefined>
70
+ >,
71
+ void
71
72
  >;
72
73
  },
73
74
  private extendableSignals: ExtendableDictionary<
@@ -136,17 +137,47 @@ export class ExtendableStoreAdapter<
136
137
  mapValues(
137
138
  this.extendableSignals.currentValue,
138
139
  (signal) => ({
139
- update: (predicate, config = {}) =>
140
- thru(this.context.transform(key), (transform) => {
141
- transform.register((args) =>
142
- signal.pull(predicate(args)),
140
+ update: (predicate, config = {}) => {
141
+ const callbacks = new Map<
142
+ string,
143
+ UnaryFunction<unknown, void>
144
+ >();
145
+
146
+ this.context.register(async (event) => {
147
+ if (
148
+ event.type === "transformAction" &&
149
+ event.data.key === (await key)
150
+ ) {
151
+ return {
152
+ ...event,
153
+ predicate: signal.pull(
154
+ predicate(
155
+ Serializable.parse(event.data.args ?? null),
156
+ ),
157
+ ),
158
+ callback: callbacks.get(event.id),
159
+ };
160
+ }
161
+ });
162
+
163
+ return (args) =>
164
+ new Promise<unknown>((callback) =>
165
+ this.context.share(
166
+ async ({ id }) => (
167
+ callbacks.set(id, callback),
168
+ {
169
+ id,
170
+ type: "transformAction",
171
+ data: {
172
+ key: await key,
173
+ args: JSON.stringify(args),
174
+ },
175
+ sameOrigin: config.sameOrigin,
176
+ }
177
+ ),
178
+ ),
143
179
  );
144
-
145
- return (args) =>
146
- new Promise<unknown>((callback) =>
147
- transform.share({ args, callback, ...config }),
148
- );
149
- }),
180
+ },
150
181
  }),
151
182
  ),
152
183
  ),
@@ -177,55 +208,22 @@ export class StoreProvider<Data> extends ExtendableStoreAdapter<
177
208
  ),
178
209
  );
179
210
 
180
- const callbacks = new Map<string, UnaryFunction<unknown, void>>();
181
-
182
211
  super(
183
212
  {
184
- 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) =>
201
- actions
202
- .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
- }),
219
- flatMap(identity),
220
- )
221
- .subscribe(transformActions),
222
- }),
213
+ share: (action) => actions.next(action),
214
+ register: (project) =>
215
+ actions
216
+ .pipe(
217
+ mergeMap(project),
218
+ flatMap((action) => action ?? []),
219
+ )
220
+ .subscribe(transformActions),
223
221
  },
224
222
  new ExtendableDictionary({
225
223
  data: new ComputedSignal({
226
224
  value: merge(seedActions, transformActions).pipe(
227
- sequence<MulticastAction<Data>, Data>(
228
- ([action, previousAction], [previousState]) => {
225
+ chain<MulticastAction<Data>, Data>(
226
+ ([action, previousAction], previousStates) => {
229
227
  console.log(action);
230
228
 
231
229
  if (action.type === "seedAction") {
@@ -234,12 +232,12 @@ export class StoreProvider<Data> extends ExtendableStoreAdapter<
234
232
 
235
233
  if (
236
234
  action.previousId !== previousAction?.id ||
237
- previousState == null
235
+ !(0 in previousStates)
238
236
  ) {
239
237
  throw new Error();
240
238
  }
241
239
 
242
- return tap(action.predicate(previousState), (state) =>
240
+ return tap(action.predicate(previousStates[0]), (state) =>
243
241
  action.callback?.call(null, state),
244
242
  );
245
243
  },
@@ -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
- );