@fireflysemantics/slice 17.0.13 → 17.0.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -4
- package/esm2022/lib/AbstractStore.mjs +17 -14
- package/esm2022/lib/EStore.mjs +203 -139
- package/esm2022/lib/OStore.mjs +1 -1
- package/esm2022/lib/Slice.mjs +10 -10
- package/fesm2022/fireflysemantics-slice.mjs +227 -160
- package/fesm2022/fireflysemantics-slice.mjs.map +1 -1
- package/lib/AbstractStore.d.ts +16 -13
- package/lib/EStore.d.ts +182 -116
- package/lib/OStore.d.ts +1 -1
- package/lib/Slice.d.ts +9 -9
- package/package.json +1 -1
package/lib/EStore.d.ts
CHANGED
@@ -7,39 +7,46 @@ import { Slice } from './Slice';
|
|
7
7
|
* This `todoFactory` code will be used to illustrate the API examples. The following
|
8
8
|
* utilities are used in the tests and the API Typedoc examples contained here.
|
9
9
|
* @example Utilities for API Examples
|
10
|
-
```
|
11
|
-
export const enum TodoSliceEnum {
|
12
|
-
|
13
|
-
|
14
|
-
}
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
10
|
+
* ```
|
11
|
+
* export const enum TodoSliceEnum {
|
12
|
+
* COMPLETE = "Complete",
|
13
|
+
* INCOMPLETE = "Incomplete"
|
14
|
+
* }
|
15
|
+
* export class Todo {
|
16
|
+
* constructor(
|
17
|
+
* public complete: boolean,
|
18
|
+
* public title: string,
|
19
|
+
* public gid?:string,
|
20
|
+
* public id?:string) {}
|
21
|
+
* }
|
22
|
+
*
|
23
|
+
* export let todos = [new Todo(false, "You complete me!"), new Todo(true, "You completed me!")];
|
24
|
+
*
|
25
|
+
* export function todosFactory():Todo[] {
|
26
|
+
* return [new Todo(false, "You complete me!"), new Todo(true, "You completed me!")];
|
27
|
+
* }
|
28
|
+
* ```
|
26
29
|
*/
|
27
30
|
export declare class EStore<E> extends AbstractStore<E> {
|
28
31
|
/**
|
29
32
|
* Store constructor (Initialization with element is optional)
|
30
33
|
*
|
31
34
|
* perform initial notification to all observers,
|
32
|
-
* such that
|
35
|
+
* such that functions like {@link combineLatest}{}
|
33
36
|
* will execute at least once.
|
34
|
-
*
|
35
|
-
* @
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
37
|
+
*
|
38
|
+
* @param entities The entities to initialize the store with.
|
39
|
+
* @param config The optional configuration instance.
|
40
|
+
*
|
41
|
+
* @example EStore<Todo> Creation
|
42
|
+
* ```
|
43
|
+
* // Initialize the Store
|
44
|
+
* let store: EStore<Todo> = new EStore<Todo>(todosFactory());
|
45
|
+
* ```
|
46
|
+
*/
|
40
47
|
constructor(entities?: E[], config?: StoreConfig);
|
41
48
|
/**
|
42
|
-
* Calls complete on all {@link
|
49
|
+
* Calls complete on all EStore {@link ReplaySubject} instances.
|
43
50
|
*
|
44
51
|
* Call destroy when disposing of the store.
|
45
52
|
*/
|
@@ -51,16 +58,15 @@ export declare class EStore<E> extends AbstractStore<E> {
|
|
51
58
|
* it will be deleted. If the store
|
52
59
|
* does not contains the entity,
|
53
60
|
* it is added.
|
54
|
-
* @param e
|
55
|
-
* @example Toggle the
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
```
|
61
|
+
* @param e The entity to toggle
|
62
|
+
* @example Toggle the Todo instance
|
63
|
+
* ```
|
64
|
+
* estore.post(todo);
|
65
|
+
* // Remove todo
|
66
|
+
* estore.toggle(todo);
|
67
|
+
* // Add it back
|
68
|
+
* estore.toggle(todo);
|
69
|
+
* ```
|
64
70
|
*/
|
65
71
|
toggle(e: E): void;
|
66
72
|
/**
|
@@ -84,26 +90,26 @@ export declare class EStore<E> extends AbstractStore<E> {
|
|
84
90
|
* change detection in the event that it maintains
|
85
91
|
* a reference to the `active` state `Map` instance.
|
86
92
|
*
|
87
|
-
* @example Add
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
93
|
+
* @example Add todo1 and todo2 as active
|
94
|
+
* ```
|
95
|
+
* addActive(todo1);
|
96
|
+
* addActive(todo2);
|
97
|
+
* ```
|
92
98
|
*/
|
93
99
|
addActive(e: E): void;
|
94
100
|
/**
|
95
|
-
* Delete an entity
|
101
|
+
* Delete an active entity.
|
96
102
|
*
|
97
103
|
* Also we clone the map prior to broadcasting it with
|
98
104
|
* `notifyActive` to make sure we will trigger Angular
|
99
105
|
* change detection in the event that it maintains
|
100
106
|
* a reference to the `active` state `Map` instance.
|
101
107
|
*
|
102
|
-
* @example
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
108
|
+
* @example Remove todo1 and todo2 as active entities
|
109
|
+
* ```
|
110
|
+
* deleteActive(todo1);
|
111
|
+
* deleteActive(todo2);
|
112
|
+
* ```
|
107
113
|
*/
|
108
114
|
deleteActive(e: E): void;
|
109
115
|
/**
|
@@ -114,20 +120,20 @@ export declare class EStore<E> extends AbstractStore<E> {
|
|
114
120
|
* change detection in the event that it maintains
|
115
121
|
* a reference to the `active` state `Map` instance.
|
116
122
|
*
|
117
|
-
* @example
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
```
|
123
|
+
* @example Clear active todo instances
|
124
|
+
* ```
|
125
|
+
* store.clearActive();
|
126
|
+
* ```
|
122
127
|
*/
|
123
128
|
clearActive(): void;
|
124
129
|
/**
|
125
|
-
* Observe the active
|
130
|
+
* Observe the active entities.
|
131
|
+
*
|
126
132
|
* @example
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
133
|
+
* ```
|
134
|
+
* let active$ = store.observeActive();
|
135
|
+
* ```
|
136
|
+
*/
|
131
137
|
observeActive(): Observable<Map<string, E>>;
|
132
138
|
/**
|
133
139
|
* Observe the active entity.
|
@@ -169,24 +175,81 @@ export declare class EStore<E> extends AbstractStore<E> {
|
|
169
175
|
set loading(loading: boolean);
|
170
176
|
/**
|
171
177
|
* @return A snapshot of the loading state.
|
178
|
+
* @example Create a reference to the loading state
|
179
|
+
* ```
|
180
|
+
* const loading:boolean = todoStore.loading;
|
181
|
+
* ```
|
172
182
|
*/
|
173
183
|
get loading(): boolean;
|
174
184
|
/**
|
175
185
|
* Observe loading.
|
186
|
+
*
|
187
|
+
* Note that this obverable piped through
|
188
|
+
* `takeWhile(v->v, true), such that it will
|
189
|
+
* complete after each emission.
|
190
|
+
*
|
191
|
+
* See:
|
192
|
+
* https://fireflysemantics.medium.com/waiting-on-estore-to-load-8dcbe161613c
|
193
|
+
*
|
194
|
+
* For more details.
|
195
|
+
* Also note that v=>v is the same as v=>v!=false
|
196
|
+
*
|
176
197
|
* @example
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
198
|
+
* ```
|
199
|
+
* const observeLoadingHandler: Observer<boolean> = {
|
200
|
+
* complete: () => {
|
201
|
+
* console.log(`Data Loaded and Observable Marked as Complete`);
|
202
|
+
* }, // completeHandler
|
203
|
+
* error: () => {
|
204
|
+
* console.log(`Any Errors?`);
|
205
|
+
* }, // errorHandler
|
206
|
+
* next: (l) => {
|
207
|
+
* console.log(`Data loaded and loading is ${l}`);
|
208
|
+
* },
|
209
|
+
* };
|
210
|
+
*
|
211
|
+
* const observeLoadingResubscribeHandler: Observer<boolean> = {
|
212
|
+
* complete: () => {
|
213
|
+
* console.log(`Data Loaded and Resubscribe Observable Marked as Complete`);
|
214
|
+
* }, // completeHandler
|
215
|
+
* error: () => {
|
216
|
+
* console.log(`Any Resubscribe Errors?`);
|
217
|
+
* }, // errorHandler
|
218
|
+
* next: (l) => {
|
219
|
+
* console.log(`Data loaded and resusbscribe loading value is ${l}`);
|
220
|
+
* },
|
221
|
+
* };
|
222
|
+
*
|
223
|
+
* const todoStore: EStore<Todo> = new EStore();
|
224
|
+
* //============================================
|
225
|
+
* // Loading is true by default
|
226
|
+
* //============================================
|
227
|
+
* console.log(`The initial value of loading is ${todoStore.loading}`);
|
228
|
+
* //============================================
|
229
|
+
* // Observe Loading
|
230
|
+
* //============================================
|
231
|
+
* let loading$: Observable<boolean> = todoStore.observeLoading();
|
232
|
+
* loading$.subscribe((l) => console.log(`The value of loading is ${l}`));
|
233
|
+
*
|
234
|
+
* todoStore.loading = false;
|
235
|
+
* loading$.subscribe(observeLoadingHandler);
|
236
|
+
* //============================================
|
237
|
+
* // The subscription no longer fires
|
238
|
+
* //============================================
|
239
|
+
* todoStore.loading = true;
|
240
|
+
* todoStore.loading = false;
|
241
|
+
*
|
242
|
+
* //============================================
|
243
|
+
* // The subscription no longer fires,
|
244
|
+
* // so if we want to observe loading again
|
245
|
+
* // resusbscribe.
|
246
|
+
* //============================================
|
247
|
+
* todoStore.loading = true;
|
248
|
+
* loading$ = todoStore.observeLoading();
|
249
|
+
* loading$.subscribe(observeLoadingResubscribeHandler);
|
250
|
+
* todoStore.loading = false;
|
251
|
+
* ```
|
252
|
+
*/
|
190
253
|
observeLoading(): Observable<boolean>;
|
191
254
|
/**
|
192
255
|
* Notfiies when loading has completed.
|
@@ -282,92 +345,95 @@ export declare class EStore<E> extends AbstractStore<E> {
|
|
282
345
|
/**
|
283
346
|
* Post (Add a new) element(s) to the store.
|
284
347
|
* @param e An indiidual entity or an array of entities
|
285
|
-
* @example Post a
|
286
|
-
|
287
|
-
|
288
|
-
|
348
|
+
* @example Post a Todo instance.
|
349
|
+
*
|
350
|
+
*```
|
351
|
+
* store.post(todo);
|
352
|
+
*```
|
289
353
|
*/
|
290
354
|
post(e: E | E[]): void;
|
291
355
|
/**
|
292
|
-
* Post
|
356
|
+
* Post N entities to the store.
|
293
357
|
* @param ...e
|
294
|
-
* @example Post two
|
295
|
-
|
296
|
-
|
297
|
-
|
358
|
+
* @example Post two Todo instances.
|
359
|
+
* ```
|
360
|
+
* store.post(todo1, todo2);
|
361
|
+
* ```
|
298
362
|
*/
|
299
363
|
postN(...e: E[]): void;
|
300
364
|
/**
|
301
365
|
* Post (Add) an array of elements to the store.
|
302
366
|
* @param e
|
303
|
-
* @example Post a
|
304
|
-
|
305
|
-
|
306
|
-
|
367
|
+
* @example Post a Todo array.
|
368
|
+
*
|
369
|
+
* ```
|
370
|
+
* store.post([todo1, todo2]);
|
371
|
+
* ```
|
307
372
|
*/
|
308
373
|
postA(e: E[]): void;
|
309
374
|
/**
|
310
|
-
* Put (Update) an
|
375
|
+
* Put (Update) an entity.
|
311
376
|
* @param e
|
312
377
|
* @example Put a Todo instance.
|
313
|
-
|
314
|
-
|
315
|
-
|
378
|
+
* ```
|
379
|
+
* store.put(todo1);
|
380
|
+
* ```
|
316
381
|
*/
|
317
382
|
put(e: E | E[]): void;
|
318
383
|
/**
|
319
384
|
* Put (Update) an element or add an element that was read from a persistence source
|
320
385
|
* and thus already has an assigned global id`.
|
321
|
-
* @param e
|
322
|
-
* @example Put Todo instances.
|
323
|
-
|
324
|
-
|
325
|
-
|
386
|
+
* @param e The enetity instances to update.
|
387
|
+
* @example Put N Todo instances.
|
388
|
+
*
|
389
|
+
* ```
|
390
|
+
* store.put(todo1, todo2);
|
391
|
+
* ```
|
326
392
|
*/
|
327
393
|
putN(...e: E[]): void;
|
328
394
|
/**
|
329
|
-
* Put (Update) the array of
|
330
|
-
* @param e
|
331
|
-
* @example Put Todo instances.
|
332
|
-
|
333
|
-
|
334
|
-
|
395
|
+
* Put (Update) the array of enntities.
|
396
|
+
* @param e The array of enntities to update
|
397
|
+
* @example Put an array of Todo instances.
|
398
|
+
* ```
|
399
|
+
* store.put([todo1, todo2]);
|
400
|
+
* ```
|
335
401
|
*/
|
336
402
|
putA(e: E[]): void;
|
337
403
|
/**
|
338
404
|
* Delete (Update) the array of elements.
|
339
405
|
* @param e
|
340
406
|
* @example Delete todo1.
|
341
|
-
|
342
|
-
|
343
|
-
|
407
|
+
* ```
|
408
|
+
* store.delete(todo1]);
|
409
|
+
* ```
|
344
410
|
*/
|
345
411
|
delete(e: E | E[]): void;
|
346
412
|
/**
|
347
413
|
* Delete N elements.
|
348
414
|
* @param ...e
|
349
|
-
* @example
|
350
|
-
|
351
|
-
|
352
|
-
|
415
|
+
* @example Delete N Todo instance argument.
|
416
|
+
* ```
|
417
|
+
* store.deleteN(todo1, todo2);
|
418
|
+
* ```
|
353
419
|
*/
|
354
420
|
deleteN(...e: E[]): void;
|
355
421
|
/**
|
356
|
-
* Delete
|
357
|
-
* @param
|
358
|
-
* @example
|
359
|
-
|
360
|
-
|
361
|
-
|
422
|
+
* Delete an array of elements.
|
423
|
+
* @param e The array of instances to be deleted
|
424
|
+
* @example Delete the array of Todo instances.
|
425
|
+
* ```
|
426
|
+
* store.deleteA([todo1, todo2]);
|
427
|
+
* ```
|
362
428
|
*/
|
363
429
|
deleteA(e: E[]): void;
|
364
430
|
/**
|
365
431
|
* Delete elements by {@link Predicate}.
|
366
432
|
* @param p The predicate.
|
367
|
-
* @example
|
368
|
-
|
369
|
-
|
370
|
-
|
433
|
+
* @example Delete the Todo instances.
|
434
|
+
* ```
|
435
|
+
* store.delete(todo1, todo2);
|
436
|
+
* ```
|
371
437
|
*/
|
372
438
|
deleteP(p: Predicate<E>): void;
|
373
439
|
/**
|
@@ -391,9 +457,9 @@ export declare class EStore<E> extends AbstractStore<E> {
|
|
391
457
|
* send their own delta notification.
|
392
458
|
*
|
393
459
|
* @example Reset the store.
|
394
|
-
|
395
|
-
|
396
|
-
|
460
|
+
* ```
|
461
|
+
* store.reset();
|
462
|
+
* ```
|
397
463
|
*/
|
398
464
|
reset(): void;
|
399
465
|
/**
|
package/lib/OStore.d.ts
CHANGED
package/lib/Slice.d.ts
CHANGED
@@ -16,15 +16,15 @@ export declare class Slice<E> extends AbstractStore<E> {
|
|
16
16
|
* @param eStore The EStore instance containing the elements considered for slicing
|
17
17
|
*
|
18
18
|
* @example
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
19
|
+
* ```
|
20
|
+
* //Empty slice
|
21
|
+
* new Slice<Todo>(Todo.COMPLETE, todo=>!todo.complete);
|
22
|
+
*
|
23
|
+
* //Initialized slice
|
24
|
+
* let todos = [new Todo(false, "You complete me!"),
|
25
|
+
* new Todo(true, "You completed me!")];
|
26
|
+
* new Slice<Todo>(Todo.COMPLETE, todo=>!todo.complete, todos);
|
27
|
+
* ```
|
28
28
|
*/
|
29
29
|
constructor(label: string, predicate: Predicate<E>, eStore: EStore<E>);
|
30
30
|
/**
|