@genesislcap/foundation-store 14.395.0 → 14.396.1
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 +59 -15
- package/dist/foundation-store.api.json +52 -4
- package/dist/foundation-store.d.ts +24 -14
- package/docs/.gitattributes +2 -0
- 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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AAC,OAAO,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
|
*
|
|
@@ -145,19 +159,6 @@ export class AbstractStore {
|
|
|
145
159
|
});
|
|
146
160
|
return listenerKeys.length === 1 ? listener : undefined;
|
|
147
161
|
};
|
|
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
162
|
this.createListenerEnvelope = (listenerType, token) => {
|
|
162
163
|
if (listenerType === EventListenerType.async) {
|
|
163
164
|
return (event) => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -172,6 +173,19 @@ export class AbstractStore {
|
|
|
172
173
|
if (listenerType === EventListenerType.error) {
|
|
173
174
|
this.errors.set(type, detail);
|
|
174
175
|
}
|
|
176
|
+
if (event.broadcast) {
|
|
177
|
+
if (this.channel) {
|
|
178
|
+
/**
|
|
179
|
+
* TODO: Improve typing in PostMessage and/or here to avoid @ts-ignore.
|
|
180
|
+
* Safe to ignore because key and detail are already validated by the emit parameters.
|
|
181
|
+
*/
|
|
182
|
+
// @ts-ignore
|
|
183
|
+
this.channel.postMessage(type, detail);
|
|
184
|
+
}
|
|
185
|
+
else {
|
|
186
|
+
console.warn(`[Store] Event ${type} marked for broadcast, but channel is not active.`);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
175
189
|
return token && token(detail, event);
|
|
176
190
|
};
|
|
177
191
|
};
|
|
@@ -301,13 +315,37 @@ export class AbstractStore {
|
|
|
301
315
|
this.root = root;
|
|
302
316
|
this.addEventListeners(root.element);
|
|
303
317
|
this.connectStoreFragments(root);
|
|
318
|
+
this.connectBroadcastChannel();
|
|
304
319
|
}
|
|
305
320
|
/** {@inheritDoc StoreConnectable.disconnect} */
|
|
306
321
|
disconnect(root) {
|
|
307
322
|
this.removeEventListeners(root.element);
|
|
308
323
|
this.disconnectStoreFragments(root);
|
|
324
|
+
this.disconnectBroadcastChannel();
|
|
309
325
|
this.root = undefined;
|
|
310
326
|
}
|
|
327
|
+
/**
|
|
328
|
+
* Connects the broadcast channel if a name is configured.
|
|
329
|
+
* @internal
|
|
330
|
+
*/
|
|
331
|
+
connectBroadcastChannel() {
|
|
332
|
+
if (this.broadcastChannelName && !this.channel) {
|
|
333
|
+
this.channel = createTypedBroadcastChannel(this.broadcastChannelName);
|
|
334
|
+
this.channel.onmessage = (ev) => {
|
|
335
|
+
this.emit(ev.data.type, ev.data.detail);
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
/**
|
|
340
|
+
* Disconnects the broadcast channel.
|
|
341
|
+
* @internal
|
|
342
|
+
*/
|
|
343
|
+
disconnectBroadcastChannel() {
|
|
344
|
+
if (this.channel) {
|
|
345
|
+
this.channel.close();
|
|
346
|
+
this.channel = null;
|
|
347
|
+
}
|
|
348
|
+
}
|
|
311
349
|
/** {@inheritDoc Store.name} */
|
|
312
350
|
get name() {
|
|
313
351
|
return 'store';
|
|
@@ -393,12 +431,16 @@ export class AbstractStore {
|
|
|
393
431
|
* fragments.
|
|
394
432
|
*/
|
|
395
433
|
emit(...args) {
|
|
396
|
-
const [key, detail] = args;
|
|
434
|
+
const [key, detail, options] = getBaseEmitArgs(...args);
|
|
397
435
|
const hasDetail = detail !== undefined;
|
|
398
436
|
if (isDev()) {
|
|
399
437
|
logger.debug(`'${this.name}': Emit '${key}' store event${hasDetail ? ` with ${logValue(detail)}` : ''}`);
|
|
400
438
|
}
|
|
401
|
-
|
|
439
|
+
const event = new CustomEvent(key, Object.assign(Object.assign({ detail }, internalEmitOptions), options));
|
|
440
|
+
if (options === null || options === void 0 ? void 0 : options.broadcast) {
|
|
441
|
+
event.broadcast = true;
|
|
442
|
+
}
|
|
443
|
+
this.root.element.dispatchEvent(event);
|
|
402
444
|
}
|
|
403
445
|
/**
|
|
404
446
|
* A convenience method to invoke an async api and emit success and error events.
|
|
@@ -475,10 +517,12 @@ export class AbstractStoreRoot extends AbstractStore {
|
|
|
475
517
|
if (prev) {
|
|
476
518
|
this.removeEventListeners(prev);
|
|
477
519
|
this.disconnectStoreFragments(this);
|
|
520
|
+
this.disconnectBroadcastChannel();
|
|
478
521
|
}
|
|
479
522
|
if (next) {
|
|
480
523
|
this.addEventListeners(next);
|
|
481
524
|
this.connectStoreFragments(this);
|
|
525
|
+
this.connectBroadcastChannel();
|
|
482
526
|
}
|
|
483
527
|
}
|
|
484
528
|
}
|
|
@@ -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.
|
|
4
|
+
"version": "14.396.1",
|
|
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.
|
|
42
|
-
"@genesislcap/genx": "14.
|
|
43
|
-
"@genesislcap/rollup-builder": "14.
|
|
44
|
-
"@genesislcap/ts-builder": "14.
|
|
45
|
-
"@genesislcap/uvu-playwright-builder": "14.
|
|
46
|
-
"@genesislcap/vite-builder": "14.
|
|
47
|
-
"@genesislcap/webpack-builder": "14.
|
|
41
|
+
"@genesislcap/foundation-testing": "14.396.1",
|
|
42
|
+
"@genesislcap/genx": "14.396.1",
|
|
43
|
+
"@genesislcap/rollup-builder": "14.396.1",
|
|
44
|
+
"@genesislcap/ts-builder": "14.396.1",
|
|
45
|
+
"@genesislcap/uvu-playwright-builder": "14.396.1",
|
|
46
|
+
"@genesislcap/vite-builder": "14.396.1",
|
|
47
|
+
"@genesislcap/webpack-builder": "14.396.1"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@genesislcap/foundation-
|
|
51
|
-
"@genesislcap/foundation-
|
|
52
|
-
"@genesislcap/foundation-
|
|
50
|
+
"@genesislcap/foundation-broadcast-channel": "14.396.1",
|
|
51
|
+
"@genesislcap/foundation-events": "14.396.1",
|
|
52
|
+
"@genesislcap/foundation-logger": "14.396.1",
|
|
53
|
+
"@genesislcap/foundation-utils": "14.396.1",
|
|
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": "4a6225102f4b6566bff9ec8a91848d661b528588"
|
|
68
69
|
}
|