@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 +1 -1
- package/src/lib/memoize.ts +3 -1
- package/src/operators/multicast.ts +1 -1
- package/src/store.ts +29 -30
package/package.json
CHANGED
package/src/lib/memoize.ts
CHANGED
|
@@ -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>) =>
|
|
5
|
+
lodash.memoize(func, (...args: Parameters<T>) =>
|
|
6
|
+
lodash.tap(objectHash(args ?? null), (hash) => console.log({ hash, args })),
|
|
7
|
+
);
|
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
|
|
61
|
+
public transform: {
|
|
62
62
|
share: UnaryFunction<
|
|
63
63
|
MulticastMessageConstructor<MulticastClientMessage>,
|
|
64
64
|
void
|
|
65
65
|
>;
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
>,
|
|
71
|
-
|
|
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.
|
|
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.
|
|
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.
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
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.
|
|
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
|
-
|
|
206
|
+
parse: (key, handler) =>
|
|
215
207
|
actions
|
|
216
208
|
.pipe(
|
|
217
|
-
mergeMap(
|
|
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),
|