@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.
- package/package.json +1 -1
- package/src/store.ts +58 -73
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,
|
|
@@ -60,21 +59,16 @@ export class ExtendableStoreAdapter<
|
|
|
60
59
|
|
|
61
60
|
constructor(
|
|
62
61
|
public context: {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
predicate
|
|
161
|
-
|
|
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
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
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({
|