@genesislcap/foundation-store 14.393.2 → 14.393.3-FUI-2471.2
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/dist/dts/store/foundationStore.d.ts +24 -15
- package/dist/dts/store/foundationStore.d.ts.map +1 -1
- package/dist/esm/store/foundationStore.js +61 -15
- package/dist/foundation-store.api.json +52 -4
- package/dist/foundation-store.d.ts +24 -14
- package/docs/api/foundation-store.abstractstore.broadcastchannelname.md +13 -0
- package/docs/api/foundation-store.abstractstore.emit.md +2 -2
- package/docs/api/foundation-store.abstractstore.md +21 -0
- package/docs/api-report.md.api.md +7 -1
- package/package.json +13 -12
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { EventDetailMap } from '@genesislcap/foundation-events';
|
|
1
|
+
import type { EmitOptions, EventDetailMap } from '@genesislcap/foundation-events';
|
|
2
2
|
import { ErrorMap } from '@genesislcap/foundation-utils';
|
|
3
3
|
import { BindingObserver, Constructable, ExecutionContext } from '@microsoft/fast-element';
|
|
4
4
|
import { Key } from '@microsoft/fast-foundation';
|
|
@@ -273,6 +273,18 @@ export declare abstract class AbstractStore<TStore extends Store, TEventDetailMa
|
|
|
273
273
|
* @internal
|
|
274
274
|
*/
|
|
275
275
|
private eventListenerMap;
|
|
276
|
+
/**
|
|
277
|
+
* The broadcast channel name to enable cross-window synchronization.
|
|
278
|
+
* If set, events emitted with { broadcast: true } will be sent to this channel.
|
|
279
|
+
*
|
|
280
|
+
* @public
|
|
281
|
+
*/
|
|
282
|
+
protected broadcastChannelName: string | null;
|
|
283
|
+
/**
|
|
284
|
+
* The active broadcast channel instance.
|
|
285
|
+
* @internal
|
|
286
|
+
*/
|
|
287
|
+
private channel;
|
|
276
288
|
/**
|
|
277
289
|
* The store root fragment.
|
|
278
290
|
*
|
|
@@ -340,6 +352,16 @@ export declare abstract class AbstractStore<TStore extends Store, TEventDetailMa
|
|
|
340
352
|
connect(root: TStoreRoot): void;
|
|
341
353
|
/** {@inheritDoc StoreConnectable.disconnect} */
|
|
342
354
|
disconnect(root: TStoreRoot): void;
|
|
355
|
+
/**
|
|
356
|
+
* Connects the broadcast channel if a name is configured.
|
|
357
|
+
* @internal
|
|
358
|
+
*/
|
|
359
|
+
protected connectBroadcastChannel(): void;
|
|
360
|
+
/**
|
|
361
|
+
* Disconnects the broadcast channel.
|
|
362
|
+
* @internal
|
|
363
|
+
*/
|
|
364
|
+
protected disconnectBroadcastChannel(): void;
|
|
343
365
|
/** {@inheritDoc Store.errors} */
|
|
344
366
|
errors: ErrorMap<TEventDetailMap & TInternalEventDetailMap>;
|
|
345
367
|
/** {@inheritDoc Store.name} */
|
|
@@ -384,19 +406,6 @@ export declare abstract class AbstractStore<TStore extends Store, TEventDetailMa
|
|
|
384
406
|
* @internal
|
|
385
407
|
*/
|
|
386
408
|
private createListenerType;
|
|
387
|
-
/**
|
|
388
|
-
* Creates an event listener envelope.
|
|
389
|
-
*
|
|
390
|
-
* @remarks
|
|
391
|
-
* These wrap the provided token.
|
|
392
|
-
*
|
|
393
|
-
* @typeParam TDetail - The CustomEvent detail.
|
|
394
|
-
* @param listenerType - The type of event listener to create. See {@link EventListenerType}.
|
|
395
|
-
* @param token - The function handling the event.
|
|
396
|
-
* @returns An event listener.
|
|
397
|
-
*
|
|
398
|
-
* @internal
|
|
399
|
-
*/
|
|
400
409
|
private createListenerEnvelope;
|
|
401
410
|
/**
|
|
402
411
|
* Creates an event listener.
|
|
@@ -502,7 +511,7 @@ export declare abstract class AbstractStore<TStore extends Store, TEventDetailMa
|
|
|
502
511
|
* provided to define additional internal events like x-success, x-error etc, or public events from other store
|
|
503
512
|
* fragments.
|
|
504
513
|
*/
|
|
505
|
-
protected emit<K extends keyof (TEventDetailMap & TInternalEventDetailMap) & string>(...args: (TEventDetailMap & TInternalEventDetailMap)[K] extends void ? [key: K] : [key: K, detail: (TEventDetailMap & TInternalEventDetailMap)[K]]): void;
|
|
514
|
+
protected emit<K extends keyof (TEventDetailMap & TInternalEventDetailMap) & string>(...args: (TEventDetailMap & TInternalEventDetailMap)[K] extends void ? [key: K, options?: EmitOptions] : [key: K, detail: (TEventDetailMap & TInternalEventDetailMap)[K], options?: EmitOptions]): void;
|
|
506
515
|
/**
|
|
507
516
|
* A convenience method to invoke an async api and emit success and error events.
|
|
508
517
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"foundationStore.d.ts","sourceRoot":"","sources":["../../../src/store/foundationStore.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"foundationStore.d.ts","sourceRoot":"","sources":["../../../src/store/foundationStore.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAElF,OAAO,EAAkB,QAAQ,EAAS,MAAM,+BAA+B,CAAC;AAChF,OAAO,EACL,eAAe,EACf,aAAa,EAEb,gBAAgB,EAGjB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAM,GAAG,EAAE,MAAM,4BAA4B,CAAC;AAErD,OAAO,EAAE,UAAU,IAAI,YAAY,EAAM,MAAM,MAAM,CAAC;AAItD;;;;GAIG;AACH,MAAM,MAAM,wBAAwB,CAAC,OAAO,GAAG,GAAG,IAAI,CACpD,KAAK,EAAE,OAAO,EACd,IAAI,EAAE,eAAe,KAClB,IAAI,CAAC;AAEV;;;;;;GAMG;AACH,MAAM,WAAW,KAAK;IACpB;;;;;;;OAOG;IACH,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAEvB;;;;;;;;;;;;;;;;OAgBG;IACH,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,cAAc,CAAC,CAAC;IAE1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAgDG;IACH,OAAO,CAAC,OAAO,GAAG,GAAG,EAAE,OAAO,GAAG,GAAG,EAClC,KAAK,EAAE,CAAC,CAAC,KAAK,EAAE,IAAI,KAA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EACpC,GAAG,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,EAC3B,KAAK,EAAE,MAAM,CAAC,eAAe,GAAG,uBAAuB,CAAC,EACxD,OAAO,CAAC,EAAE,MAAM,CAAC,eAAe,GAAG,uBAAuB,CAAC;CAW9D;AAED;;;GAGG;AACH,MAAM,MAAM,uBAAuB,GAAG;IACpC,iBAAiB,EAAE,WAAW,CAAC;IAC/B,oBAAoB,EAAE,IAAI,CAAC;IAC3B,aAAa,EAAE,OAAO,CAAC;CACxB,CAAC;AAEF;;;;;;;GAOG;AACH,8BAAsB,iBAAiB,CACrC,MAAM,SAAS,SAAS,EACxB,eAAe,SAAS,uBAAuB,GAAG,uBAAuB,EACzE,uBAAuB,SAAS,cAAc,GAAG,eAAe,CAEhE,SAAQ,aAAa,CAAC,MAAM,EAAE,eAAe,EAAE,uBAAuB,CACtE,YAAW,SAAS;IAEpB,oCAAoC;IACxB,KAAK,EAAE,OAAO,CAAS;IAEnC,sCAAsC;IAC1B,OAAO,EAAE,WAAW,CAAC;IAEjC;;;;OAIG;IACH,SAAS,CAAC,IAAI,OAAQ;IAEtB;;;;;;;;OAQG;IACH,OAAO,CAAC,cAAc;IAatB,WAAW,gBAGT;IACF,cAAc,gBAGZ;IACF,OAAO,gBAAuF;CAC/F"}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { __awaiter, __decorate } from "tslib";
|
|
2
|
+
import { createTypedBroadcastChannel, } from '@genesislcap/foundation-broadcast-channel';
|
|
3
|
+
import { getBaseEmitArgs } from '@genesislcap/foundation-events';
|
|
2
4
|
import { createErrorMap, isDev } from '@genesislcap/foundation-utils';
|
|
3
5
|
import { defaultExecutionContext, observable, Observable as FASTObservable, } from '@microsoft/fast-element';
|
|
4
6
|
import { DI } from '@microsoft/fast-foundation';
|
|
@@ -80,6 +82,18 @@ export class AbstractStore {
|
|
|
80
82
|
* @internal
|
|
81
83
|
*/
|
|
82
84
|
this.eventListenerMap = new Map();
|
|
85
|
+
/**
|
|
86
|
+
* The broadcast channel name to enable cross-window synchronization.
|
|
87
|
+
* If set, events emitted with { broadcast: true } will be sent to this channel.
|
|
88
|
+
*
|
|
89
|
+
* @public
|
|
90
|
+
*/
|
|
91
|
+
this.broadcastChannelName = null;
|
|
92
|
+
/**
|
|
93
|
+
* The active broadcast channel instance.
|
|
94
|
+
* @internal
|
|
95
|
+
*/
|
|
96
|
+
this.channel = null;
|
|
83
97
|
/**
|
|
84
98
|
* The child store fragments this store fragment manages.
|
|
85
99
|
*
|
|
@@ -125,6 +139,7 @@ export class AbstractStore {
|
|
|
125
139
|
this.commit = new Proxy(this, this.commitHandler);
|
|
126
140
|
/** {@inheritDoc Store.errors} */
|
|
127
141
|
this.errors = createErrorMap(logger.error);
|
|
142
|
+
// ...
|
|
128
143
|
/**
|
|
129
144
|
* Creates an event listener by type.
|
|
130
145
|
*
|
|
@@ -145,19 +160,6 @@ export class AbstractStore {
|
|
|
145
160
|
});
|
|
146
161
|
return listenerKeys.length === 1 ? listener : undefined;
|
|
147
162
|
};
|
|
148
|
-
/**
|
|
149
|
-
* Creates an event listener envelope.
|
|
150
|
-
*
|
|
151
|
-
* @remarks
|
|
152
|
-
* These wrap the provided token.
|
|
153
|
-
*
|
|
154
|
-
* @typeParam TDetail - The CustomEvent detail.
|
|
155
|
-
* @param listenerType - The type of event listener to create. See {@link EventListenerType}.
|
|
156
|
-
* @param token - The function handling the event.
|
|
157
|
-
* @returns An event listener.
|
|
158
|
-
*
|
|
159
|
-
* @internal
|
|
160
|
-
*/
|
|
161
163
|
this.createListenerEnvelope = (listenerType, token) => {
|
|
162
164
|
if (listenerType === EventListenerType.async) {
|
|
163
165
|
return (event) => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -172,6 +174,19 @@ export class AbstractStore {
|
|
|
172
174
|
if (listenerType === EventListenerType.error) {
|
|
173
175
|
this.errors.set(type, detail);
|
|
174
176
|
}
|
|
177
|
+
if (event.broadcast) {
|
|
178
|
+
if (this.channel) {
|
|
179
|
+
/**
|
|
180
|
+
* TODO: Improve typing in PostMessage and/or here to avoid @ts-ignore.
|
|
181
|
+
* Safe to ignore because key and detail are already validated by the emit parameters.
|
|
182
|
+
*/
|
|
183
|
+
// @ts-ignore
|
|
184
|
+
this.channel.postMessage(type, detail);
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
console.warn(`[Store] Event ${type} marked for broadcast, but channel is not active.`);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
175
190
|
return token && token(detail, event);
|
|
176
191
|
};
|
|
177
192
|
};
|
|
@@ -301,13 +316,38 @@ export class AbstractStore {
|
|
|
301
316
|
this.root = root;
|
|
302
317
|
this.addEventListeners(root.element);
|
|
303
318
|
this.connectStoreFragments(root);
|
|
319
|
+
this.connectBroadcastChannel();
|
|
304
320
|
}
|
|
305
321
|
/** {@inheritDoc StoreConnectable.disconnect} */
|
|
306
322
|
disconnect(root) {
|
|
307
323
|
this.removeEventListeners(root.element);
|
|
308
324
|
this.disconnectStoreFragments(root);
|
|
325
|
+
this.disconnectBroadcastChannel();
|
|
309
326
|
this.root = undefined;
|
|
310
327
|
}
|
|
328
|
+
/**
|
|
329
|
+
* Connects the broadcast channel if a name is configured.
|
|
330
|
+
* @internal
|
|
331
|
+
*/
|
|
332
|
+
connectBroadcastChannel() {
|
|
333
|
+
if (this.broadcastChannelName && !this.channel) {
|
|
334
|
+
this.channel = createTypedBroadcastChannel(this.broadcastChannelName);
|
|
335
|
+
this.channel.onmessage = (ev) => {
|
|
336
|
+
// Re-emit received messages locally (without broadcasting back)
|
|
337
|
+
this.emit(ev.data.type, ev.data.detail);
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
342
|
+
* Disconnects the broadcast channel.
|
|
343
|
+
* @internal
|
|
344
|
+
*/
|
|
345
|
+
disconnectBroadcastChannel() {
|
|
346
|
+
if (this.channel) {
|
|
347
|
+
this.channel.close();
|
|
348
|
+
this.channel = null;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
311
351
|
/** {@inheritDoc Store.name} */
|
|
312
352
|
get name() {
|
|
313
353
|
return 'store';
|
|
@@ -393,12 +433,16 @@ export class AbstractStore {
|
|
|
393
433
|
* fragments.
|
|
394
434
|
*/
|
|
395
435
|
emit(...args) {
|
|
396
|
-
const [key, detail] = args;
|
|
436
|
+
const [key, detail, options] = getBaseEmitArgs(...args);
|
|
397
437
|
const hasDetail = detail !== undefined;
|
|
398
438
|
if (isDev()) {
|
|
399
439
|
logger.debug(`'${this.name}': Emit '${key}' store event${hasDetail ? ` with ${logValue(detail)}` : ''}`);
|
|
400
440
|
}
|
|
401
|
-
|
|
441
|
+
const event = new CustomEvent(key, Object.assign(Object.assign({ detail }, internalEmitOptions), options));
|
|
442
|
+
if (options === null || options === void 0 ? void 0 : options.broadcast) {
|
|
443
|
+
event.broadcast = true;
|
|
444
|
+
}
|
|
445
|
+
this.root.element.dispatchEvent(event);
|
|
402
446
|
}
|
|
403
447
|
/**
|
|
404
448
|
* A convenience method to invoke an async api and emit success and error events.
|
|
@@ -475,10 +519,12 @@ export class AbstractStoreRoot extends AbstractStore {
|
|
|
475
519
|
if (prev) {
|
|
476
520
|
this.removeEventListeners(prev);
|
|
477
521
|
this.disconnectStoreFragments(this);
|
|
522
|
+
this.disconnectBroadcastChannel();
|
|
478
523
|
}
|
|
479
524
|
if (next) {
|
|
480
525
|
this.addEventListeners(next);
|
|
481
526
|
this.connectStoreFragments(this);
|
|
527
|
+
this.connectBroadcastChannel();
|
|
482
528
|
}
|
|
483
529
|
}
|
|
484
530
|
}
|
|
@@ -709,6 +709,36 @@
|
|
|
709
709
|
"isAbstract": false,
|
|
710
710
|
"name": "bindingAsRx"
|
|
711
711
|
},
|
|
712
|
+
{
|
|
713
|
+
"kind": "Property",
|
|
714
|
+
"canonicalReference": "@genesislcap/foundation-store!AbstractStore#broadcastChannelName:member",
|
|
715
|
+
"docComment": "/**\n * The broadcast channel name to enable cross-window synchronization. If set, events emitted with { broadcast: true } will be sent to this channel.\n *\n * @public\n */\n",
|
|
716
|
+
"excerptTokens": [
|
|
717
|
+
{
|
|
718
|
+
"kind": "Content",
|
|
719
|
+
"text": "protected broadcastChannelName: "
|
|
720
|
+
},
|
|
721
|
+
{
|
|
722
|
+
"kind": "Content",
|
|
723
|
+
"text": "string | null"
|
|
724
|
+
},
|
|
725
|
+
{
|
|
726
|
+
"kind": "Content",
|
|
727
|
+
"text": ";"
|
|
728
|
+
}
|
|
729
|
+
],
|
|
730
|
+
"isReadonly": false,
|
|
731
|
+
"isOptional": false,
|
|
732
|
+
"releaseTag": "Public",
|
|
733
|
+
"name": "broadcastChannelName",
|
|
734
|
+
"propertyTypeTokenRange": {
|
|
735
|
+
"startIndex": 1,
|
|
736
|
+
"endIndex": 2
|
|
737
|
+
},
|
|
738
|
+
"isStatic": false,
|
|
739
|
+
"isProtected": true,
|
|
740
|
+
"isAbstract": false
|
|
741
|
+
},
|
|
712
742
|
{
|
|
713
743
|
"kind": "Property",
|
|
714
744
|
"canonicalReference": "@genesislcap/foundation-store!AbstractStore#commit:member",
|
|
@@ -1125,7 +1155,25 @@
|
|
|
1125
1155
|
},
|
|
1126
1156
|
{
|
|
1127
1157
|
"kind": "Content",
|
|
1128
|
-
"text": "(TEventDetailMap & TInternalEventDetailMap)[K] extends void ? [key: K
|
|
1158
|
+
"text": "(TEventDetailMap & TInternalEventDetailMap)[K] extends void ? [key: K, options?: "
|
|
1159
|
+
},
|
|
1160
|
+
{
|
|
1161
|
+
"kind": "Reference",
|
|
1162
|
+
"text": "EmitOptions",
|
|
1163
|
+
"canonicalReference": "@genesislcap/foundation-events!EmitOptions:type"
|
|
1164
|
+
},
|
|
1165
|
+
{
|
|
1166
|
+
"kind": "Content",
|
|
1167
|
+
"text": "] : [key: K, detail: (TEventDetailMap & TInternalEventDetailMap)[K], options?: "
|
|
1168
|
+
},
|
|
1169
|
+
{
|
|
1170
|
+
"kind": "Reference",
|
|
1171
|
+
"text": "EmitOptions",
|
|
1172
|
+
"canonicalReference": "@genesislcap/foundation-events!EmitOptions:type"
|
|
1173
|
+
},
|
|
1174
|
+
{
|
|
1175
|
+
"kind": "Content",
|
|
1176
|
+
"text": "]"
|
|
1129
1177
|
},
|
|
1130
1178
|
{
|
|
1131
1179
|
"kind": "Content",
|
|
@@ -1155,8 +1203,8 @@
|
|
|
1155
1203
|
],
|
|
1156
1204
|
"isStatic": false,
|
|
1157
1205
|
"returnTypeTokenRange": {
|
|
1158
|
-
"startIndex":
|
|
1159
|
-
"endIndex":
|
|
1206
|
+
"startIndex": 9,
|
|
1207
|
+
"endIndex": 10
|
|
1160
1208
|
},
|
|
1161
1209
|
"releaseTag": "Public",
|
|
1162
1210
|
"isProtected": true,
|
|
@@ -1166,7 +1214,7 @@
|
|
|
1166
1214
|
"parameterName": "args",
|
|
1167
1215
|
"parameterTypeTokenRange": {
|
|
1168
1216
|
"startIndex": 3,
|
|
1169
|
-
"endIndex":
|
|
1217
|
+
"endIndex": 8
|
|
1170
1218
|
},
|
|
1171
1219
|
"isOptional": false
|
|
1172
1220
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { BindingObserver } from '@microsoft/fast-element';
|
|
2
2
|
import { Constructable } from '@microsoft/fast-element';
|
|
3
|
+
import type { EmitOptions } from '@genesislcap/foundation-events';
|
|
3
4
|
import { ErrorMap as ErrorMap_2 } from '@genesislcap/foundation-utils';
|
|
4
5
|
import type { EventDetailMap } from '@genesislcap/foundation-events';
|
|
5
6
|
import { ExecutionContext } from '@microsoft/fast-element';
|
|
@@ -28,6 +29,18 @@ export declare abstract class AbstractStore<TStore extends Store, TEventDetailMa
|
|
|
28
29
|
* @internal
|
|
29
30
|
*/
|
|
30
31
|
private eventListenerMap;
|
|
32
|
+
/**
|
|
33
|
+
* The broadcast channel name to enable cross-window synchronization.
|
|
34
|
+
* If set, events emitted with { broadcast: true } will be sent to this channel.
|
|
35
|
+
*
|
|
36
|
+
* @public
|
|
37
|
+
*/
|
|
38
|
+
protected broadcastChannelName: string | null;
|
|
39
|
+
/**
|
|
40
|
+
* The active broadcast channel instance.
|
|
41
|
+
* @internal
|
|
42
|
+
*/
|
|
43
|
+
private channel;
|
|
31
44
|
/**
|
|
32
45
|
* The store root fragment.
|
|
33
46
|
*
|
|
@@ -95,6 +108,16 @@ export declare abstract class AbstractStore<TStore extends Store, TEventDetailMa
|
|
|
95
108
|
connect(root: TStoreRoot): void;
|
|
96
109
|
/** {@inheritDoc StoreConnectable.disconnect} */
|
|
97
110
|
disconnect(root: TStoreRoot): void;
|
|
111
|
+
/**
|
|
112
|
+
* Connects the broadcast channel if a name is configured.
|
|
113
|
+
* @internal
|
|
114
|
+
*/
|
|
115
|
+
protected connectBroadcastChannel(): void;
|
|
116
|
+
/**
|
|
117
|
+
* Disconnects the broadcast channel.
|
|
118
|
+
* @internal
|
|
119
|
+
*/
|
|
120
|
+
protected disconnectBroadcastChannel(): void;
|
|
98
121
|
/** {@inheritDoc Store.errors} */
|
|
99
122
|
errors: ErrorMap_2<TEventDetailMap & TInternalEventDetailMap>;
|
|
100
123
|
/** {@inheritDoc Store.name} */
|
|
@@ -139,19 +162,6 @@ export declare abstract class AbstractStore<TStore extends Store, TEventDetailMa
|
|
|
139
162
|
* @internal
|
|
140
163
|
*/
|
|
141
164
|
private createListenerType;
|
|
142
|
-
/**
|
|
143
|
-
* Creates an event listener envelope.
|
|
144
|
-
*
|
|
145
|
-
* @remarks
|
|
146
|
-
* These wrap the provided token.
|
|
147
|
-
*
|
|
148
|
-
* @typeParam TDetail - The CustomEvent detail.
|
|
149
|
-
* @param listenerType - The type of event listener to create. See {@link EventListenerType}.
|
|
150
|
-
* @param token - The function handling the event.
|
|
151
|
-
* @returns An event listener.
|
|
152
|
-
*
|
|
153
|
-
* @internal
|
|
154
|
-
*/
|
|
155
165
|
private createListenerEnvelope;
|
|
156
166
|
/**
|
|
157
167
|
* Creates an event listener.
|
|
@@ -257,7 +267,7 @@ export declare abstract class AbstractStore<TStore extends Store, TEventDetailMa
|
|
|
257
267
|
* provided to define additional internal events like x-success, x-error etc, or public events from other store
|
|
258
268
|
* fragments.
|
|
259
269
|
*/
|
|
260
|
-
protected emit<K extends keyof (TEventDetailMap & TInternalEventDetailMap) & string>(...args: (TEventDetailMap & TInternalEventDetailMap)[K] extends void ? [key: K] : [key: K, detail: (TEventDetailMap & TInternalEventDetailMap)[K]]): void;
|
|
270
|
+
protected emit<K extends keyof (TEventDetailMap & TInternalEventDetailMap) & string>(...args: (TEventDetailMap & TInternalEventDetailMap)[K] extends void ? [key: K, options?: EmitOptions] : [key: K, detail: (TEventDetailMap & TInternalEventDetailMap)[K], options?: EmitOptions]): void;
|
|
261
271
|
/**
|
|
262
272
|
* A convenience method to invoke an async api and emit success and error events.
|
|
263
273
|
*
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
|
2
|
+
|
|
3
|
+
[Home](./index.md) > [@genesislcap/foundation-store](./foundation-store.md) > [AbstractStore](./foundation-store.abstractstore.md) > [broadcastChannelName](./foundation-store.abstractstore.broadcastchannelname.md)
|
|
4
|
+
|
|
5
|
+
## AbstractStore.broadcastChannelName property
|
|
6
|
+
|
|
7
|
+
The broadcast channel name to enable cross-window synchronization. If set, events emitted with { broadcast: true } will be sent to this channel.
|
|
8
|
+
|
|
9
|
+
**Signature:**
|
|
10
|
+
|
|
11
|
+
```typescript
|
|
12
|
+
protected broadcastChannelName: string | null;
|
|
13
|
+
```
|
|
@@ -9,7 +9,7 @@ Emit events to the stores directly via the standard event flow.
|
|
|
9
9
|
**Signature:**
|
|
10
10
|
|
|
11
11
|
```typescript
|
|
12
|
-
protected emit<K extends keyof (TEventDetailMap & TInternalEventDetailMap) & string>(...args: (TEventDetailMap & TInternalEventDetailMap)[K] extends void ? [key: K] : [key: K, detail: (TEventDetailMap & TInternalEventDetailMap)[K]]): void;
|
|
12
|
+
protected emit<K extends keyof (TEventDetailMap & TInternalEventDetailMap) & string>(...args: (TEventDetailMap & TInternalEventDetailMap)[K] extends void ? [key: K, options?: EmitOptions] : [key: K, detail: (TEventDetailMap & TInternalEventDetailMap)[K], options?: EmitOptions]): void;
|
|
13
13
|
```
|
|
14
14
|
|
|
15
15
|
## Parameters
|
|
@@ -37,7 +37,7 @@ args
|
|
|
37
37
|
|
|
38
38
|
</td><td>
|
|
39
39
|
|
|
40
|
-
(TEventDetailMap & TInternalEventDetailMap)\[K\] extends void ? \[key: K\] : \[key: K, detail: (TEventDetailMap & TInternalEventDetailMap)\[K\]\]
|
|
40
|
+
(TEventDetailMap & TInternalEventDetailMap)\[K\] extends void ? \[key: K, options?: EmitOptions\] : \[key: K, detail: (TEventDetailMap & TInternalEventDetailMap)\[K\], options?: EmitOptions\]
|
|
41
41
|
|
|
42
42
|
|
|
43
43
|
</td><td>
|
|
@@ -72,6 +72,27 @@ Description
|
|
|
72
72
|
</th></tr></thead>
|
|
73
73
|
<tbody><tr><td>
|
|
74
74
|
|
|
75
|
+
[broadcastChannelName](./foundation-store.abstractstore.broadcastchannelname.md)
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
</td><td>
|
|
79
|
+
|
|
80
|
+
`protected`
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
</td><td>
|
|
84
|
+
|
|
85
|
+
string \| null
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
</td><td>
|
|
89
|
+
|
|
90
|
+
The broadcast channel name to enable cross-window synchronization. If set, events emitted with { broadcast: true } will be sent to this channel.
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
</td></tr>
|
|
94
|
+
<tr><td>
|
|
95
|
+
|
|
75
96
|
[commit](./foundation-store.abstractstore.commit.md)
|
|
76
97
|
|
|
77
98
|
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
import { BindingObserver } from '@microsoft/fast-element';
|
|
8
8
|
import { Constructable } from '@microsoft/fast-element';
|
|
9
|
+
import type { EmitOptions } from '@genesislcap/foundation-events';
|
|
9
10
|
import { ErrorMap as ErrorMap_2 } from '@genesislcap/foundation-utils';
|
|
10
11
|
import type { EventDetailMap } from '@genesislcap/foundation-events';
|
|
11
12
|
import { ExecutionContext } from '@microsoft/fast-element';
|
|
@@ -33,6 +34,7 @@ export abstract class AbstractStore<TStore extends Store, TEventDetailMap extend
|
|
|
33
34
|
//
|
|
34
35
|
// (undocumented)
|
|
35
36
|
bindingAsRx<TReturn>(getter: (store: this) => TReturn): Observable<TReturn>;
|
|
37
|
+
protected broadcastChannelName: string | null;
|
|
36
38
|
// @beta
|
|
37
39
|
protected readonly commit: this;
|
|
38
40
|
// @internal
|
|
@@ -41,6 +43,8 @@ export abstract class AbstractStore<TStore extends Store, TEventDetailMap extend
|
|
|
41
43
|
protected commitValue<K extends keyof TStore>(key: K, value: TStore[K]): void;
|
|
42
44
|
connect(root: TStoreRoot): void;
|
|
43
45
|
// @internal
|
|
46
|
+
protected connectBroadcastChannel(): void;
|
|
47
|
+
// @internal
|
|
44
48
|
protected connectStoreFragments(root: TStoreRoot, storeFragments?: Store[]): void;
|
|
45
49
|
// Warning: (ae-incompatible-release-tags) The symbol "createAsyncListener" is marked as @public, but its signature references "KeyOrKeys" which is marked as @internal
|
|
46
50
|
protected createAsyncListener: <TDetail = void, TReturn = void>(keys: KeyOrKeys<TEventDetailMap & TInternalEventDetailMap>, token: (detail: TDetail, event?: CustomEvent<TDetail>) => Promise<TReturn>) => EventListener;
|
|
@@ -50,8 +54,10 @@ export abstract class AbstractStore<TStore extends Store, TEventDetailMap extend
|
|
|
50
54
|
protected createListener: <TDetail = void>(keys: KeyOrKeys<TEventDetailMap & TInternalEventDetailMap>, token: (detail: TDetail, event?: CustomEvent<TDetail>) => void) => EventListener;
|
|
51
55
|
disconnect(root: TStoreRoot): void;
|
|
52
56
|
// @internal
|
|
57
|
+
protected disconnectBroadcastChannel(): void;
|
|
58
|
+
// @internal
|
|
53
59
|
protected disconnectStoreFragments(root: TStoreRoot, storeFragments?: Store[]): void;
|
|
54
|
-
protected emit<K extends keyof (TEventDetailMap & TInternalEventDetailMap) & string>(...args: (TEventDetailMap & TInternalEventDetailMap)[K] extends void ? [key: K] : [key: K, detail: (TEventDetailMap & TInternalEventDetailMap)[K]]): void;
|
|
60
|
+
protected emit<K extends keyof (TEventDetailMap & TInternalEventDetailMap) & string>(...args: (TEventDetailMap & TInternalEventDetailMap)[K] extends void ? [key: K, options?: EmitOptions] : [key: K, detail: (TEventDetailMap & TInternalEventDetailMap)[K], options?: EmitOptions]): void;
|
|
55
61
|
errors: ErrorMap_2<TEventDetailMap & TInternalEventDetailMap>;
|
|
56
62
|
protected invokeAsyncAPI<TResult>(api: () => Promise<TResult>, error: keyof (TEventDetailMap & TInternalEventDetailMap), success?: keyof (TEventDetailMap & TInternalEventDetailMap)): Promise<void>;
|
|
57
63
|
get name(): string;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@genesislcap/foundation-store",
|
|
3
3
|
"description": "Genesis Foundation Store",
|
|
4
|
-
"version": "14.393.2",
|
|
4
|
+
"version": "14.393.3-FUI-2471.2",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"license": "SEE LICENSE IN license.txt",
|
|
7
7
|
"main": "dist/esm/index.js",
|
|
@@ -38,18 +38,19 @@
|
|
|
38
38
|
}
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@genesislcap/foundation-testing": "14.393.2",
|
|
42
|
-
"@genesislcap/genx": "14.393.2",
|
|
43
|
-
"@genesislcap/rollup-builder": "14.393.2",
|
|
44
|
-
"@genesislcap/ts-builder": "14.393.2",
|
|
45
|
-
"@genesislcap/uvu-playwright-builder": "14.393.2",
|
|
46
|
-
"@genesislcap/vite-builder": "14.393.2",
|
|
47
|
-
"@genesislcap/webpack-builder": "14.393.2"
|
|
41
|
+
"@genesislcap/foundation-testing": "14.393.3-FUI-2471.2",
|
|
42
|
+
"@genesislcap/genx": "14.393.3-FUI-2471.2",
|
|
43
|
+
"@genesislcap/rollup-builder": "14.393.3-FUI-2471.2",
|
|
44
|
+
"@genesislcap/ts-builder": "14.393.3-FUI-2471.2",
|
|
45
|
+
"@genesislcap/uvu-playwright-builder": "14.393.3-FUI-2471.2",
|
|
46
|
+
"@genesislcap/vite-builder": "14.393.3-FUI-2471.2",
|
|
47
|
+
"@genesislcap/webpack-builder": "14.393.3-FUI-2471.2"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@genesislcap/foundation-
|
|
51
|
-
"@genesislcap/foundation-
|
|
52
|
-
"@genesislcap/foundation-
|
|
50
|
+
"@genesislcap/foundation-broadcast-channel": "14.393.3-FUI-2471.2",
|
|
51
|
+
"@genesislcap/foundation-events": "14.393.3-FUI-2471.2",
|
|
52
|
+
"@genesislcap/foundation-logger": "14.393.3-FUI-2471.2",
|
|
53
|
+
"@genesislcap/foundation-utils": "14.393.3-FUI-2471.2",
|
|
53
54
|
"@microsoft/fast-element": "1.14.0",
|
|
54
55
|
"@microsoft/fast-foundation": "2.50.0",
|
|
55
56
|
"@microsoft/fast-web-utilities": "5.4.1",
|
|
@@ -64,5 +65,5 @@
|
|
|
64
65
|
"publishConfig": {
|
|
65
66
|
"access": "public"
|
|
66
67
|
},
|
|
67
|
-
"gitHead": "
|
|
68
|
+
"gitHead": "8d5276ff6ff9d909b67f0095a7cc2df458d1e8eb"
|
|
68
69
|
}
|