@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
package/README.md
CHANGED
@@ -169,14 +169,13 @@ class DefaultStore extends AbstractStoreRoot<Store, StoreEventDetailMap, Interna
|
|
169
169
|
*/
|
170
170
|
onFooEvent = this.createListener('store-foo', detail => {...});
|
171
171
|
onBarEvent = this.createListener<boolean>('store-bar', detail => this.commit.someToggle = detail); // < commit values to the store synchronously
|
172
|
-
onZooEvent = this.createAsyncListener<StoreZooEventDetail>('store-zoo', async (detail) =>
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
});
|
172
|
+
onZooEvent = this.createAsyncListener<StoreZooEventDetail>('store-zoo', async (detail) =>
|
173
|
+
this.invokeAsyncAPI(
|
174
|
+
async () => this.someAsyncTask(detail), // < likely an injected service,
|
175
|
+
'store-zoo-error',
|
176
|
+
'store-zoo-success'
|
177
|
+
)
|
178
|
+
);
|
180
179
|
|
181
180
|
/**
|
182
181
|
* 9: Create getters for common derived data needs, similar to selectors in the Redux sense. These however do not
|
@@ -197,7 +196,7 @@ class DefaultStore extends AbstractStoreRoot<Store, StoreEventDetailMap, Interna
|
|
197
196
|
/**
|
198
197
|
* 10: Register the store which defines the DI key using the interface
|
199
198
|
*/
|
200
|
-
export const Store = registerStore(DefaultStore, 'RootStore');
|
199
|
+
export const Store = registerStore<Store>(DefaultStore, 'RootStore');
|
201
200
|
```
|
202
201
|
|
203
202
|
Your root store is now ready to be injected into your application. Hopefully the above gives you a good idea of general
|
@@ -225,7 +224,7 @@ class DefaultTradeEntryUI extends AbstractStore<TradeEntryUI, TradeEntryUIEventD
|
|
225
224
|
onOpen = this.createListener<boolean>('trade-entry-ui-open', detail => this.commit.isOpen = detail);
|
226
225
|
}
|
227
226
|
|
228
|
-
export const TradeEntryUI = registerStore(DefaultTradeEntryUI, 'TradeEntryUI');
|
227
|
+
export const TradeEntryUI = registerStore<TradeEntryUI>(DefaultTradeEntryUI, 'TradeEntryUI');
|
229
228
|
```
|
230
229
|
|
231
230
|
## Store events
|
@@ -235,36 +234,81 @@ export const TradeEntryUI = registerStore(DefaultTradeEntryUI, 'TradeEntryUI');
|
|
235
234
|
In your main application class, likely `./src/main/main.ts`, you need to fire a `'store-connected'` event in-order to
|
236
235
|
fully initialise the store.
|
237
236
|
|
238
|
-
For example:
|
239
|
-
|
240
237
|
```typescript
|
241
238
|
// ./main/main.ts
|
242
239
|
|
243
240
|
type EventMap = StoreEventDetailMap & {...}; // < whatever other events you allow your custom element to emit
|
244
241
|
|
245
|
-
|
242
|
+
/**
|
243
|
+
* MainApplication
|
244
|
+
*
|
245
|
+
* @fires store-connected - Fires a custom 'store-connected' event after connection to connect the store.
|
246
|
+
* @fires store-ready - Fires a custom 'store-ready' event after connection to ready the store.
|
247
|
+
* @fires store-disconnected - Fires a custom 'store-disconnected' event after disconnection to unbind the store.
|
248
|
+
*
|
249
|
+
* @public
|
250
|
+
*/
|
251
|
+
@customElement({ name, template, styles })
|
246
252
|
export class MainApplication extends EventEmitter<EventMap>(FASTElement) {
|
247
|
-
|
248
|
-
|
253
|
+
/**
|
254
|
+
* @public
|
255
|
+
*/
|
256
|
+
@Store store: Store; // < injected root store
|
257
|
+
|
258
|
+
/**
|
259
|
+
* @public
|
260
|
+
*/
|
249
261
|
connectedCallback() {
|
250
262
|
super.connectedCallback();
|
251
|
-
this
|
263
|
+
this.addEventListeners();
|
264
|
+
this.readyStore();
|
252
265
|
}
|
253
|
-
}
|
254
|
-
```
|
255
266
|
|
256
|
-
|
267
|
+
/**
|
268
|
+
* @public
|
269
|
+
*/
|
270
|
+
disconnectedCallback() {
|
271
|
+
super.disconnectedCallback();
|
272
|
+
this.removeEventListeners();
|
273
|
+
this.disconnectStore();
|
274
|
+
}
|
257
275
|
|
258
|
-
|
259
|
-
|
276
|
+
/**
|
277
|
+
* @internal
|
278
|
+
*/
|
279
|
+
protected addEventListeners() {
|
280
|
+
this.addEventListener('store-connected', this.store.onConnected);
|
281
|
+
}
|
260
282
|
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
283
|
+
/**
|
284
|
+
* @internal
|
285
|
+
*/
|
286
|
+
protected removeEventListeners() {
|
287
|
+
this.removeEventListener('store-connected', this.store.onConnected);
|
288
|
+
}
|
289
|
+
|
290
|
+
/**
|
291
|
+
* @internal
|
292
|
+
*/
|
293
|
+
protected readyStore() {
|
294
|
+
this.$emit('store-connected', this);
|
295
|
+
/**
|
296
|
+
* Do some other work if needed.
|
297
|
+
*/
|
298
|
+
this.$emit('store-ready', true);
|
299
|
+
}
|
300
|
+
|
301
|
+
/**
|
302
|
+
* @internal
|
303
|
+
*/
|
304
|
+
protected disconnectStore() {
|
305
|
+
this.$emit('store-disconnected');
|
306
|
+
}
|
307
|
+
}
|
265
308
|
```
|
266
309
|
|
267
|
-
|
310
|
+
The `'store-connected'` event handler needs to be explicitly bound. When the root store handles `'store-connected'`,
|
311
|
+
it auto binds all the store event listeners to the rootElement.
|
268
312
|
|
269
313
|
At this point you can start emitting strongly typed store events, and they will be handled by their corresponding store.
|
270
314
|
See [EventEmitter](src/.foundation/events/eventEmitter/README.md) for more information.
|
@@ -278,11 +322,26 @@ do, you can just emit this right after `'store-connected'`.
|
|
278
322
|
```typescript
|
279
323
|
// ./main/main.ts
|
280
324
|
|
281
|
-
this.$emit('store-connected', this
|
282
|
-
|
325
|
+
this.$emit('store-connected', this);
|
326
|
+
/**
|
327
|
+
* Do some other work if needed.
|
328
|
+
*/
|
283
329
|
this.$emit('store-ready', true);
|
284
330
|
```
|
285
331
|
|
332
|
+
### `'store-disconnected'`
|
333
|
+
|
334
|
+
Emitting `'store-disconnected'` will remove all the previously bound event listeners.
|
335
|
+
|
336
|
+
```typescript
|
337
|
+
// ./main/main.ts
|
338
|
+
|
339
|
+
disconnectedCallback() {
|
340
|
+
super.disconnectedCallback();
|
341
|
+
this.$emit('store-disconnected');
|
342
|
+
}
|
343
|
+
```
|
344
|
+
|
286
345
|
## Using store fragments
|
287
346
|
|
288
347
|
To use a store fragment in your custom element simply inject it using its `interface` as the DI key.
|
@@ -425,14 +484,13 @@ constructor(
|
|
425
484
|
this.createErrorListener('trades-load-error', () => this.commit.trades = undefined);
|
426
485
|
}
|
427
486
|
|
428
|
-
onTradesLoad = this.createAsyncListener<string>('trades-load', async (positionId) =>
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
});
|
487
|
+
onTradesLoad = this.createAsyncListener<string>('trades-load', async (positionId) =>
|
488
|
+
this.invokeAsyncAPI(
|
489
|
+
async () => this.service.getTrades(positionId),
|
490
|
+
'trades-load-error',
|
491
|
+
'trades-load-success'
|
492
|
+
)
|
493
|
+
);
|
436
494
|
```
|
437
495
|
|
438
496
|
### Errors
|