@genesislcap/foundation-store 14.117.0 → 14.118.0
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +94 -36
- package/dist/dts/__test__/elements.d.ts +701 -0
- package/dist/dts/__test__/elements.d.ts.map +1 -0
- package/dist/dts/__test__/index.d.ts +5 -0
- package/dist/dts/__test__/index.d.ts.map +1 -0
- package/dist/dts/__test__/services.d.ts +40 -0
- package/dist/dts/__test__/services.d.ts.map +1 -0
- package/dist/dts/__test__/store.d.ts +145 -0
- package/dist/dts/__test__/store.d.ts.map +1 -0
- package/dist/dts/__test__/types.d.ts +15 -0
- package/dist/dts/__test__/types.d.ts.map +1 -0
- package/dist/dts/store/errorMap.d.ts +3 -0
- package/dist/dts/store/errorMap.d.ts.map +1 -1
- package/dist/dts/store/foundationStore.d.ts +108 -12
- package/dist/dts/store/foundationStore.d.ts.map +1 -1
- package/dist/esm/__test__/elements.js +118 -0
- package/dist/esm/__test__/index.js +4 -0
- package/dist/esm/__test__/services.js +37 -0
- package/dist/esm/__test__/store.js +154 -0
- package/dist/esm/__test__/types.js +1 -0
- package/dist/esm/store/foundationStore.js +145 -40
- package/dist/foundation-store.api.json +174 -13
- package/dist/foundation-store.d.ts +113 -12
- package/docs/api/foundation-store.abstractstore.createasynclistener.md +35 -1
- package/docs/api/foundation-store.abstractstore.createerrorlistener.md +1 -1
- package/docs/api/foundation-store.abstractstore.createlistener.md +1 -1
- package/docs/api/foundation-store.abstractstore.invokeasyncapi.md +46 -0
- package/docs/api/foundation-store.abstractstore.md +4 -3
- package/docs/api/foundation-store.errordetailmap.md +4 -0
- package/docs/api/foundation-store.errormap.md +4 -0
- package/docs/api/foundation-store.errormaplogger.md +4 -0
- package/docs/api/foundation-store.registerstore.md +1 -1
- package/docs/api-report.md +27 -6
- package/package.json +11 -7
@@ -822,7 +822,7 @@
|
|
822
822
|
{
|
823
823
|
"kind": "Property",
|
824
824
|
"canonicalReference": "@genesislcap/foundation-store!AbstractStore#createAsyncListener:member",
|
825
|
-
"docComment": "/**\n * Creates an async event listener.\n *\n * @remarks\n *\n * You can think of this like an `effect` in the redux sense. You should not commit values to the store in these, instead raise subsequent events to be handled synchronously, where commits are allowed.\n *\n * @param
|
825
|
+
"docComment": "/**\n * Creates an async event listener.\n *\n * @remarks\n *\n * You can think of this like an `effect` in the redux sense. You should not commit values to the store in these, instead raise subsequent events to be handled synchronously, where commits are allowed.\n *\n * @param keys - The event key or keys from the store fragment's event detail map.\n *\n * @param token - The async function handling the event.\n *\n * @typeParam TDetail - The CustomEvent detail.\n *\n * @returns The event listener.\n *\n * @example\n *\n * Creating an interface defined handler for a single event key.\n * ```ts\n * onDomainAction = this.createAsyncListener<DomainActionDetail>(\n * 'domain-action',\n * async ({ id, message }) =>\n * this.invokeAsyncAPI(\n * async () => this.domainService.action(id, message),\n * 'domain-action-error',\n * 'domain-action-success'\n * )\n * );\n * ```\n *\n * @example\n *\n * Creating an anonymous handler in the constructor for multiple event keys.\n * ```ts\n * this.createAsyncListener(\n * [\n * 'columns-changed',\n * 'types-changed',\n * 'max-rows-changed',\n * 'max-view-changed',\n * 'order-by-changed',\n * 'reverse-changed',\n * ],\n * async (_, { type }) => this.emit('domain-load')\n * );\n * ```\n *\n * @public\n */\n",
|
826
826
|
"excerptTokens": [
|
827
827
|
{
|
828
828
|
"kind": "Content",
|
@@ -830,7 +830,25 @@
|
|
830
830
|
},
|
831
831
|
{
|
832
832
|
"kind": "Content",
|
833
|
-
"text": "<TDetail = void, TReturn = void>(
|
833
|
+
"text": "<TDetail = void, TReturn = void>(keys: "
|
834
|
+
},
|
835
|
+
{
|
836
|
+
"kind": "Reference",
|
837
|
+
"text": "KeyOrKeys",
|
838
|
+
"canonicalReference": "@genesislcap/foundation-store!KeyOrKeys:type"
|
839
|
+
},
|
840
|
+
{
|
841
|
+
"kind": "Content",
|
842
|
+
"text": "<TEventDetailMap & TInternalEventDetailMap>, token: (detail: TDetail, event?: "
|
843
|
+
},
|
844
|
+
{
|
845
|
+
"kind": "Reference",
|
846
|
+
"text": "CustomEvent",
|
847
|
+
"canonicalReference": "!CustomEvent:interface"
|
848
|
+
},
|
849
|
+
{
|
850
|
+
"kind": "Content",
|
851
|
+
"text": "<TDetail>) => "
|
834
852
|
},
|
835
853
|
{
|
836
854
|
"kind": "Reference",
|
@@ -857,7 +875,7 @@
|
|
857
875
|
"name": "createAsyncListener",
|
858
876
|
"propertyTypeTokenRange": {
|
859
877
|
"startIndex": 1,
|
860
|
-
"endIndex":
|
878
|
+
"endIndex": 9
|
861
879
|
},
|
862
880
|
"isStatic": false,
|
863
881
|
"isProtected": true,
|
@@ -866,7 +884,7 @@
|
|
866
884
|
{
|
867
885
|
"kind": "Property",
|
868
886
|
"canonicalReference": "@genesislcap/foundation-store!AbstractStore#createErrorListener:member",
|
869
|
-
"docComment": "/**\n * Creates an error event listener.\n *\n * @remarks\n *\n * This logs and stores errors by event key in the store fragment's {@link ErrorMap}, allowing multiple errors to co-exist, and be presentable to the user via the UI for further action or dismissal.\n *\n * @param
|
887
|
+
"docComment": "/**\n * Creates an error event listener.\n *\n * @remarks\n *\n * This logs and stores errors by event key in the store fragment's {@link ErrorMap}, allowing multiple errors to co-exist, and be presentable to the user via the UI for further action or dismissal.\n *\n * @param keys - The event key or keys from the store fragment's event detail map.\n *\n * @param token - The function handling the event.\n *\n * @typeParam TDetail - The CustomEvent detail.\n *\n * @returns The event listener.\n *\n * @public\n */\n",
|
870
888
|
"excerptTokens": [
|
871
889
|
{
|
872
890
|
"kind": "Content",
|
@@ -892,7 +910,25 @@
|
|
892
910
|
},
|
893
911
|
{
|
894
912
|
"kind": "Content",
|
895
|
-
"text": ">(
|
913
|
+
"text": ">(keys: "
|
914
|
+
},
|
915
|
+
{
|
916
|
+
"kind": "Reference",
|
917
|
+
"text": "KeyOrKeys",
|
918
|
+
"canonicalReference": "@genesislcap/foundation-store!KeyOrKeys:type"
|
919
|
+
},
|
920
|
+
{
|
921
|
+
"kind": "Content",
|
922
|
+
"text": "<TEventDetailMap & TInternalEventDetailMap>, token?: (detail: TDetail, event?: "
|
923
|
+
},
|
924
|
+
{
|
925
|
+
"kind": "Reference",
|
926
|
+
"text": "CustomEvent",
|
927
|
+
"canonicalReference": "!CustomEvent:interface"
|
928
|
+
},
|
929
|
+
{
|
930
|
+
"kind": "Content",
|
931
|
+
"text": "<TDetail>) => void) => "
|
896
932
|
},
|
897
933
|
{
|
898
934
|
"kind": "Reference",
|
@@ -910,7 +946,7 @@
|
|
910
946
|
"name": "createErrorListener",
|
911
947
|
"propertyTypeTokenRange": {
|
912
948
|
"startIndex": 1,
|
913
|
-
"endIndex":
|
949
|
+
"endIndex": 11
|
914
950
|
},
|
915
951
|
"isStatic": false,
|
916
952
|
"isProtected": true,
|
@@ -919,7 +955,7 @@
|
|
919
955
|
{
|
920
956
|
"kind": "Property",
|
921
957
|
"canonicalReference": "@genesislcap/foundation-store!AbstractStore#createListener:member",
|
922
|
-
"docComment": "/**\n * Creates an event listener.\n *\n * @remarks\n *\n * You can think of this like a `reducer` in the redux sense. You are allowed to commit values to the store in these synchronous handlers.\n *\n * @param
|
958
|
+
"docComment": "/**\n * Creates an event listener.\n *\n * @remarks\n *\n * You can think of this like a `reducer` in the redux sense. You are allowed to commit values to the store in these synchronous handlers.\n *\n * @param keys - The event key or keys from the store fragment's event detail map.\n *\n * @param token - The function handling the event.\n *\n * @typeParam TDetail - The CustomEvent detail.\n *\n * @returns The event listener.\n *\n * @public\n */\n",
|
923
959
|
"excerptTokens": [
|
924
960
|
{
|
925
961
|
"kind": "Content",
|
@@ -927,7 +963,25 @@
|
|
927
963
|
},
|
928
964
|
{
|
929
965
|
"kind": "Content",
|
930
|
-
"text": "<TDetail = void>(
|
966
|
+
"text": "<TDetail = void>(keys: "
|
967
|
+
},
|
968
|
+
{
|
969
|
+
"kind": "Reference",
|
970
|
+
"text": "KeyOrKeys",
|
971
|
+
"canonicalReference": "@genesislcap/foundation-store!KeyOrKeys:type"
|
972
|
+
},
|
973
|
+
{
|
974
|
+
"kind": "Content",
|
975
|
+
"text": "<TEventDetailMap & TInternalEventDetailMap>, token: (detail: TDetail, event?: "
|
976
|
+
},
|
977
|
+
{
|
978
|
+
"kind": "Reference",
|
979
|
+
"text": "CustomEvent",
|
980
|
+
"canonicalReference": "!CustomEvent:interface"
|
981
|
+
},
|
982
|
+
{
|
983
|
+
"kind": "Content",
|
984
|
+
"text": "<TDetail>) => void) => "
|
931
985
|
},
|
932
986
|
{
|
933
987
|
"kind": "Reference",
|
@@ -945,7 +999,7 @@
|
|
945
999
|
"name": "createListener",
|
946
1000
|
"propertyTypeTokenRange": {
|
947
1001
|
"startIndex": 1,
|
948
|
-
"endIndex":
|
1002
|
+
"endIndex": 7
|
949
1003
|
},
|
950
1004
|
"isStatic": false,
|
951
1005
|
"isProtected": true,
|
@@ -1103,6 +1157,113 @@
|
|
1103
1157
|
"isProtected": false,
|
1104
1158
|
"isAbstract": false
|
1105
1159
|
},
|
1160
|
+
{
|
1161
|
+
"kind": "Method",
|
1162
|
+
"canonicalReference": "@genesislcap/foundation-store!AbstractStore#invokeAsyncAPI:member(1)",
|
1163
|
+
"docComment": "/**\n * A convenience method to invoke an async api and emit success and error events.\n *\n * @remarks\n *\n * The async api function should throw when it encounters an error.\n *\n * @param api - The async service api function.\n *\n * @param error - The event key from the store fragment's event detail map.\n *\n * @param success - The event key from the store fragment's event detail map.\n *\n * @example\n * ```ts\n * onLoad = this.createAsyncListener('domain-load', async () =>\n * this.invokeAsyncAPI(\n * async () => {\n * !this.domainService.initialized && (await this.domainService.initialize(this.asDomainServiceInit()));\n * return this.domainService.list();\n * },\n * 'domain-load-error',\n * 'domain-load-success'\n * )\n * );\n * ```\n *\n * @public\n */\n",
|
1164
|
+
"excerptTokens": [
|
1165
|
+
{
|
1166
|
+
"kind": "Content",
|
1167
|
+
"text": "protected invokeAsyncAPI<TResult>(api: "
|
1168
|
+
},
|
1169
|
+
{
|
1170
|
+
"kind": "Content",
|
1171
|
+
"text": "() => "
|
1172
|
+
},
|
1173
|
+
{
|
1174
|
+
"kind": "Reference",
|
1175
|
+
"text": "Promise",
|
1176
|
+
"canonicalReference": "!Promise:interface"
|
1177
|
+
},
|
1178
|
+
{
|
1179
|
+
"kind": "Content",
|
1180
|
+
"text": "<TResult>"
|
1181
|
+
},
|
1182
|
+
{
|
1183
|
+
"kind": "Content",
|
1184
|
+
"text": ", error: "
|
1185
|
+
},
|
1186
|
+
{
|
1187
|
+
"kind": "Content",
|
1188
|
+
"text": "keyof (TEventDetailMap & TInternalEventDetailMap)"
|
1189
|
+
},
|
1190
|
+
{
|
1191
|
+
"kind": "Content",
|
1192
|
+
"text": ", success?: "
|
1193
|
+
},
|
1194
|
+
{
|
1195
|
+
"kind": "Content",
|
1196
|
+
"text": "keyof (TEventDetailMap & TInternalEventDetailMap)"
|
1197
|
+
},
|
1198
|
+
{
|
1199
|
+
"kind": "Content",
|
1200
|
+
"text": "): "
|
1201
|
+
},
|
1202
|
+
{
|
1203
|
+
"kind": "Reference",
|
1204
|
+
"text": "Promise",
|
1205
|
+
"canonicalReference": "!Promise:interface"
|
1206
|
+
},
|
1207
|
+
{
|
1208
|
+
"kind": "Content",
|
1209
|
+
"text": "<void>"
|
1210
|
+
},
|
1211
|
+
{
|
1212
|
+
"kind": "Content",
|
1213
|
+
"text": ";"
|
1214
|
+
}
|
1215
|
+
],
|
1216
|
+
"typeParameters": [
|
1217
|
+
{
|
1218
|
+
"typeParameterName": "TResult",
|
1219
|
+
"constraintTokenRange": {
|
1220
|
+
"startIndex": 0,
|
1221
|
+
"endIndex": 0
|
1222
|
+
},
|
1223
|
+
"defaultTypeTokenRange": {
|
1224
|
+
"startIndex": 0,
|
1225
|
+
"endIndex": 0
|
1226
|
+
}
|
1227
|
+
}
|
1228
|
+
],
|
1229
|
+
"isStatic": false,
|
1230
|
+
"returnTypeTokenRange": {
|
1231
|
+
"startIndex": 9,
|
1232
|
+
"endIndex": 11
|
1233
|
+
},
|
1234
|
+
"releaseTag": "Public",
|
1235
|
+
"isProtected": true,
|
1236
|
+
"overloadIndex": 1,
|
1237
|
+
"parameters": [
|
1238
|
+
{
|
1239
|
+
"parameterName": "api",
|
1240
|
+
"parameterTypeTokenRange": {
|
1241
|
+
"startIndex": 1,
|
1242
|
+
"endIndex": 4
|
1243
|
+
},
|
1244
|
+
"isOptional": false
|
1245
|
+
},
|
1246
|
+
{
|
1247
|
+
"parameterName": "error",
|
1248
|
+
"parameterTypeTokenRange": {
|
1249
|
+
"startIndex": 5,
|
1250
|
+
"endIndex": 6
|
1251
|
+
},
|
1252
|
+
"isOptional": false
|
1253
|
+
},
|
1254
|
+
{
|
1255
|
+
"parameterName": "success",
|
1256
|
+
"parameterTypeTokenRange": {
|
1257
|
+
"startIndex": 7,
|
1258
|
+
"endIndex": 8
|
1259
|
+
},
|
1260
|
+
"isOptional": true
|
1261
|
+
}
|
1262
|
+
],
|
1263
|
+
"isOptional": false,
|
1264
|
+
"isAbstract": false,
|
1265
|
+
"name": "invokeAsyncAPI"
|
1266
|
+
},
|
1106
1267
|
{
|
1107
1268
|
"kind": "Property",
|
1108
1269
|
"canonicalReference": "@genesislcap/foundation-store!AbstractStore#name:member",
|
@@ -1537,7 +1698,7 @@
|
|
1537
1698
|
{
|
1538
1699
|
"kind": "TypeAlias",
|
1539
1700
|
"canonicalReference": "@genesislcap/foundation-store!ErrorDetailMap:type",
|
1540
|
-
"docComment": "/**\n * @public\n */\n",
|
1701
|
+
"docComment": "/**\n * @deprecated\n *\n * - Use `ErrorDetailMap` from `@genesislcap/foundation-utils` instead.\n *\n * @public\n */\n",
|
1541
1702
|
"excerptTokens": [
|
1542
1703
|
{
|
1543
1704
|
"kind": "Content",
|
@@ -1568,7 +1729,7 @@
|
|
1568
1729
|
{
|
1569
1730
|
"kind": "Interface",
|
1570
1731
|
"canonicalReference": "@genesislcap/foundation-store!ErrorMap:interface",
|
1571
|
-
"docComment": "/**\n * @public\n */\n",
|
1732
|
+
"docComment": "/**\n * @deprecated\n *\n * - Use `ErrorMap` from `@genesislcap/foundation-utils` instead.\n *\n * @public\n */\n",
|
1572
1733
|
"excerptTokens": [
|
1573
1734
|
{
|
1574
1735
|
"kind": "Content",
|
@@ -1733,7 +1894,7 @@
|
|
1733
1894
|
{
|
1734
1895
|
"kind": "TypeAlias",
|
1735
1896
|
"canonicalReference": "@genesislcap/foundation-store!ErrorMapLogger:type",
|
1736
|
-
"docComment": "/**\n * @public\n */\n",
|
1897
|
+
"docComment": "/**\n * @deprecated\n *\n * - Use `ErrorMapLogger` from `@genesislcap/foundation-utils` instead.\n *\n * @public\n */\n",
|
1737
1898
|
"excerptTokens": [
|
1738
1899
|
{
|
1739
1900
|
"kind": "Content",
|
@@ -1759,7 +1920,7 @@
|
|
1759
1920
|
{
|
1760
1921
|
"kind": "Variable",
|
1761
1922
|
"canonicalReference": "@genesislcap/foundation-store!registerStore:var",
|
1762
|
-
"docComment": "/**\n * Creates a dependency injection key for the store being registered.\n *\n * @param Base - The store fragment class.\n *\n * @param name - The name of your store fragment, mostly used for internal logging.\n *\n * @returns The created key.\n *\n * @example\n * ```ts\n * export const TradeEntry = registerStore(DefaultTradeEntry, 'TradeEntry');\n * ```\n *\n * @public\n */\n",
|
1923
|
+
"docComment": "/**\n * Creates a dependency injection key for the store being registered.\n *\n * @param Base - The store fragment class.\n *\n * @param name - The name of your store fragment, mostly used for internal logging.\n *\n * @returns The created key.\n *\n * @example\n * ```ts\n * export const TradeEntry = registerStore<TradeEntry>(DefaultTradeEntry, 'TradeEntry');\n * ```\n *\n * @public\n */\n",
|
1763
1924
|
"excerptTokens": [
|
1764
1925
|
{
|
1765
1926
|
"kind": "Content",
|
@@ -20,6 +20,10 @@ export declare abstract class AbstractStore<TStore extends Store, TEventDetailMa
|
|
20
20
|
/**
|
21
21
|
* The store fragment's event listener map.
|
22
22
|
*
|
23
|
+
* @remarks
|
24
|
+
* Keyed by listener to allow events to have multiple listeners for cleaner logic flows.
|
25
|
+
* See multiple event keys example in `createAsyncListener`.
|
26
|
+
*
|
23
27
|
* @internal
|
24
28
|
*/
|
25
29
|
private eventListenerMap;
|
@@ -117,18 +121,39 @@ export declare abstract class AbstractStore<TStore extends Store, TEventDetailMa
|
|
117
121
|
*/
|
118
122
|
private logEvent;
|
119
123
|
/**
|
120
|
-
*
|
121
|
-
*
|
122
|
-
* @
|
123
|
-
* @
|
124
|
+
* Creates an event listener by type.
|
125
|
+
*
|
126
|
+
* @typeParam TDetail - The CustomEvent detail.
|
127
|
+
* @param type - The type of event listener to create. See {@link EventListenerType}.
|
128
|
+
* @param keys - The event key or keys from the store fragment's event detail map.
|
129
|
+
* @param token - The function handling the event.
|
130
|
+
* @returns The event listener when one key is passed or undefined.
|
124
131
|
*
|
125
132
|
* @internal
|
126
133
|
*/
|
127
|
-
private
|
134
|
+
private createListenerType;
|
135
|
+
/**
|
136
|
+
* Creates an event listener envelope.
|
137
|
+
*
|
138
|
+
* @remarks
|
139
|
+
* These wrap the provided token.
|
140
|
+
*
|
141
|
+
* @typeParam TDetail - The CustomEvent detail.
|
142
|
+
* @param listenerType - The type of event listener to create. See {@link EventListenerType}.
|
143
|
+
* @param token - The function handling the event.
|
144
|
+
* @returns An event listener.
|
145
|
+
*
|
146
|
+
* @internal
|
147
|
+
*/
|
148
|
+
private createListenerEnvelope;
|
128
149
|
/**
|
129
150
|
* Creates an event listener.
|
151
|
+
*
|
152
|
+
* @remarks
|
153
|
+
* See the `createAsyncListener` for usage examples.
|
154
|
+
*
|
130
155
|
* @typeParam TDetail - The CustomEvent detail.
|
131
|
-
* @param
|
156
|
+
* @param keys - The event key or keys from the store fragment's event detail map.
|
132
157
|
* @param token - The function handling the event.
|
133
158
|
* @returns The event listener.
|
134
159
|
*
|
@@ -137,11 +162,42 @@ export declare abstract class AbstractStore<TStore extends Store, TEventDetailMa
|
|
137
162
|
* You can think of this like a `reducer` in the redux sense. You are allowed to commit values to the store in these
|
138
163
|
* synchronous handlers.
|
139
164
|
*/
|
140
|
-
protected createListener: <TDetail = void>(
|
165
|
+
protected createListener: <TDetail = void>(keys: KeyOrKeys<TEventDetailMap & TInternalEventDetailMap>, token: (detail: TDetail, event?: CustomEvent<TDetail>) => void) => EventListener;
|
141
166
|
/**
|
142
167
|
* Creates an async event listener.
|
168
|
+
*
|
169
|
+
* @example
|
170
|
+
* Creating an interface defined handler for a single event key.
|
171
|
+
* ```ts
|
172
|
+
* onDomainAction = this.createAsyncListener<DomainActionDetail>(
|
173
|
+
* 'domain-action',
|
174
|
+
* async ({ id, message }) =>
|
175
|
+
* this.invokeAsyncAPI(
|
176
|
+
* async () => this.domainService.action(id, message),
|
177
|
+
* 'domain-action-error',
|
178
|
+
* 'domain-action-success'
|
179
|
+
* )
|
180
|
+
* );
|
181
|
+
* ```
|
182
|
+
*
|
183
|
+
* @example
|
184
|
+
* Creating an anonymous handler in the constructor for multiple event keys.
|
185
|
+
* ```ts
|
186
|
+
* this.createAsyncListener(
|
187
|
+
* [
|
188
|
+
* 'columns-changed',
|
189
|
+
* 'types-changed',
|
190
|
+
* 'max-rows-changed',
|
191
|
+
* 'max-view-changed',
|
192
|
+
* 'order-by-changed',
|
193
|
+
* 'reverse-changed',
|
194
|
+
* ],
|
195
|
+
* async (_, { type }) => this.emit('domain-load')
|
196
|
+
* );
|
197
|
+
* ```
|
198
|
+
*
|
143
199
|
* @typeParam TDetail - The CustomEvent detail.
|
144
|
-
* @param
|
200
|
+
* @param keys - The event key or keys from the store fragment's event detail map.
|
145
201
|
* @param token - The async function handling the event.
|
146
202
|
* @returns The event listener.
|
147
203
|
*
|
@@ -150,11 +206,11 @@ export declare abstract class AbstractStore<TStore extends Store, TEventDetailMa
|
|
150
206
|
* You can think of this like an `effect` in the redux sense. You should not commit values to the store in these,
|
151
207
|
* instead raise subsequent events to be handled synchronously, where commits are allowed.
|
152
208
|
*/
|
153
|
-
protected createAsyncListener: <TDetail = void, TReturn = void>(
|
209
|
+
protected createAsyncListener: <TDetail = void, TReturn = void>(keys: KeyOrKeys<TEventDetailMap & TInternalEventDetailMap>, token: (detail: TDetail, event?: CustomEvent<TDetail>) => Promise<TReturn>) => EventListener;
|
154
210
|
/**
|
155
211
|
* Creates an error event listener.
|
156
212
|
* @typeParam TDetail - The CustomEvent detail.
|
157
|
-
* @param
|
213
|
+
* @param keys - The event key or keys from the store fragment's event detail map.
|
158
214
|
* @param token - The function handling the event.
|
159
215
|
* @returns The event listener.
|
160
216
|
*
|
@@ -163,7 +219,7 @@ export declare abstract class AbstractStore<TStore extends Store, TEventDetailMa
|
|
163
219
|
* This logs and stores errors by event key in the store fragment's {@link ErrorMap}, allowing multiple errors to
|
164
220
|
* co-exist, and be presentable to the user via the UI for further action or dismissal.
|
165
221
|
*/
|
166
|
-
protected createErrorListener: <TDetail extends Error = Error>(
|
222
|
+
protected createErrorListener: <TDetail extends Error = Error>(keys: KeyOrKeys<TEventDetailMap & TInternalEventDetailMap>, token?: (detail: TDetail, event?: CustomEvent<TDetail>) => void) => EventListener;
|
167
223
|
/**
|
168
224
|
* Add the store fragment's event listeners to the root element.
|
169
225
|
* @param element - The store root element.
|
@@ -195,6 +251,32 @@ export declare abstract class AbstractStore<TStore extends Store, TEventDetailMa
|
|
195
251
|
* fragments.
|
196
252
|
*/
|
197
253
|
protected emit<K extends keyof (TEventDetailMap & TInternalEventDetailMap) & string>(...args: (TEventDetailMap & TInternalEventDetailMap)[K] extends void ? [key: K] : [key: K, detail: (TEventDetailMap & TInternalEventDetailMap)[K]]): void;
|
254
|
+
/**
|
255
|
+
* A convenience method to invoke an async api and emit success and error events.
|
256
|
+
*
|
257
|
+
* @remarks
|
258
|
+
* The async api function should throw when it encounters an error.
|
259
|
+
*
|
260
|
+
* @example
|
261
|
+
* ```ts
|
262
|
+
* onLoad = this.createAsyncListener('domain-load', async () =>
|
263
|
+
* this.invokeAsyncAPI(
|
264
|
+
* async () => {
|
265
|
+
* !this.domainService.initialized && (await this.domainService.initialize(this.asDomainServiceInit()));
|
266
|
+
* return this.domainService.list();
|
267
|
+
* },
|
268
|
+
* 'domain-load-error',
|
269
|
+
* 'domain-load-success'
|
270
|
+
* )
|
271
|
+
* );
|
272
|
+
* ```
|
273
|
+
*
|
274
|
+
* @param api - The async service api function.
|
275
|
+
* @param error - The event key from the store fragment's event detail map.
|
276
|
+
* @param success - The event key from the store fragment's event detail map.
|
277
|
+
* @public
|
278
|
+
*/
|
279
|
+
protected invokeAsyncAPI<TResult>(api: () => Promise<TResult>, error: keyof (TEventDetailMap & TInternalEventDetailMap), success?: keyof (TEventDetailMap & TInternalEventDetailMap)): Promise<void>;
|
198
280
|
}
|
199
281
|
|
200
282
|
/**
|
@@ -242,11 +324,13 @@ export declare abstract class AbstractStoreRoot<TStore extends StoreRoot, TEvent
|
|
242
324
|
export declare const createErrorMap: <TErrorDetailMap extends ErrorDetailMap>(logger: ErrorMapLogger) => ErrorMap<TErrorDetailMap>;
|
243
325
|
|
244
326
|
/**
|
327
|
+
* @deprecated - Use `ErrorDetailMap` from `@genesislcap/foundation-utils` instead.
|
245
328
|
* @public
|
246
329
|
*/
|
247
330
|
export declare type ErrorDetailMap = Record<string, unknown>;
|
248
331
|
|
249
332
|
/**
|
333
|
+
* @deprecated - Use `ErrorMap` from `@genesislcap/foundation-utils` instead.
|
250
334
|
* @public
|
251
335
|
*/
|
252
336
|
export declare interface ErrorMap<TErrorDetailMap extends ErrorDetailMap> extends Pick<Map<keyof TErrorDetailMap, Error>, 'get' | 'has' | 'delete' | 'clear' | 'size'> {
|
@@ -268,10 +352,27 @@ export declare interface ErrorMap<TErrorDetailMap extends ErrorDetailMap> extend
|
|
268
352
|
}
|
269
353
|
|
270
354
|
/**
|
355
|
+
* @deprecated - Use `ErrorMapLogger` from `@genesislcap/foundation-utils` instead.
|
271
356
|
* @public
|
272
357
|
*/
|
273
358
|
export declare type ErrorMapLogger = (...args: any[]) => void;
|
274
359
|
|
360
|
+
/**
|
361
|
+
* @internal
|
362
|
+
*/
|
363
|
+
export declare enum EventListenerType {
|
364
|
+
sync = "sync",
|
365
|
+
async = "async",
|
366
|
+
error = "error"
|
367
|
+
}
|
368
|
+
|
369
|
+
/**
|
370
|
+
* @typeParam TEventDetailMaps - The store's complete event detail map.
|
371
|
+
*
|
372
|
+
* @internal
|
373
|
+
*/
|
374
|
+
export declare type KeyOrKeys<TEventDetailMaps extends EventDetailMap> = keyof TEventDetailMaps | (keyof TEventDetailMaps)[];
|
375
|
+
|
275
376
|
/**
|
276
377
|
* Creates a dependency injection key for the store being registered.
|
277
378
|
* @param Base - The store fragment class.
|
@@ -280,7 +381,7 @@ export declare type ErrorMapLogger = (...args: any[]) => void;
|
|
280
381
|
*
|
281
382
|
* @example
|
282
383
|
* ```ts
|
283
|
-
* export const TradeEntry = registerStore(DefaultTradeEntry, 'TradeEntry');
|
384
|
+
* export const TradeEntry = registerStore<TradeEntry>(DefaultTradeEntry, 'TradeEntry');
|
284
385
|
* ```
|
285
386
|
*
|
286
387
|
* @public
|
@@ -9,10 +9,44 @@ Creates an async event listener.
|
|
9
9
|
**Signature:**
|
10
10
|
|
11
11
|
```typescript
|
12
|
-
protected createAsyncListener: <TDetail = void, TReturn = void>(
|
12
|
+
protected createAsyncListener: <TDetail = void, TReturn = void>(keys: KeyOrKeys<TEventDetailMap & TInternalEventDetailMap>, token: (detail: TDetail, event?: CustomEvent<TDetail>) => Promise<TReturn>) => EventListener;
|
13
13
|
```
|
14
14
|
|
15
15
|
## Remarks
|
16
16
|
|
17
17
|
You can think of this like an `effect` in the redux sense. You should not commit values to the store in these, instead raise subsequent events to be handled synchronously, where commits are allowed.
|
18
18
|
|
19
|
+
## Example 1
|
20
|
+
|
21
|
+
Creating an interface defined handler for a single event key.
|
22
|
+
|
23
|
+
```ts
|
24
|
+
onDomainAction = this.createAsyncListener<DomainActionDetail>(
|
25
|
+
'domain-action',
|
26
|
+
async ({ id, message }) =>
|
27
|
+
this.invokeAsyncAPI(
|
28
|
+
async () => this.domainService.action(id, message),
|
29
|
+
'domain-action-error',
|
30
|
+
'domain-action-success'
|
31
|
+
)
|
32
|
+
);
|
33
|
+
```
|
34
|
+
|
35
|
+
## Example 2
|
36
|
+
|
37
|
+
Creating an anonymous handler in the constructor for multiple event keys.
|
38
|
+
|
39
|
+
```ts
|
40
|
+
this.createAsyncListener(
|
41
|
+
[
|
42
|
+
'columns-changed',
|
43
|
+
'types-changed',
|
44
|
+
'max-rows-changed',
|
45
|
+
'max-view-changed',
|
46
|
+
'order-by-changed',
|
47
|
+
'reverse-changed',
|
48
|
+
],
|
49
|
+
async (_, { type }) => this.emit('domain-load')
|
50
|
+
);
|
51
|
+
```
|
52
|
+
|
@@ -9,7 +9,7 @@ Creates an error event listener.
|
|
9
9
|
**Signature:**
|
10
10
|
|
11
11
|
```typescript
|
12
|
-
protected createErrorListener: <TDetail extends Error = Error>(
|
12
|
+
protected createErrorListener: <TDetail extends Error = Error>(keys: KeyOrKeys<TEventDetailMap & TInternalEventDetailMap>, token?: (detail: TDetail, event?: CustomEvent<TDetail>) => void) => EventListener;
|
13
13
|
```
|
14
14
|
|
15
15
|
## Remarks
|
@@ -9,7 +9,7 @@ Creates an event listener.
|
|
9
9
|
**Signature:**
|
10
10
|
|
11
11
|
```typescript
|
12
|
-
protected createListener: <TDetail = void>(
|
12
|
+
protected createListener: <TDetail = void>(keys: KeyOrKeys<TEventDetailMap & TInternalEventDetailMap>, token: (detail: TDetail, event?: CustomEvent<TDetail>) => void) => EventListener;
|
13
13
|
```
|
14
14
|
|
15
15
|
## Remarks
|
@@ -0,0 +1,46 @@
|
|
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) > [invokeAsyncAPI](./foundation-store.abstractstore.invokeasyncapi.md)
|
4
|
+
|
5
|
+
## AbstractStore.invokeAsyncAPI() method
|
6
|
+
|
7
|
+
A convenience method to invoke an async api and emit success and error events.
|
8
|
+
|
9
|
+
**Signature:**
|
10
|
+
|
11
|
+
```typescript
|
12
|
+
protected invokeAsyncAPI<TResult>(api: () => Promise<TResult>, error: keyof (TEventDetailMap & TInternalEventDetailMap), success?: keyof (TEventDetailMap & TInternalEventDetailMap)): Promise<void>;
|
13
|
+
```
|
14
|
+
|
15
|
+
## Parameters
|
16
|
+
|
17
|
+
| Parameter | Type | Description |
|
18
|
+
| --- | --- | --- |
|
19
|
+
| api | () => Promise<TResult> | The async service api function. |
|
20
|
+
| error | keyof (TEventDetailMap & TInternalEventDetailMap) | The event key from the store fragment's event detail map. |
|
21
|
+
| success | keyof (TEventDetailMap & TInternalEventDetailMap) | _(Optional)_ The event key from the store fragment's event detail map. |
|
22
|
+
|
23
|
+
**Returns:**
|
24
|
+
|
25
|
+
Promise<void>
|
26
|
+
|
27
|
+
## Remarks
|
28
|
+
|
29
|
+
The async api function should throw when it encounters an error.
|
30
|
+
|
31
|
+
## Example
|
32
|
+
|
33
|
+
|
34
|
+
```ts
|
35
|
+
onLoad = this.createAsyncListener('domain-load', async () =>
|
36
|
+
this.invokeAsyncAPI(
|
37
|
+
async () => {
|
38
|
+
!this.domainService.initialized && (await this.domainService.initialize(this.asDomainServiceInit()));
|
39
|
+
return this.domainService.list();
|
40
|
+
},
|
41
|
+
'domain-load-error',
|
42
|
+
'domain-load-success'
|
43
|
+
)
|
44
|
+
);
|
45
|
+
```
|
46
|
+
|
@@ -24,9 +24,9 @@ export declare abstract class AbstractStore<TStore extends Store, TEventDetailMa
|
|
24
24
|
| Property | Modifiers | Type | Description |
|
25
25
|
| --- | --- | --- | --- |
|
26
26
|
| [commit](./foundation-store.abstractstore.commit.md) | <p><code>protected</code></p><p><code>readonly</code></p> | this | **_(BETA)_** The value commit proxy. |
|
27
|
-
| [createAsyncListener](./foundation-store.abstractstore.createasynclistener.md) | <code>protected</code> | <TDetail = void, TReturn = void>(
|
28
|
-
| [createErrorListener](./foundation-store.abstractstore.createerrorlistener.md) | <code>protected</code> | <TDetail extends Error = Error>(
|
29
|
-
| [createListener](./foundation-store.abstractstore.createlistener.md) | <code>protected</code> | <TDetail = void>(
|
27
|
+
| [createAsyncListener](./foundation-store.abstractstore.createasynclistener.md) | <code>protected</code> | <TDetail = void, TReturn = void>(keys: KeyOrKeys<TEventDetailMap & TInternalEventDetailMap>, token: (detail: TDetail, event?: CustomEvent<TDetail>) => Promise<TReturn>) => EventListener | Creates an async event listener. |
|
28
|
+
| [createErrorListener](./foundation-store.abstractstore.createerrorlistener.md) | <code>protected</code> | <TDetail extends Error = Error>(keys: KeyOrKeys<TEventDetailMap & TInternalEventDetailMap>, token?: (detail: TDetail, event?: CustomEvent<TDetail>) => void) => EventListener | Creates an error event listener. |
|
29
|
+
| [createListener](./foundation-store.abstractstore.createlistener.md) | <code>protected</code> | <TDetail = void>(keys: KeyOrKeys<TEventDetailMap & TInternalEventDetailMap>, token: (detail: TDetail, event?: CustomEvent<TDetail>) => void) => EventListener | Creates an event listener. |
|
30
30
|
| [errors](./foundation-store.abstractstore.errors.md) | | ErrorMap<TEventDetailMap & TInternalEventDetailMap> | Contains any errors the store may have, see [ErrorMap](./foundation-store.errormap.md)<!-- -->. |
|
31
31
|
| [name](./foundation-store.abstractstore.name.md) | <code>readonly</code> | string | The name of the store fragment. |
|
32
32
|
| [root](./foundation-store.abstractstore.root.md) | <code>protected</code> | TStoreRoot | The store root fragment. |
|
@@ -43,4 +43,5 @@ export declare abstract class AbstractStore<TStore extends Store, TEventDetailMa
|
|
43
43
|
| [connect(root)](./foundation-store.abstractstore.connect.md) | | Connects this store fragment. |
|
44
44
|
| [disconnect(root)](./foundation-store.abstractstore.disconnect.md) | | Disconnects this store fragment. |
|
45
45
|
| [emit(args)](./foundation-store.abstractstore.emit.md) | <code>protected</code> | Emit events to the stores directly via the standard event flow. |
|
46
|
+
| [invokeAsyncAPI(api, error, success)](./foundation-store.abstractstore.invokeasyncapi.md) | <code>protected</code> | A convenience method to invoke an async api and emit success and error events. |
|
46
47
|
|