@cascateer/core 2.4.17 → 2.4.19

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cascateer/core",
3
- "version": "2.4.17",
3
+ "version": "2.4.19",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/cascateer/core.git"
@@ -2,4 +2,6 @@ import * as lodash from "lodash";
2
2
  import objectHash from "object-hash";
3
3
 
4
4
  export const memoize = <T extends (...args: any) => any>(func: T) =>
5
- lodash.memoize(func, (...args: Parameters<T>) => objectHash(args ?? null));
5
+ lodash.memoize(func, (...args: Parameters<T>) =>
6
+ lodash.tap(objectHash(args ?? null), (hash) => console.log({ hash, args })),
7
+ );
@@ -31,7 +31,7 @@ interface MulticastActions<Data> {
31
31
  };
32
32
  }
33
33
 
34
- type MulticastBaseActionMessage<
34
+ export type MulticastBaseActionMessage<
35
35
  Data,
36
36
  Type extends keyof MulticastActions<Data>,
37
37
  > = MulticastBaseMessage<Type, MulticastActions<Data>[Type]["data"]>;
package/src/store.ts CHANGED
@@ -11,8 +11,8 @@ import {
11
11
  } from "rxjs";
12
12
  import { MulticastAction, MulticastSubject } from "./operators";
13
13
  import {
14
+ MulticastBaseActionMessage,
14
15
  MulticastClientMessage,
15
- MulticastHostMessage,
16
16
  MulticastMessageConstructor,
17
17
  } from "./operators/multicast";
18
18
  import { Serializable } from "./serializable";
@@ -58,18 +58,17 @@ export class ExtendableStoreAdapter<
58
58
  }
59
59
 
60
60
  constructor(
61
- public context: {
61
+ public transform: {
62
62
  share: UnaryFunction<
63
63
  MulticastMessageConstructor<MulticastClientMessage>,
64
64
  void
65
65
  >;
66
- register: UnaryFunction<
67
- UnaryFunction<
68
- MulticastHostMessage,
69
- Promise<MulticastAction<any, "transformAction"> | undefined>
70
- >,
71
- void
72
- >;
66
+ parse: (
67
+ key: Promise<string>,
68
+ handler: (
69
+ action: MulticastBaseActionMessage<any, "transformAction">,
70
+ ) => MulticastAction<any, "transformAction">,
71
+ ) => void;
73
72
  },
74
73
  private extendableSignals: ExtendableDictionary<
75
74
  ComputedSignal<any>,
@@ -89,7 +88,7 @@ export class ExtendableStoreAdapter<
89
88
  >,
90
89
  ) {
91
90
  return new ExtendableStoreAdapter(
92
- this.context,
91
+ this.transform,
93
92
  this.extendableSignals.extend(
94
93
  (currentSignals) => () =>
95
94
  signals({
@@ -125,7 +124,7 @@ export class ExtendableStoreAdapter<
125
124
  >,
126
125
  ) {
127
126
  return new ExtendableStoreAdapter(
128
- this.context,
127
+ this.transform,
129
128
  this.extendableSignals,
130
129
  this.extendableActions.extend(
131
130
  () =>
@@ -143,26 +142,19 @@ export class ExtendableStoreAdapter<
143
142
  UnaryFunction<unknown, void>
144
143
  >();
145
144
 
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
- });
145
+ this.transform.parse(key, (event) => ({
146
+ ...event,
147
+ predicate: signal.pull(
148
+ predicate(
149
+ Serializable.parse(event.data.args ?? null),
150
+ ),
151
+ ),
152
+ callback: callbacks.get(event.id),
153
+ }));
162
154
 
163
155
  return (args) =>
164
156
  new Promise<unknown>((callback) =>
165
- this.context.share(
157
+ this.transform.share(
166
158
  async ({ id }) => (
167
159
  callbacks.set(id, callback),
168
160
  {
@@ -211,10 +203,17 @@ export class StoreProvider<Data> extends ExtendableStoreAdapter<
211
203
  super(
212
204
  {
213
205
  share: (action) => actions.next(action),
214
- register: (project) =>
206
+ parse: (key, handler) =>
215
207
  actions
216
208
  .pipe(
217
- mergeMap(project),
209
+ mergeMap(async (event) => {
210
+ if (
211
+ event.type === "transformAction" &&
212
+ event.data.key === (await key)
213
+ ) {
214
+ return handler(event);
215
+ }
216
+ }),
218
217
  flatMap((action) => action ?? []),
219
218
  )
220
219
  .subscribe(transformActions),