@genesislcap/foundation-broadcast-channel 14.172.0
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +87 -0
- package/dist/dts/__test__/config.d.ts +12 -0
- package/dist/dts/__test__/config.d.ts.map +1 -0
- package/dist/dts/__test__/elements.d.ts +59 -0
- package/dist/dts/__test__/elements.d.ts.map +1 -0
- package/dist/dts/__test__/index.d.ts +4 -0
- package/dist/dts/__test__/index.d.ts.map +1 -0
- package/dist/dts/__test__/types.d.ts +28 -0
- package/dist/dts/__test__/types.d.ts.map +1 -0
- package/dist/dts/broadcast-channel/broadcast-channel.d.ts +123 -0
- package/dist/dts/broadcast-channel/broadcast-channel.d.ts.map +1 -0
- package/dist/dts/broadcast-channel/index.d.ts +2 -0
- package/dist/dts/broadcast-channel/index.d.ts.map +1 -0
- package/dist/dts/index.d.ts +3 -0
- package/dist/dts/index.d.ts.map +1 -0
- package/dist/dts/index.federated.d.ts +1 -0
- package/dist/dts/index.federated.d.ts.map +1 -0
- package/dist/dts/tsdoc-metadata.json +11 -0
- package/dist/dts/utils/index.d.ts +2 -0
- package/dist/dts/utils/index.d.ts.map +1 -0
- package/dist/dts/utils/logger.d.ts +5 -0
- package/dist/dts/utils/logger.d.ts.map +1 -0
- package/dist/esm/__test__/config.js +7 -0
- package/dist/esm/__test__/elements.js +108 -0
- package/dist/esm/__test__/index.js +3 -0
- package/dist/esm/__test__/types.js +24 -0
- package/dist/esm/broadcast-channel/broadcast-channel.js +61 -0
- package/dist/esm/broadcast-channel/index.js +1 -0
- package/dist/esm/index.federated.js +1 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/utils/index.js +1 -0
- package/dist/esm/utils/logger.js +5 -0
- package/dist/foundation-broadcast-channel.api.json +797 -0
- package/dist/foundation-broadcast-channel.d.ts +138 -0
- package/docs/.gitattributes +2 -0
- package/docs/api/foundation-broadcast-channel.createtypedbroadcastchannel.md +25 -0
- package/docs/api/foundation-broadcast-channel.defaulttypedbroadcastchannel.ismessagetype.md +13 -0
- package/docs/api/foundation-broadcast-channel.defaulttypedbroadcastchannel.md +24 -0
- package/docs/api/foundation-broadcast-channel.defaulttypedbroadcastchannel.postmessage.md +13 -0
- package/docs/api/foundation-broadcast-channel.logger.md +12 -0
- package/docs/api/foundation-broadcast-channel.md +32 -0
- package/docs/api/foundation-broadcast-channel.registertypedbroadcastchannel.md +24 -0
- package/docs/api/foundation-broadcast-channel.typedbroadcastchannel.ismessagetype.md +25 -0
- package/docs/api/foundation-broadcast-channel.typedbroadcastchannel.md +42 -0
- package/docs/api/foundation-broadcast-channel.typedbroadcastchannel.onmessage.md +34 -0
- package/docs/api/foundation-broadcast-channel.typedbroadcastchannel.onmessageerror.md +11 -0
- package/docs/api/foundation-broadcast-channel.typedbroadcastchannel.postmessage.md +29 -0
- package/docs/api/foundation-broadcast-channel.typedmessageevent.md +16 -0
- package/docs/api/index.md +12 -0
- package/docs/api-report.md +47 -0
- package/license.txt +46 -0
- package/package.json +43 -0
package/README.md
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
# Foundation Broadcast Channel
|
2
|
+
|
3
|
+
[![lerna](https://img.shields.io/badge/maintained%20with-lerna-cc00ff.svg)](https://lerna.js.org/)
|
4
|
+
[![TypeScript](https://img.shields.io/badge/%3C%2F%3E-TypeScript-%230074c1.svg)](https://www.typescriptlang.org/)
|
5
|
+
|
6
|
+
`foundation-broadcast-channel` provides a strongly typed [Broadcast_Channel](https://developer.mozilla.org/en-US/docs/Web/API/Broadcast_Channel_API) API and related utilities.
|
7
|
+
The system uses the same event typing we use in our stores, where the key is the event, and the value is the details or payload if any.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
To enable this module in your application, follow the steps below.
|
12
|
+
|
13
|
+
1. Add `@genesislcap/foundation-broadcast-channel` as a dependency in your `package.json` file.
|
14
|
+
|
15
|
+
_Note whenever you change the dependencies of your project, ensure you run the `$ npm run bootstrap` command again, or npm i, depending on your setup. You can find more information in the [package.json basics](https://learn.genesis.global/secure/web/basics/package-json-basics/) page._
|
16
|
+
|
17
|
+
```json
|
18
|
+
{
|
19
|
+
"dependencies": {
|
20
|
+
"@genesislcap/foundation-broadcast-channel": "latest",
|
21
|
+
...
|
22
|
+
}
|
23
|
+
}
|
24
|
+
```
|
25
|
+
|
26
|
+
## Usage
|
27
|
+
|
28
|
+
Create a typed channel for your application or package, likely in a config.ts file.
|
29
|
+
|
30
|
+
```ts
|
31
|
+
import { registerTypedBroadcastChannel, TypedBroadcastChannel } from '@genesislcap/foundation-broadcast-channel';
|
32
|
+
|
33
|
+
// Define or import the channel event / message map
|
34
|
+
export type GenesisResourcesEvents = {
|
35
|
+
'resources-loaded': ResourceItem[];
|
36
|
+
'resources-unloaded': void;
|
37
|
+
};
|
38
|
+
|
39
|
+
// Define the interface
|
40
|
+
export interface GenesisResourcesChannel extends TypedBroadcastChannel<GenesisResourcesEvents> {}
|
41
|
+
|
42
|
+
// Define the DI key
|
43
|
+
export const GenesisResourcesChannel = registerTypedBroadcastChannel<GenesisResourcesEvents>(GenesisResourcesChannelId);
|
44
|
+
```
|
45
|
+
|
46
|
+
Inject the channel into the actors you wish to post broadcast messages from.
|
47
|
+
|
48
|
+
```ts
|
49
|
+
import { GenesisResourcesChannel } from '@genesislcap/foundation-comms';
|
50
|
+
|
51
|
+
constructor(@GenesisResourcesChannel protected channel: GenesisResourcesChannel) {}
|
52
|
+
|
53
|
+
// Broadcast strongly typed messages
|
54
|
+
this.channel.postMessage('resources-loaded', this.resources);
|
55
|
+
```
|
56
|
+
|
57
|
+
Inject the channel into the actors you wish to recieve broadcast messages from.
|
58
|
+
|
59
|
+
```ts
|
60
|
+
import { GenesisResourcesChannel } from '@genesislcap/foundation-comms';
|
61
|
+
|
62
|
+
@GenesisResourcesChannel protected channel: GenesisResourcesChannel;
|
63
|
+
|
64
|
+
// Handle broadcasted messages and use the provided type narrowing API
|
65
|
+
this.channel.onmessage = (ev) => {
|
66
|
+
if (this.channel.isMessageType('resources-loaded', ev)) {
|
67
|
+
// Typescript now knows what detail is
|
68
|
+
if (!ev.data.detail.length) {
|
69
|
+
throw Error('No backend resources available');
|
70
|
+
}
|
71
|
+
}
|
72
|
+
};
|
73
|
+
|
74
|
+
// Close the channel when finished, perhaps on disconnectedCallback
|
75
|
+
this.channel.close();
|
76
|
+
```
|
77
|
+
|
78
|
+
Note that injected channels are `transient` by design.
|
79
|
+
|
80
|
+
## [API Docs](./docs/api/index.md)
|
81
|
+
|
82
|
+
## License
|
83
|
+
|
84
|
+
Note: this project provides front-end dependencies and uses licensed components listed in the next section; thus, licenses for those components are required during development. Contact [Genesis Global](https://genesis.global/contact-us/) for more details.
|
85
|
+
|
86
|
+
### Licensed components
|
87
|
+
Genesis low-code platform
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import { TypedBroadcastChannel } from '../broadcast-channel';
|
2
|
+
import { TestEvents } from './types';
|
3
|
+
/**
|
4
|
+
* @internal
|
5
|
+
*/
|
6
|
+
export interface TestChannel extends TypedBroadcastChannel<TestEvents> {
|
7
|
+
}
|
8
|
+
/**
|
9
|
+
* @internal
|
10
|
+
*/
|
11
|
+
export declare const TestChannel: import("@microsoft/fast-foundation").InterfaceSymbol<TypedBroadcastChannel<TestEvents>>;
|
12
|
+
//# sourceMappingURL=config.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/__test__/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiC,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAC5F,OAAO,EAAiB,UAAU,EAAE,MAAM,SAAS,CAAC;AAEpD;;GAEG;AACH,MAAM,WAAW,WAAY,SAAQ,qBAAqB,CAAC,UAAU,CAAC;CAAG;AAEzE;;GAEG;AAEH,eAAO,MAAM,WAAW,yFAA2D,CAAC"}
|
@@ -0,0 +1,59 @@
|
|
1
|
+
import { FASTElement } from '@microsoft/fast-element';
|
2
|
+
import { TestChannel } from './config';
|
3
|
+
import { TestEntity } from './types';
|
4
|
+
/**
|
5
|
+
* @internal
|
6
|
+
*/
|
7
|
+
export declare class SubscriberTestElement extends FASTElement {
|
8
|
+
/**
|
9
|
+
* @public
|
10
|
+
*/
|
11
|
+
channel: TestChannel;
|
12
|
+
/**
|
13
|
+
* @public
|
14
|
+
*/
|
15
|
+
entities: TestEntity[];
|
16
|
+
/**
|
17
|
+
* @public
|
18
|
+
*/
|
19
|
+
connectedCallback(): void;
|
20
|
+
/**
|
21
|
+
* @public
|
22
|
+
*/
|
23
|
+
disconnectedCallback(): void;
|
24
|
+
}
|
25
|
+
/**
|
26
|
+
* @internal
|
27
|
+
*/
|
28
|
+
export declare class BroadcasterTestElement extends FASTElement {
|
29
|
+
/**
|
30
|
+
* @public
|
31
|
+
*/
|
32
|
+
channel: TestChannel;
|
33
|
+
/**
|
34
|
+
* @public
|
35
|
+
*/
|
36
|
+
postLoadedMessage(detail: TestEntity[]): void;
|
37
|
+
/**
|
38
|
+
* @public
|
39
|
+
*/
|
40
|
+
postUnloadedMessage(): void;
|
41
|
+
/**
|
42
|
+
* @public
|
43
|
+
*/
|
44
|
+
disconnectedCallback(): void;
|
45
|
+
}
|
46
|
+
/**
|
47
|
+
* @internal
|
48
|
+
*/
|
49
|
+
export declare class TestElement extends FASTElement {
|
50
|
+
/**
|
51
|
+
* @public
|
52
|
+
*/
|
53
|
+
broadcaster: BroadcasterTestElement;
|
54
|
+
/**
|
55
|
+
* @public
|
56
|
+
*/
|
57
|
+
subscriber: SubscriberTestElement;
|
58
|
+
}
|
59
|
+
//# sourceMappingURL=elements.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"elements.d.ts","sourceRoot":"","sources":["../../../src/__test__/elements.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,WAAW,EAAyB,MAAM,yBAAyB,CAAC;AAC5F,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAErC;;GAEG;AACH,qBAMa,qBAAsB,SAAQ,WAAW;IACpD;;OAEG;IACU,OAAO,EAAE,WAAW,CAAC;IAElC;;OAEG;IACS,QAAQ,EAAE,UAAU,EAAE,CAAC;IAEnC;;OAEG;IACH,iBAAiB;IAkBjB;;OAEG;IACH,oBAAoB;CAIrB;AAED;;GAEG;AACH,qBAMa,sBAAuB,SAAQ,WAAW;IACrD;;OAEG;IACU,OAAO,EAAE,WAAW,CAAC;IAElC;;OAEG;IACH,iBAAiB,CAAC,MAAM,EAAE,UAAU,EAAE;IAItC;;OAEG;IACH,mBAAmB;IAInB;;OAEG;IACH,oBAAoB;CAIrB;AAED;;GAEG;AACH,qBASa,WAAY,SAAQ,WAAW;IAC1C;;OAEG;IACS,WAAW,EAAE,sBAAsB,CAAC;IAChD;;OAEG;IACS,UAAU,EAAE,qBAAqB,CAAC;CAC/C"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/__test__/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC"}
|
@@ -0,0 +1,28 @@
|
|
1
|
+
import { TypedMessageEvent } from '../broadcast-channel';
|
2
|
+
/**
|
3
|
+
* @internal
|
4
|
+
*/
|
5
|
+
export declare const TestChannelId = "test-channel";
|
6
|
+
/**
|
7
|
+
* @internal
|
8
|
+
*/
|
9
|
+
export type TestEntity = {
|
10
|
+
label: string;
|
11
|
+
quantity?: number;
|
12
|
+
};
|
13
|
+
/**
|
14
|
+
* @internal
|
15
|
+
*/
|
16
|
+
export type TestEvents = {
|
17
|
+
loaded: TestEntity[];
|
18
|
+
unloaded: void;
|
19
|
+
};
|
20
|
+
/**
|
21
|
+
* @internal
|
22
|
+
*/
|
23
|
+
export declare const mockLoadedEvent: (detail?: TestEntity[]) => TypedMessageEvent<TestEvents, "loaded">;
|
24
|
+
/**
|
25
|
+
* @internal
|
26
|
+
*/
|
27
|
+
export declare const mockUnloadedEvent: () => TypedMessageEvent<TestEvents, "unloaded">;
|
28
|
+
//# sourceMappingURL=types.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/__test__/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAEzD;;GAEG;AACH,eAAO,MAAM,aAAa,iBAAiB,CAAC;AAE5C;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG;IACvB,MAAM,EAAE,UAAU,EAAE,CAAC;IACrB,QAAQ,EAAE,IAAI,CAAC;CAChB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,eAAe,YAAY,UAAU,EAAE,4CAOP,CAAC;AAG9C;;GAEG;AACH,eAAO,MAAM,iBAAiB,iDAKiB,CAAC"}
|
@@ -0,0 +1,123 @@
|
|
1
|
+
import { EventDetailMap } from '@genesislcap/foundation-events';
|
2
|
+
/**
|
3
|
+
* A TypedMessageEvent for BroadcastChannel transmission.
|
4
|
+
* @public
|
5
|
+
*/
|
6
|
+
export type TypedMessageEvent<TEventDetailMap extends EventDetailMap, T extends keyof TEventDetailMap> = MessageEvent<{
|
7
|
+
type: T;
|
8
|
+
detail: TEventDetailMap[T];
|
9
|
+
}>;
|
10
|
+
/**
|
11
|
+
* @internal
|
12
|
+
*/
|
13
|
+
type PostMessage<TEventDetailMap extends EventDetailMap> = <K extends keyof TEventDetailMap>(...args: TEventDetailMap[K] extends void ? [type: K] : [type: K, detail: TEventDetailMap[K]]) => void;
|
14
|
+
/**
|
15
|
+
* @internal
|
16
|
+
*/
|
17
|
+
type OnMessage<TEventDetailMap extends EventDetailMap> = ((this: BroadcastChannel, ev: TypedMessageEvent<TEventDetailMap, keyof TEventDetailMap>) => any) | null;
|
18
|
+
/**
|
19
|
+
* @internal
|
20
|
+
*/
|
21
|
+
type OnMessageError<TEventDetailMap extends EventDetailMap> = OnMessage<TEventDetailMap>;
|
22
|
+
/**
|
23
|
+
* A TypedBroadcastChannel for sending and receiving typed messages based on {@link @genesislcap/foundation-events#EventDetailMap} input.
|
24
|
+
*
|
25
|
+
* @example
|
26
|
+
* ```ts
|
27
|
+
* export type GenesisResourcesEvents = {
|
28
|
+
* 'resources-loaded': ResourceItem[];
|
29
|
+
* 'resources-unloaded': void;
|
30
|
+
* };
|
31
|
+
* ...
|
32
|
+
* protected channel: TypedBroadcastChannel<GenesisResourcesEvents>;
|
33
|
+
* ```
|
34
|
+
*
|
35
|
+
* See the {@link registerTypedBroadcastChannel} and {@link createTypedBroadcastChannel} APIs below.
|
36
|
+
*
|
37
|
+
* @public
|
38
|
+
*/
|
39
|
+
export interface TypedBroadcastChannel<TEventDetailMap extends EventDetailMap> extends Omit<BroadcastChannel, 'postMessage' | 'onmessage' | 'onmessageerror'> {
|
40
|
+
/**
|
41
|
+
* Post strongly typed messages.
|
42
|
+
* @example
|
43
|
+
* The event detail map provided to the channel on creation will provide `postMessage` typing.
|
44
|
+
* ```ts
|
45
|
+
* type GenesisResourcesEvents = {
|
46
|
+
* 'resources-loaded': ResourceItem[];
|
47
|
+
* 'resources-unloaded': void;
|
48
|
+
* };
|
49
|
+
* ...
|
50
|
+
* channel.postMessage('resources-loaded', this.resources); // ok, as this.resources is an array of ResourceItems.
|
51
|
+
* channel.postMessage('resources-loaded'); // not ok, as an array is expected for this message type.
|
52
|
+
* channel.postMessage('resources-unloaded'); // ok, as this message type maps to void for its detail.
|
53
|
+
* ```
|
54
|
+
*/
|
55
|
+
postMessage: PostMessage<TEventDetailMap>;
|
56
|
+
/**
|
57
|
+
* On message handler.
|
58
|
+
* @example Use the `channel.isMessageType` method to narrow based on message types.
|
59
|
+
* ```ts
|
60
|
+
* import { GenesisResourcesChannel } from '@genesislcap/foundation-comms';
|
61
|
+
* ...
|
62
|
+
* @GenesisResourcesChannel protected channel: GenesisResourcesChannel;
|
63
|
+
* ...
|
64
|
+
* this.channel.onmessage = (ev) => {
|
65
|
+
* if (this.channel.isMessageType('resources-loaded', ev)) {
|
66
|
+
* if (!ev.data.detail.length) {
|
67
|
+
* throw Error('No backend resources available');
|
68
|
+
* }
|
69
|
+
* }
|
70
|
+
* };
|
71
|
+
* ...
|
72
|
+
* this.channel.close();
|
73
|
+
* ```
|
74
|
+
*/
|
75
|
+
onmessage: OnMessage<TEventDetailMap>;
|
76
|
+
onmessageerror: OnMessageError<TEventDetailMap>;
|
77
|
+
/**
|
78
|
+
* A type predicate function to narrow down message events based on their 'type' property.
|
79
|
+
* @param type - The message type.
|
80
|
+
* @param event - The message event.
|
81
|
+
*/
|
82
|
+
isMessageType<T extends keyof TEventDetailMap>(type: T, event: TypedMessageEvent<TEventDetailMap, keyof TEventDetailMap>): event is TypedMessageEvent<TEventDetailMap, T>;
|
83
|
+
}
|
84
|
+
/**
|
85
|
+
* Default TypedBroadcastChannel implementation.
|
86
|
+
* @public
|
87
|
+
*/
|
88
|
+
export declare class DefaultTypedBroadcastChannel<TEventDetailMap extends EventDetailMap> extends BroadcastChannel implements TypedBroadcastChannel<TEventDetailMap> {
|
89
|
+
/** {@inheritDoc TypedBroadcastChannel.postMessage} */
|
90
|
+
postMessage: PostMessage<TEventDetailMap>;
|
91
|
+
/** {@inheritDoc TypedBroadcastChannel.isMessageType} */
|
92
|
+
isMessageType: <T extends keyof TEventDetailMap>(type: T, event: TypedMessageEvent<TEventDetailMap, keyof TEventDetailMap>) => event is TypedMessageEvent<TEventDetailMap, T>;
|
93
|
+
}
|
94
|
+
/**
|
95
|
+
* Creates a dependency injection key for the broadcast channel being registered which is lazily created when injected.
|
96
|
+
* @example In a package's config.ts
|
97
|
+
* ```ts
|
98
|
+
* export interface GenesisResourcesChannel extends TypedBroadcastChannel<GenesisResourcesEvents> {}
|
99
|
+
* ...
|
100
|
+
* export const GenesisResourcesChannel = registerTypedBroadcastChannel<GenesisResourcesEvents>(GenesisResourcesChannelId);
|
101
|
+
* ```
|
102
|
+
* @param name - The channel name.
|
103
|
+
* @returns The created key.
|
104
|
+
* @public
|
105
|
+
*/
|
106
|
+
export declare const registerTypedBroadcastChannel: <TEventDetailMap extends EventDetailMap>(name: string) => import("@microsoft/fast-foundation").InterfaceSymbol<TypedBroadcastChannel<TEventDetailMap>>;
|
107
|
+
/**
|
108
|
+
* Creates a strongly typed broadcast channel.
|
109
|
+
*
|
110
|
+
* @remarks
|
111
|
+
* `registerTypedBroadcastChannel` may be preferred, as it will create and register the channel in the DI.
|
112
|
+
*
|
113
|
+
* @example
|
114
|
+
* ```ts
|
115
|
+
* const channel = createTypedBroadcastChannel<GenesisResourcesEvents>(GenesisResourcesChannelId);
|
116
|
+
* ```
|
117
|
+
* @param name - The channel name.
|
118
|
+
* @returns The created TypedBroadcastChannel.
|
119
|
+
* @public
|
120
|
+
*/
|
121
|
+
export declare const createTypedBroadcastChannel: <TEventDetailMap extends EventDetailMap>(name: string) => DefaultTypedBroadcastChannel<TEventDetailMap>;
|
122
|
+
export {};
|
123
|
+
//# sourceMappingURL=broadcast-channel.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"broadcast-channel.d.ts","sourceRoot":"","sources":["../../../src/broadcast-channel/broadcast-channel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAGhE;;;GAGG;AACH,MAAM,MAAM,iBAAiB,CAC3B,eAAe,SAAS,cAAc,EACtC,CAAC,SAAS,MAAM,eAAe,IAC7B,YAAY,CAAC;IACf,IAAI,EAAE,CAAC,CAAC;IACR,MAAM,EAAE,eAAe,CAAC,CAAC,CAAC,CAAC;CAC5B,CAAC,CAAC;AAEH;;GAEG;AACH,KAAK,WAAW,CAAC,eAAe,SAAS,cAAc,IAAI,CAAC,CAAC,SAAS,MAAM,eAAe,EACzF,GAAG,IAAI,EAAE,eAAe,CAAC,CAAC,CAAC,SAAS,IAAI,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,EAAE,MAAM,EAAE,eAAe,CAAC,CAAC,CAAC,CAAC,KACzF,IAAI,CAAC;AAEV;;GAEG;AACH,KAAK,SAAS,CAAC,eAAe,SAAS,cAAc,IACjD,CAAC,CAAC,IAAI,EAAE,gBAAgB,EAAE,EAAE,EAAE,iBAAiB,CAAC,eAAe,EAAE,MAAM,eAAe,CAAC,KAAK,GAAG,CAAC,GAChG,IAAI,CAAC;AAET;;GAEG;AACH,KAAK,cAAc,CAAC,eAAe,SAAS,cAAc,IAAI,SAAS,CAAC,eAAe,CAAC,CAAC;AAEzF;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,WAAW,qBAAqB,CAAC,eAAe,SAAS,cAAc,CAC3E,SAAQ,IAAI,CAAC,gBAAgB,EAAE,aAAa,GAAG,WAAW,GAAG,gBAAgB,CAAC;IAC9E;;;;;;;;;;;;;;OAcG;IACH,WAAW,EAAE,WAAW,CAAC,eAAe,CAAC,CAAC;IAC1C;;;;;;;;;;;;;;;;;;OAkBG;IACH,SAAS,EAAE,SAAS,CAAC,eAAe,CAAC,CAAC;IACtC,cAAc,EAAE,cAAc,CAAC,eAAe,CAAC,CAAC;IAChD;;;;OAIG;IACH,aAAa,CAAC,CAAC,SAAS,MAAM,eAAe,EAC3C,IAAI,EAAE,CAAC,EACP,KAAK,EAAE,iBAAiB,CAAC,eAAe,EAAE,MAAM,eAAe,CAAC,GAC/D,KAAK,IAAI,iBAAiB,CAAC,eAAe,EAAE,CAAC,CAAC,CAAC;CACnD;AAED;;;GAGG;AACH,qBAAa,4BAA4B,CAAC,eAAe,SAAS,cAAc,CAC9E,SAAQ,gBACR,YAAW,qBAAqB,CAAC,eAAe,CAAC;IAEjD,sDAAsD;IAEtD,WAAW,EAAE,WAAW,CAAC,eAAe,CAAC,CAMvC;IACF,wDAAwD;IACxD,aAAa,oDAEJ,kBAAkB,eAAe,EAAE,MAAM,eAAe,CAAC,oDAGhE;CACH;AAED;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,6BAA6B,iDAClC,MAAM,iGAQb,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,2BAA2B,iDAChC,MAAM,kDAGb,CAAC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/broadcast-channel/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,SAAS,CAAC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
//# sourceMappingURL=index.federated.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.federated.d.ts","sourceRoot":"","sources":["../../src/index.federated.ts"],"names":[],"mappings":""}
|
@@ -0,0 +1,11 @@
|
|
1
|
+
// This file is read by tools that parse documentation comments conforming to the TSDoc standard.
|
2
|
+
// It should be published with your NPM package. It should not be tracked by Git.
|
3
|
+
{
|
4
|
+
"tsdocVersion": "0.12",
|
5
|
+
"toolPackages": [
|
6
|
+
{
|
7
|
+
"packageName": "@microsoft/api-extractor",
|
8
|
+
"packageVersion": "7.34.9"
|
9
|
+
}
|
10
|
+
]
|
11
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../../src/utils/logger.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,eAAO,MAAM,MAAM,iDAA+C,CAAC"}
|
@@ -0,0 +1,108 @@
|
|
1
|
+
import { __decorate } from "tslib";
|
2
|
+
import { customElement, FASTElement, html, observable, ref } from '@microsoft/fast-element';
|
3
|
+
import { TestChannel } from './config';
|
4
|
+
/**
|
5
|
+
* @internal
|
6
|
+
*/
|
7
|
+
let SubscriberTestElement = class SubscriberTestElement extends FASTElement {
|
8
|
+
/**
|
9
|
+
* @public
|
10
|
+
*/
|
11
|
+
connectedCallback() {
|
12
|
+
super.connectedCallback();
|
13
|
+
this.channel.onmessage = (ev) => {
|
14
|
+
if (this.channel.isMessageType('loaded', ev)) {
|
15
|
+
const entities = ev.data.detail;
|
16
|
+
if (!entities.length) {
|
17
|
+
throw Error('No test entities available');
|
18
|
+
}
|
19
|
+
this.entities = entities;
|
20
|
+
return;
|
21
|
+
}
|
22
|
+
if (this.channel.isMessageType('unloaded', ev)) {
|
23
|
+
this.entities = undefined;
|
24
|
+
}
|
25
|
+
};
|
26
|
+
}
|
27
|
+
/**
|
28
|
+
* @public
|
29
|
+
*/
|
30
|
+
disconnectedCallback() {
|
31
|
+
super.disconnectedCallback();
|
32
|
+
this.channel.close();
|
33
|
+
}
|
34
|
+
};
|
35
|
+
__decorate([
|
36
|
+
TestChannel
|
37
|
+
], SubscriberTestElement.prototype, "channel", void 0);
|
38
|
+
__decorate([
|
39
|
+
observable
|
40
|
+
], SubscriberTestElement.prototype, "entities", void 0);
|
41
|
+
SubscriberTestElement = __decorate([
|
42
|
+
customElement({
|
43
|
+
name: 'subscriber-test-element',
|
44
|
+
template: html `
|
45
|
+
<template></template>
|
46
|
+
`,
|
47
|
+
})
|
48
|
+
], SubscriberTestElement);
|
49
|
+
export { SubscriberTestElement };
|
50
|
+
/**
|
51
|
+
* @internal
|
52
|
+
*/
|
53
|
+
let BroadcasterTestElement = class BroadcasterTestElement extends FASTElement {
|
54
|
+
/**
|
55
|
+
* @public
|
56
|
+
*/
|
57
|
+
postLoadedMessage(detail) {
|
58
|
+
this.channel.postMessage('loaded', detail);
|
59
|
+
}
|
60
|
+
/**
|
61
|
+
* @public
|
62
|
+
*/
|
63
|
+
postUnloadedMessage() {
|
64
|
+
this.channel.postMessage('unloaded');
|
65
|
+
}
|
66
|
+
/**
|
67
|
+
* @public
|
68
|
+
*/
|
69
|
+
disconnectedCallback() {
|
70
|
+
super.disconnectedCallback();
|
71
|
+
this.channel.close();
|
72
|
+
}
|
73
|
+
};
|
74
|
+
__decorate([
|
75
|
+
TestChannel
|
76
|
+
], BroadcasterTestElement.prototype, "channel", void 0);
|
77
|
+
BroadcasterTestElement = __decorate([
|
78
|
+
customElement({
|
79
|
+
name: 'broadcaster-test-element',
|
80
|
+
template: html `
|
81
|
+
<template></template>
|
82
|
+
`,
|
83
|
+
})
|
84
|
+
], BroadcasterTestElement);
|
85
|
+
export { BroadcasterTestElement };
|
86
|
+
/**
|
87
|
+
* @internal
|
88
|
+
*/
|
89
|
+
let TestElement = class TestElement extends FASTElement {
|
90
|
+
};
|
91
|
+
__decorate([
|
92
|
+
observable
|
93
|
+
], TestElement.prototype, "broadcaster", void 0);
|
94
|
+
__decorate([
|
95
|
+
observable
|
96
|
+
], TestElement.prototype, "subscriber", void 0);
|
97
|
+
TestElement = __decorate([
|
98
|
+
customElement({
|
99
|
+
name: 'broadcast-channel-test-element',
|
100
|
+
template: html `
|
101
|
+
<template>
|
102
|
+
<broadcaster-test-element ${ref('broadcaster')}></broadcaster-test-element>
|
103
|
+
<subscriber-test-element ${ref('subscriber')}></subscriber-test-element>
|
104
|
+
</template>
|
105
|
+
`,
|
106
|
+
})
|
107
|
+
], TestElement);
|
108
|
+
export { TestElement };
|
@@ -0,0 +1,24 @@
|
|
1
|
+
/**
|
2
|
+
* @internal
|
3
|
+
*/
|
4
|
+
export const TestChannelId = 'test-channel';
|
5
|
+
/**
|
6
|
+
* @internal
|
7
|
+
*/
|
8
|
+
export const mockLoadedEvent = (detail = [{
|
9
|
+
label: 'foo'
|
10
|
+
}]) => ({
|
11
|
+
data: {
|
12
|
+
type: 'loaded',
|
13
|
+
detail,
|
14
|
+
}
|
15
|
+
});
|
16
|
+
/**
|
17
|
+
* @internal
|
18
|
+
*/
|
19
|
+
export const mockUnloadedEvent = () => ({
|
20
|
+
data: {
|
21
|
+
type: 'unloaded',
|
22
|
+
detail: undefined,
|
23
|
+
}
|
24
|
+
});
|
@@ -0,0 +1,61 @@
|
|
1
|
+
import { DI } from '@microsoft/fast-foundation';
|
2
|
+
/**
|
3
|
+
* Default TypedBroadcastChannel implementation.
|
4
|
+
* @public
|
5
|
+
*/
|
6
|
+
export class DefaultTypedBroadcastChannel extends BroadcastChannel {
|
7
|
+
constructor() {
|
8
|
+
super(...arguments);
|
9
|
+
/** {@inheritDoc TypedBroadcastChannel.postMessage} */
|
10
|
+
// @ts-ignore
|
11
|
+
this.postMessage = (...args) => {
|
12
|
+
const [type, detail] = args;
|
13
|
+
super.postMessage({
|
14
|
+
type,
|
15
|
+
detail,
|
16
|
+
});
|
17
|
+
};
|
18
|
+
/** {@inheritDoc TypedBroadcastChannel.isMessageType} */
|
19
|
+
this.isMessageType = (type, event) => {
|
20
|
+
var _a;
|
21
|
+
return ((_a = event.data) === null || _a === void 0 ? void 0 : _a.type) === type;
|
22
|
+
};
|
23
|
+
}
|
24
|
+
}
|
25
|
+
/**
|
26
|
+
* Creates a dependency injection key for the broadcast channel being registered which is lazily created when injected.
|
27
|
+
* @example In a package's config.ts
|
28
|
+
* ```ts
|
29
|
+
* export interface GenesisResourcesChannel extends TypedBroadcastChannel<GenesisResourcesEvents> {}
|
30
|
+
* ...
|
31
|
+
* export const GenesisResourcesChannel = registerTypedBroadcastChannel<GenesisResourcesEvents>(GenesisResourcesChannelId);
|
32
|
+
* ```
|
33
|
+
* @param name - The channel name.
|
34
|
+
* @returns The created key.
|
35
|
+
* @public
|
36
|
+
*/
|
37
|
+
export const registerTypedBroadcastChannel = (name) => {
|
38
|
+
class Value extends DefaultTypedBroadcastChannel {
|
39
|
+
constructor() {
|
40
|
+
super(name);
|
41
|
+
}
|
42
|
+
}
|
43
|
+
return DI.createInterface((x) => x.transient(Value));
|
44
|
+
};
|
45
|
+
/**
|
46
|
+
* Creates a strongly typed broadcast channel.
|
47
|
+
*
|
48
|
+
* @remarks
|
49
|
+
* `registerTypedBroadcastChannel` may be preferred, as it will create and register the channel in the DI.
|
50
|
+
*
|
51
|
+
* @example
|
52
|
+
* ```ts
|
53
|
+
* const channel = createTypedBroadcastChannel<GenesisResourcesEvents>(GenesisResourcesChannelId);
|
54
|
+
* ```
|
55
|
+
* @param name - The channel name.
|
56
|
+
* @returns The created TypedBroadcastChannel.
|
57
|
+
* @public
|
58
|
+
*/
|
59
|
+
export const createTypedBroadcastChannel = (name) => {
|
60
|
+
return new DefaultTypedBroadcastChannel(name);
|
61
|
+
};
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './broadcast-channel';
|
@@ -0,0 +1 @@
|
|
1
|
+
import('./index');
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './logger';
|