@cascateer/core 2.4.16 → 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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/store.ts +58 -73
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cascateer/core",
3
- "version": "2.4.16",
3
+ "version": "2.4.17",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/cascateer/core.git"
package/src/store.ts CHANGED
@@ -1,8 +1,7 @@
1
1
  import { EndoFunction, ExtendableDictionary } from "@cascateer/lib";
2
2
  import { chain, flatMap } from "@cascateer/lib/observables";
3
- import { constant, Dictionary, mapValues, tap, thru } from "lodash";
3
+ import { constant, Dictionary, mapValues, tap } from "lodash";
4
4
  import {
5
- identity,
6
5
  merge,
7
6
  mergeMap,
8
7
  Observable,
@@ -60,21 +59,16 @@ export class ExtendableStoreAdapter<
60
59
 
61
60
  constructor(
62
61
  public context: {
63
- transform: UnaryFunction<
64
- Promise<string>,
65
- {
66
- share: UnaryFunction<
67
- MulticastMessageConstructor<MulticastClientMessage>,
68
- void
69
- >;
70
- register: UnaryFunction<
71
- UnaryFunction<
72
- MulticastHostMessage,
73
- Promise<MulticastAction<any, "transformAction"> | undefined>
74
- >,
75
- void
76
- >;
77
- }
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
78
72
  >;
79
73
  },
80
74
  private extendableSignals: ExtendableDictionary<
@@ -143,50 +137,47 @@ export class ExtendableStoreAdapter<
143
137
  mapValues(
144
138
  this.extendableSignals.currentValue,
145
139
  (signal) => ({
146
- update: (predicate, config = {}) =>
147
- thru(this.context.transform(key), (transform) => {
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
- });
171
-
172
- return (args) =>
173
- new Promise<unknown>((callback) =>
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
- }
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),
186
156
  ),
187
157
  ),
188
- );
189
- }),
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
+ ),
179
+ );
180
+ },
190
181
  }),
191
182
  ),
192
183
  ),
@@ -217,22 +208,16 @@ export class StoreProvider<Data> extends ExtendableStoreAdapter<
217
208
  ),
218
209
  );
219
210
 
220
- const callbacks = new Map<string, UnaryFunction<unknown, void>>();
221
-
222
211
  super(
223
212
  {
224
- transform: (key) => ({
225
- share: (messageConstructor) => actions.next(messageConstructor),
226
- register: (project) =>
227
- actions
228
- .pipe(
229
- mergeMap((event) =>
230
- project(event).then((action) => action ?? []),
231
- ),
232
- flatMap(identity),
233
- )
234
- .subscribe(transformActions),
235
- }),
213
+ share: (action) => actions.next(action),
214
+ register: (project) =>
215
+ actions
216
+ .pipe(
217
+ mergeMap(project),
218
+ flatMap((action) => action ?? []),
219
+ )
220
+ .subscribe(transformActions),
236
221
  },
237
222
  new ExtendableDictionary({
238
223
  data: new ComputedSignal({