@cascateer/core 2.4.16 → 2.4.18
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/operators/multicast.ts +1 -1
- package/src/store.ts +62 -78
package/package.json
CHANGED
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
|
|
3
|
+
import { constant, Dictionary, mapValues, tap } from "lodash";
|
|
4
4
|
import {
|
|
5
|
-
identity,
|
|
6
5
|
merge,
|
|
7
6
|
mergeMap,
|
|
8
7
|
Observable,
|
|
@@ -12,8 +11,8 @@ import {
|
|
|
12
11
|
} from "rxjs";
|
|
13
12
|
import { MulticastAction, MulticastSubject } from "./operators";
|
|
14
13
|
import {
|
|
14
|
+
MulticastBaseActionMessage,
|
|
15
15
|
MulticastClientMessage,
|
|
16
|
-
MulticastHostMessage,
|
|
17
16
|
MulticastMessageConstructor,
|
|
18
17
|
} from "./operators/multicast";
|
|
19
18
|
import { Serializable } from "./serializable";
|
|
@@ -59,23 +58,17 @@ export class ExtendableStoreAdapter<
|
|
|
59
58
|
}
|
|
60
59
|
|
|
61
60
|
constructor(
|
|
62
|
-
public
|
|
63
|
-
|
|
64
|
-
|
|
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
|
-
}
|
|
61
|
+
public transform: {
|
|
62
|
+
share: UnaryFunction<
|
|
63
|
+
MulticastMessageConstructor<MulticastClientMessage>,
|
|
64
|
+
void
|
|
78
65
|
>;
|
|
66
|
+
parse: (
|
|
67
|
+
key: Promise<string>,
|
|
68
|
+
handler: (
|
|
69
|
+
action: MulticastBaseActionMessage<any, "transformAction">,
|
|
70
|
+
) => Promise<MulticastAction<any, "transformAction"> | undefined>,
|
|
71
|
+
) => void;
|
|
79
72
|
},
|
|
80
73
|
private extendableSignals: ExtendableDictionary<
|
|
81
74
|
ComputedSignal<any>,
|
|
@@ -95,7 +88,7 @@ export class ExtendableStoreAdapter<
|
|
|
95
88
|
>,
|
|
96
89
|
) {
|
|
97
90
|
return new ExtendableStoreAdapter(
|
|
98
|
-
this.
|
|
91
|
+
this.transform,
|
|
99
92
|
this.extendableSignals.extend(
|
|
100
93
|
(currentSignals) => () =>
|
|
101
94
|
signals({
|
|
@@ -131,7 +124,7 @@ export class ExtendableStoreAdapter<
|
|
|
131
124
|
>,
|
|
132
125
|
) {
|
|
133
126
|
return new ExtendableStoreAdapter(
|
|
134
|
-
this.
|
|
127
|
+
this.transform,
|
|
135
128
|
this.extendableSignals,
|
|
136
129
|
this.extendableActions.extend(
|
|
137
130
|
() =>
|
|
@@ -143,50 +136,40 @@ export class ExtendableStoreAdapter<
|
|
|
143
136
|
mapValues(
|
|
144
137
|
this.extendableSignals.currentValue,
|
|
145
138
|
(signal) => ({
|
|
146
|
-
update: (predicate, config = {}) =>
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
event.data.
|
|
157
|
-
)
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
),
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
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
|
-
),
|
|
139
|
+
update: (predicate, config = {}) => {
|
|
140
|
+
const callbacks = new Map<
|
|
141
|
+
string,
|
|
142
|
+
UnaryFunction<unknown, void>
|
|
143
|
+
>();
|
|
144
|
+
|
|
145
|
+
this.transform.parse(key, async (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
|
+
}));
|
|
154
|
+
|
|
155
|
+
return (args) =>
|
|
156
|
+
new Promise<unknown>((callback) =>
|
|
157
|
+
this.transform.share(
|
|
158
|
+
async ({ id }) => (
|
|
159
|
+
callbacks.set(id, callback),
|
|
160
|
+
{
|
|
161
|
+
id,
|
|
162
|
+
type: "transformAction",
|
|
163
|
+
data: {
|
|
164
|
+
key: await key,
|
|
165
|
+
args: JSON.stringify(args),
|
|
166
|
+
},
|
|
167
|
+
sameOrigin: config.sameOrigin,
|
|
168
|
+
}
|
|
187
169
|
),
|
|
188
|
-
)
|
|
189
|
-
|
|
170
|
+
),
|
|
171
|
+
);
|
|
172
|
+
},
|
|
190
173
|
}),
|
|
191
174
|
),
|
|
192
175
|
),
|
|
@@ -217,22 +200,23 @@ export class StoreProvider<Data> extends ExtendableStoreAdapter<
|
|
|
217
200
|
),
|
|
218
201
|
);
|
|
219
202
|
|
|
220
|
-
const callbacks = new Map<string, UnaryFunction<unknown, void>>();
|
|
221
|
-
|
|
222
203
|
super(
|
|
223
204
|
{
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
205
|
+
share: (action) => actions.next(action),
|
|
206
|
+
parse: (key, handler) =>
|
|
207
|
+
actions
|
|
208
|
+
.pipe(
|
|
209
|
+
mergeMap(async (event) => {
|
|
210
|
+
if (
|
|
211
|
+
event.type === "transformAction" &&
|
|
212
|
+
event.data.key === (await key)
|
|
213
|
+
) {
|
|
214
|
+
return handler(event);
|
|
215
|
+
}
|
|
216
|
+
}),
|
|
217
|
+
flatMap((action) => action ?? []),
|
|
218
|
+
)
|
|
219
|
+
.subscribe(transformActions),
|
|
236
220
|
},
|
|
237
221
|
new ExtendableDictionary({
|
|
238
222
|
data: new ComputedSignal({
|