@genesislcap/foundation-events 14.241.0 → 14.242.0

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.
@@ -0,0 +1,56 @@
1
+ import { EmitOptions, EventDetailMap } from '../types';
2
+ /**
3
+ * emitter function.
4
+ *
5
+ * This is the functional equivalent of the strongly typed `.emit` function created with the {@link EventEmitter} mixin.
6
+ *
7
+ * @public
8
+ *
9
+ * @remarks
10
+ * This is useful if you need to emit an event from an arbitrary location. For example, if you want to emit an event
11
+ * from a button on a custom grid cell renderer you can use this to get strong typing rather than having to dependency
12
+ * inject a reference to the class which uses the {@link EventEmitter} mixin multiple levels into the renderer.
13
+ *
14
+ * @example
15
+ * Apply mixin to the base {@link @microsoft/fast-element#FASTElement | FASTElement}
16
+ *
17
+ * # Import
18
+ * ```ts
19
+ * import { emitter, SomeSystemLevelEventDetailMap } from '@genesislcap/foundation-events';
20
+ * import { StoreEventDetailMap, TradeEntryEventDetailMap } from '../store'; // < custom app level event maps
21
+ * ```
22
+ *
23
+ * # Create event map
24
+ * ```ts
25
+ * type EventMap = SomeSystemLevelEventDetailMap & StoreEventDetailMap & TradeEntryEventDetailMap;
26
+ * ```
27
+ *
28
+ * # Use the functional emitter. For example in a custom button action on a grid cell
29
+ * ```ts
30
+ * const customAction = {
31
+ * name: `<rapid-button name="download" size="lg"></rapid-button>`
32
+ * callback: (button: HTMLElement, data: RowData) =>
33
+ * emitter<EventMap>().emit(
34
+ * button,
35
+ * 'some-allowed-event',
36
+ * { foo: 'expected data structure' },
37
+ * ),
38
+ * }
39
+ * ```
40
+ *
41
+ * @privateRemarks
42
+ * The reason it's a function which returns an object with another function is to create the best developer ergonomics
43
+ * accounting for TypeScript. This setup allows you to only set one type parameter to control the strong typing, if we
44
+ * were to add it all onto the same function you'd either have to specify multiple type parameters (repeating yourself)
45
+ * or if we used implicits it wouldn't type check the payload against the type correctly.
46
+ *
47
+ * @typeParam TEventDetailMap - The {@link EventDetailMap}.
48
+ * @param orign - the `HTMLElement` to dispatch the event from. Ensure this correctly relates to the component you've attatched the corresponding event listener to.
49
+ * @param type - the key in `TEventDetailMap` which is the event name from the detail map
50
+ * @param detail - *optional* param `TEventDetailMap[K]` which is the payload corresponding to the event `type`
51
+ * @param options - *optional* param {@link EmitOptions} to set event options. Default `{ composed: true, bubbles: true, cancelable: true, }`
52
+ */
53
+ export declare const emitter: <TEventDetailMap extends EventDetailMap>() => {
54
+ emit: <K extends keyof TEventDetailMap>(...args: TEventDetailMap[K] extends void ? [origin: HTMLElement, type: K, options?: EmitOptions] : [origin: HTMLElement, type: K, detail: TEventDetailMap[K], options?: EmitOptions]) => void;
55
+ };
56
+ //# sourceMappingURL=emitterFunction.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"emitterFunction.d.ts","sourceRoot":"","sources":["../../../src/eventEmitter/emitterFunction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,cAAc,EAAiB,MAAM,UAAU,CAAC;AAEtE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AACH,eAAO,MAAM,OAAO;qOAKf,IAAI;CAuBP,CAAC"}
@@ -1,3 +1,4 @@
1
+ export * from './emitterFunction';
1
2
  export * from './eventEmitterDI';
2
3
  export * from './eventEmitterMixin';
3
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/eventEmitter/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/eventEmitter/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC"}
@@ -42,6 +42,10 @@ export interface TypedEmitter<TEventDetailMap extends EventDetailMap> {
42
42
  export type CustomEventMap<TEventDetailMap extends EventDetailMap> = {
43
43
  [K in keyof TEventDetailMap]: CustomEvent<TEventDetailMap[K]>;
44
44
  };
45
+ /**
46
+ * @public
47
+ */
48
+ export declare const isEmitOptions: (candidate: EmitOptions | any) => boolean;
45
49
  /**
46
50
  * @public
47
51
  */
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAGhG;;;;GAIG;AACH,MAAM,MAAM,kBAAkB,CAAC,KAAK,SAAS,WAAW,IAAI,QAAQ,MAAM,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,KAAK,CAAC;AAEnG;;;GAGG;AACH,MAAM,MAAM,8BAA8B,GAAG,aAAa,CAAC,WAAW,GAAG,WAAW,CAAC,CAAC;AAEtF;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,IAAI,CAAC,eAAe,EAAE,QAAQ,CAAC,CAAC;AAE1D;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,OAAO,GAAG,IAAI,CAAC;AAExC;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG,CAAC,MAAM,EAAE,EAAE,GAAG,SAAS,EAAE,WAAW,GAAG,SAAS,CAAC,CAAC;AAEzE;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,WAAW,CAAC;AAErC;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAErD;;GAEG;AACH,MAAM,WAAW,YAAY,CAAC,eAAe,SAAS,cAAc;IAClE,KAAK,CAAC,CAAC,SAAS,MAAM,eAAe,GAAG,MAAM,EAC5C,GAAG,IAAI,EAAE,eAAe,CAAC,CAAC,CAAC,SAAS,IAAI,GACpC,CAAC,IAAI,EAAE,CAAC,EAAE,OAAO,CAAC,EAAE,WAAW,CA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,KAAG,OAGtB,CAAC;AAExC;;GAEG;AACH,eAAO,MAAM,eAAe,YAAa,OAAO,EAAE,aAWjD,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,WAAW,6BAA8B,gBAAgB,8BAC9B,CAAC;AAEzC;;GAEG;AACH,KAAK,WAAW,GAAG,CAAC,GAAG,EAAE,gBAAgB,KAAK,GAAG,CAAC;AAElD;;GAEG;AACH,eAAO,MAAM,WAAW,EAAE,WAAwE,CAAC;AAEnG;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,aAAa,EAAE,WACO,CAAC;AAEpC;;GAEG;AACH,eAAO,MAAM,wBAAwB,EAAE,WACmB,CAAC;AAE3D;;GAEG;AACH,MAAM,MAAM,YAAY,CAAC,CAAC,EAAE,CAAC,IAAI;KAAG,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,KAAK;CAAE,CAAC,MAAM,CAAC,CAAC,CAAC;AAW3F;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,kBAAkB,qHAnBwC,WAAW,KAAG,OAoBlC,CAAC;AAEpD;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,mBAAmB,qHArCuC,WAAW,KAAG,OAsCrB,CAAC"}
@@ -0,0 +1,76 @@
1
+ import { isEmitOptions } from '../types';
2
+ /**
3
+ * emitter function.
4
+ *
5
+ * This is the functional equivalent of the strongly typed `.emit` function created with the {@link EventEmitter} mixin.
6
+ *
7
+ * @public
8
+ *
9
+ * @remarks
10
+ * This is useful if you need to emit an event from an arbitrary location. For example, if you want to emit an event
11
+ * from a button on a custom grid cell renderer you can use this to get strong typing rather than having to dependency
12
+ * inject a reference to the class which uses the {@link EventEmitter} mixin multiple levels into the renderer.
13
+ *
14
+ * @example
15
+ * Apply mixin to the base {@link @microsoft/fast-element#FASTElement | FASTElement}
16
+ *
17
+ * # Import
18
+ * ```ts
19
+ * import { emitter, SomeSystemLevelEventDetailMap } from '@genesislcap/foundation-events';
20
+ * import { StoreEventDetailMap, TradeEntryEventDetailMap } from '../store'; // < custom app level event maps
21
+ * ```
22
+ *
23
+ * # Create event map
24
+ * ```ts
25
+ * type EventMap = SomeSystemLevelEventDetailMap & StoreEventDetailMap & TradeEntryEventDetailMap;
26
+ * ```
27
+ *
28
+ * # Use the functional emitter. For example in a custom button action on a grid cell
29
+ * ```ts
30
+ * const customAction = {
31
+ * name: `<rapid-button name="download" size="lg"></rapid-button>`
32
+ * callback: (button: HTMLElement, data: RowData) =>
33
+ * emitter<EventMap>().emit(
34
+ * button,
35
+ * 'some-allowed-event',
36
+ * { foo: 'expected data structure' },
37
+ * ),
38
+ * }
39
+ * ```
40
+ *
41
+ * @privateRemarks
42
+ * The reason it's a function which returns an object with another function is to create the best developer ergonomics
43
+ * accounting for TypeScript. This setup allows you to only set one type parameter to control the strong typing, if we
44
+ * were to add it all onto the same function you'd either have to specify multiple type parameters (repeating yourself)
45
+ * or if we used implicits it wouldn't type check the payload against the type correctly.
46
+ *
47
+ * @typeParam TEventDetailMap - The {@link EventDetailMap}.
48
+ * @param orign - the `HTMLElement` to dispatch the event from. Ensure this correctly relates to the component you've attatched the corresponding event listener to.
49
+ * @param type - the key in `TEventDetailMap` which is the event name from the detail map
50
+ * @param detail - *optional* param `TEventDetailMap[K]` which is the payload corresponding to the event `type`
51
+ * @param options - *optional* param {@link EmitOptions} to set event options. Default `{ composed: true, bubbles: true, cancelable: true, }`
52
+ */
53
+ export const emitter = () => ({
54
+ emit: (...args) => {
55
+ const baseOpts = {
56
+ composed: true,
57
+ bubbles: true,
58
+ cancelable: true,
59
+ };
60
+ const [origin, type, detailOrOpts, maybeOpts] = args;
61
+ if (maybeOpts) {
62
+ origin.dispatchEvent(new CustomEvent(type.toString(), Object.assign({ detail: detailOrOpts }, maybeOpts)));
63
+ }
64
+ else {
65
+ if (typeIsEmitOptions(detailOrOpts)) {
66
+ origin.dispatchEvent(new CustomEvent(type.toString(), detailOrOpts));
67
+ }
68
+ else {
69
+ origin.dispatchEvent(new CustomEvent(type.toString(), Object.assign({ detail: detailOrOpts }, baseOpts)));
70
+ }
71
+ }
72
+ },
73
+ });
74
+ function typeIsEmitOptions(p) {
75
+ return typeof p === 'object' && isEmitOptions(p);
76
+ }
@@ -1,2 +1,3 @@
1
+ export * from './emitterFunction';
1
2
  export * from './eventEmitterDI';
2
3
  export * from './eventEmitterMixin';
package/dist/esm/types.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @public
3
3
  */
4
- const isEmitOptions = (candidate) => (candidate === null || candidate === void 0 ? void 0 : candidate.hasOwnProperty('bubbles')) ||
4
+ export const isEmitOptions = (candidate) => (candidate === null || candidate === void 0 ? void 0 : candidate.hasOwnProperty('bubbles')) ||
5
5
  (candidate === null || candidate === void 0 ? void 0 : candidate.hasOwnProperty('cancelable')) ||
6
6
  (candidate === null || candidate === void 0 ? void 0 : candidate.hasOwnProperty('composed'));
7
7
  /**
@@ -722,6 +722,74 @@
722
722
  "endIndex": 2
723
723
  }
724
724
  },
725
+ {
726
+ "kind": "Variable",
727
+ "canonicalReference": "@genesislcap/foundation-events!emitter:var",
728
+ "docComment": "/**\n * emitter function.\n *\n * This is the functional equivalent of the strongly typed `.emit` function created with the {@link EventEmitter} mixin.\n *\n * @remarks\n *\n * This is useful if you need to emit an event from an arbitrary location. For example, if you want to emit an event from a button on a custom grid cell renderer you can use this to get strong typing rather than having to dependency inject a reference to the class which uses the {@link EventEmitter} mixin multiple levels into the renderer.\n *\n * @param orign - the `HTMLElement` to dispatch the event from. Ensure this correctly relates to the component you've attatched the corresponding event listener to.\n *\n * @param type - the key in `TEventDetailMap` which is the event name from the detail map\n *\n * @param detail - *optional* param `TEventDetailMap[K]` which is the payload corresponding to the event `type`\n *\n * @param options - *optional* param {@link EmitOptions} to set event options. Default `{ composed: true, bubbles: true, cancelable: true, }`\n *\n * @typeParam TEventDetailMap - The {@link EventDetailMap}.\n *\n * @example\n *\n * Apply mixin to the base {@link @microsoft/fast-element#FASTElement | FASTElement}\n *\n * # Import\n * ```ts\n * import { emitter, SomeSystemLevelEventDetailMap } from '@genesislcap/foundation-events';\n * import { StoreEventDetailMap, TradeEntryEventDetailMap } from '../store'; // < custom app level event maps\n * ```\n *\n * # Create event map\n * ```ts\n * type EventMap = SomeSystemLevelEventDetailMap & StoreEventDetailMap & TradeEntryEventDetailMap;\n * ```\n *\n * # Use the functional emitter. For example in a custom button action on a grid cell\n * ```ts\n * const customAction = {\n * name: `<rapid-button name=\"download\" size=\"lg\"></rapid-button>`\n * callback: (button: HTMLElement, data: RowData) =>\n * emitter<EventMap>().emit(\n * button,\n * 'some-allowed-event',\n * { foo: 'expected data structure' },\n * ),\n * }\n * ```\n *\n * @public\n */\n",
729
+ "excerptTokens": [
730
+ {
731
+ "kind": "Content",
732
+ "text": "emitter: "
733
+ },
734
+ {
735
+ "kind": "Content",
736
+ "text": "<TEventDetailMap extends "
737
+ },
738
+ {
739
+ "kind": "Reference",
740
+ "text": "EventDetailMap",
741
+ "canonicalReference": "@genesislcap/foundation-events!EventDetailMap:type"
742
+ },
743
+ {
744
+ "kind": "Content",
745
+ "text": ">() => {\n emit: <K extends keyof TEventDetailMap>(...args: TEventDetailMap[K] extends void ? [origin: "
746
+ },
747
+ {
748
+ "kind": "Reference",
749
+ "text": "HTMLElement",
750
+ "canonicalReference": "!HTMLElement:interface"
751
+ },
752
+ {
753
+ "kind": "Content",
754
+ "text": ", type: K, options?: "
755
+ },
756
+ {
757
+ "kind": "Reference",
758
+ "text": "EmitOptions",
759
+ "canonicalReference": "@genesislcap/foundation-events!EmitOptions:type"
760
+ },
761
+ {
762
+ "kind": "Content",
763
+ "text": "] : [origin: "
764
+ },
765
+ {
766
+ "kind": "Reference",
767
+ "text": "HTMLElement",
768
+ "canonicalReference": "!HTMLElement:interface"
769
+ },
770
+ {
771
+ "kind": "Content",
772
+ "text": ", type: K, detail: TEventDetailMap[K], options?: "
773
+ },
774
+ {
775
+ "kind": "Reference",
776
+ "text": "EmitOptions",
777
+ "canonicalReference": "@genesislcap/foundation-events!EmitOptions:type"
778
+ },
779
+ {
780
+ "kind": "Content",
781
+ "text": "]) => void;\n}"
782
+ }
783
+ ],
784
+ "fileUrlPath": "src/eventEmitter/emitterFunction.ts",
785
+ "isReadonly": true,
786
+ "releaseTag": "Public",
787
+ "name": "emitter",
788
+ "variableTypeTokenRange": {
789
+ "startIndex": 1,
790
+ "endIndex": 12
791
+ }
792
+ },
725
793
  {
726
794
  "kind": "TypeAlias",
727
795
  "canonicalReference": "@genesislcap/foundation-events!EventDetailMap:type",
@@ -3911,6 +3979,38 @@
3911
3979
  "endIndex": 3
3912
3980
  }
3913
3981
  },
3982
+ {
3983
+ "kind": "Variable",
3984
+ "canonicalReference": "@genesislcap/foundation-events!isEmitOptions:var",
3985
+ "docComment": "/**\n * @public\n */\n",
3986
+ "excerptTokens": [
3987
+ {
3988
+ "kind": "Content",
3989
+ "text": "isEmitOptions: "
3990
+ },
3991
+ {
3992
+ "kind": "Content",
3993
+ "text": "(candidate: "
3994
+ },
3995
+ {
3996
+ "kind": "Reference",
3997
+ "text": "EmitOptions",
3998
+ "canonicalReference": "@genesislcap/foundation-events!EmitOptions:type"
3999
+ },
4000
+ {
4001
+ "kind": "Content",
4002
+ "text": " | any) => boolean"
4003
+ }
4004
+ ],
4005
+ "fileUrlPath": "src/types.ts",
4006
+ "isReadonly": true,
4007
+ "releaseTag": "Public",
4008
+ "name": "isEmitOptions",
4009
+ "variableTypeTokenRange": {
4010
+ "startIndex": 1,
4011
+ "endIndex": 4
4012
+ }
4013
+ },
3914
4014
  {
3915
4015
  "kind": "TypeAlias",
3916
4016
  "canonicalReference": "@genesislcap/foundation-events!KeysMatching:type",
@@ -87,6 +87,61 @@ export declare type EmitOrigin = FASTElement;
87
87
  */
88
88
  export declare type EmitReturn = boolean | void;
89
89
 
90
+ /**
91
+ * emitter function.
92
+ *
93
+ * This is the functional equivalent of the strongly typed `.emit` function created with the {@link EventEmitter} mixin.
94
+ *
95
+ * @public
96
+ *
97
+ * @remarks
98
+ * This is useful if you need to emit an event from an arbitrary location. For example, if you want to emit an event
99
+ * from a button on a custom grid cell renderer you can use this to get strong typing rather than having to dependency
100
+ * inject a reference to the class which uses the {@link EventEmitter} mixin multiple levels into the renderer.
101
+ *
102
+ * @example
103
+ * Apply mixin to the base {@link @microsoft/fast-element#FASTElement | FASTElement}
104
+ *
105
+ * # Import
106
+ * ```ts
107
+ * import { emitter, SomeSystemLevelEventDetailMap } from '@genesislcap/foundation-events';
108
+ * import { StoreEventDetailMap, TradeEntryEventDetailMap } from '../store'; // < custom app level event maps
109
+ * ```
110
+ *
111
+ * # Create event map
112
+ * ```ts
113
+ * type EventMap = SomeSystemLevelEventDetailMap & StoreEventDetailMap & TradeEntryEventDetailMap;
114
+ * ```
115
+ *
116
+ * # Use the functional emitter. For example in a custom button action on a grid cell
117
+ * ```ts
118
+ * const customAction = {
119
+ * name: `<rapid-button name="download" size="lg"></rapid-button>`
120
+ * callback: (button: HTMLElement, data: RowData) =>
121
+ * emitter<EventMap>().emit(
122
+ * button,
123
+ * 'some-allowed-event',
124
+ * { foo: 'expected data structure' },
125
+ * ),
126
+ * }
127
+ * ```
128
+ *
129
+ * @privateRemarks
130
+ * The reason it's a function which returns an object with another function is to create the best developer ergonomics
131
+ * accounting for TypeScript. This setup allows you to only set one type parameter to control the strong typing, if we
132
+ * were to add it all onto the same function you'd either have to specify multiple type parameters (repeating yourself)
133
+ * or if we used implicits it wouldn't type check the payload against the type correctly.
134
+ *
135
+ * @typeParam TEventDetailMap - The {@link EventDetailMap}.
136
+ * @param orign - the `HTMLElement` to dispatch the event from. Ensure this correctly relates to the component you've attatched the corresponding event listener to.
137
+ * @param type - the key in `TEventDetailMap` which is the event name from the detail map
138
+ * @param detail - *optional* param `TEventDetailMap[K]` which is the payload corresponding to the event `type`
139
+ * @param options - *optional* param {@link EmitOptions} to set event options. Default `{ composed: true, bubbles: true, cancelable: true, }`
140
+ */
141
+ export declare const emitter: <TEventDetailMap extends EventDetailMap>() => {
142
+ emit: <K extends keyof TEventDetailMap>(...args: TEventDetailMap[K] extends void ? [origin: HTMLElement, type: K, options?: EmitOptions] : [origin: HTMLElement, type: K, detail: TEventDetailMap[K], options?: EmitOptions]) => void;
143
+ };
144
+
90
145
  /**
91
146
  * @public
92
147
  */
@@ -510,6 +565,11 @@ export declare type EventEmitterTarget<TBase extends FASTElement> = abstract new
510
565
  */
511
566
  export declare const getBaseEmitArgs: (...args: unknown[]) => EmitArgs;
512
567
 
568
+ /**
569
+ * @public
570
+ */
571
+ export declare const isEmitOptions: (candidate: EmitOptions | any) => boolean;
572
+
513
573
  /**
514
574
  * @public
515
575
  */
@@ -0,0 +1,51 @@
1
+ <!-- Do not edit this file. It is automatically generated by API Documenter. -->
2
+
3
+ [Home](./index.md) &gt; [@genesislcap/foundation-events](./foundation-events.md) &gt; [emitter](./foundation-events.emitter.md)
4
+
5
+ ## emitter variable
6
+
7
+ emitter function.
8
+
9
+ This is the functional equivalent of the strongly typed `.emit` function created with the [EventEmitter](./foundation-events.eventemitter.md) mixin.
10
+
11
+ **Signature:**
12
+
13
+ ```typescript
14
+ emitter: <TEventDetailMap extends EventDetailMap>() => {
15
+ emit: <K extends keyof TEventDetailMap>(...args: TEventDetailMap[K] extends void ? [origin: HTMLElement, type: K, options?: EmitOptions] : [origin: HTMLElement, type: K, detail: TEventDetailMap[K], options?: EmitOptions]) => void;
16
+ }
17
+ ```
18
+
19
+ ## Remarks
20
+
21
+ This is useful if you need to emit an event from an arbitrary location. For example, if you want to emit an event from a button on a custom grid cell renderer you can use this to get strong typing rather than having to dependency inject a reference to the class which uses the [EventEmitter](./foundation-events.eventemitter.md) mixin multiple levels into the renderer.
22
+
23
+ ## Example
24
+
25
+ Apply mixin to the base
26
+
27
+ \# Import
28
+
29
+ ```ts
30
+ import { emitter, SomeSystemLevelEventDetailMap } from '@genesislcap/foundation-events';
31
+ import { StoreEventDetailMap, TradeEntryEventDetailMap } from '../store'; // < custom app level event maps
32
+ ```
33
+ \# Create event map
34
+
35
+ ```ts
36
+ type EventMap = SomeSystemLevelEventDetailMap & StoreEventDetailMap & TradeEntryEventDetailMap;
37
+ ```
38
+ \# Use the functional emitter. For example in a custom button action on a grid cell
39
+
40
+ ```ts
41
+ const customAction = {
42
+ name: `<rapid-button name="download" size="lg"></rapid-button>`
43
+ callback: (button: HTMLElement, data: RowData) =>
44
+ emitter<EventMap>().emit(
45
+ button,
46
+ 'some-allowed-event',
47
+ { foo: 'expected data structure' },
48
+ ),
49
+ }
50
+ ```
51
+
@@ -0,0 +1,12 @@
1
+ <!-- Do not edit this file. It is automatically generated by API Documenter. -->
2
+
3
+ [Home](./index.md) &gt; [@genesislcap/foundation-events](./foundation-events.md) &gt; [isEmitOptions](./foundation-events.isemitoptions.md)
4
+
5
+ ## isEmitOptions variable
6
+
7
+
8
+ **Signature:**
9
+
10
+ ```typescript
11
+ isEmitOptions: (candidate: EmitOptions | any) => boolean
12
+ ```
@@ -24,8 +24,10 @@
24
24
  | [createInputEmitter](./foundation-events.createinputemitter.md) | <code>&lt;input&gt;</code> template emit helper. |
25
25
  | [createSelectEmitter](./foundation-events.createselectemitter.md) | <code>&lt;select&gt;</code> template emit helper. |
26
26
  | [customEvent](./foundation-events.customevent.md) | |
27
+ | [emitter](./foundation-events.emitter.md) | <p>emitter function.</p><p>This is the functional equivalent of the strongly typed <code>.emit</code> function created with the [EventEmitter](./foundation-events.eventemitter.md) mixin.</p> |
27
28
  | [EventEmitter](./foundation-events.eventemitter.md) | EventEmitter mixin. |
28
29
  | [getBaseEmitArgs](./foundation-events.getbaseemitargs.md) | |
30
+ | [isEmitOptions](./foundation-events.isemitoptions.md) | |
29
31
  | [logger](./foundation-events.logger.md) | |
30
32
  | [registerEmitter](./foundation-events.registeremitter.md) | Register an emitter with the DI. |
31
33
  | [targetChecked](./foundation-events.targetchecked.md) | |
@@ -47,6 +47,11 @@ export type EmitOrigin = FASTElement;
47
47
  // @public (undocumented)
48
48
  export type EmitReturn = boolean | void;
49
49
 
50
+ // @public
51
+ export const emitter: <TEventDetailMap extends EventDetailMap>() => {
52
+ emit: <K extends keyof TEventDetailMap>(...args: TEventDetailMap[K] extends void ? [origin: HTMLElement, type: K, options?: EmitOptions] : [origin: HTMLElement, type: K, detail: TEventDetailMap[K], options?: EmitOptions]) => void;
53
+ };
54
+
50
55
  // @public (undocumented)
51
56
  export type EventDetailMap = Record<string, unknown>;
52
57
 
@@ -384,6 +389,9 @@ export type EventEmitterTarget<TBase extends FASTElement> = abstract new (...arg
384
389
  // @public (undocumented)
385
390
  export const getBaseEmitArgs: (...args: unknown[]) => EmitArgs;
386
391
 
392
+ // @public (undocumented)
393
+ export const isEmitOptions: (candidate: EmitOptions | any) => boolean;
394
+
387
395
  // @public (undocumented)
388
396
  export type KeysMatching<T, V> = {
389
397
  [K in keyof T]-?: T[K] extends V ? K : never;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@genesislcap/foundation-events",
3
3
  "description": "Genesis Foundation Events",
4
- "version": "14.241.0",
4
+ "version": "14.242.0",
5
5
  "sideEffects": false,
6
6
  "license": "SEE LICENSE IN license.txt",
7
7
  "main": "dist/esm/index.js",
@@ -49,17 +49,17 @@
49
49
  }
50
50
  },
51
51
  "devDependencies": {
52
- "@genesislcap/foundation-testing": "14.241.0",
53
- "@genesislcap/genx": "14.241.0",
54
- "@genesislcap/rollup-builder": "14.241.0",
55
- "@genesislcap/ts-builder": "14.241.0",
56
- "@genesislcap/uvu-playwright-builder": "14.241.0",
57
- "@genesislcap/vite-builder": "14.241.0",
58
- "@genesislcap/webpack-builder": "14.241.0",
52
+ "@genesislcap/foundation-testing": "14.242.0",
53
+ "@genesislcap/genx": "14.242.0",
54
+ "@genesislcap/rollup-builder": "14.242.0",
55
+ "@genesislcap/ts-builder": "14.242.0",
56
+ "@genesislcap/uvu-playwright-builder": "14.242.0",
57
+ "@genesislcap/vite-builder": "14.242.0",
58
+ "@genesislcap/webpack-builder": "14.242.0",
59
59
  "rimraf": "^5.0.0"
60
60
  },
61
61
  "dependencies": {
62
- "@genesislcap/foundation-logger": "14.241.0",
62
+ "@genesislcap/foundation-logger": "14.242.0",
63
63
  "@microsoft/fast-element": "1.14.0",
64
64
  "@microsoft/fast-foundation": "2.49.6",
65
65
  "tslib": "^2.3.1"
@@ -72,5 +72,5 @@
72
72
  "publishConfig": {
73
73
  "access": "public"
74
74
  },
75
- "gitHead": "6837efcb9fe40e7044bb23d89368ecdcb20a4f3f"
75
+ "gitHead": "998546fa7f8fc8da70f534d4445719bef59a2dba"
76
76
  }