tsdf 8.0.0-beta.1 → 8.0.0-beta.11

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.
Files changed (57) hide show
  1. package/dist/main.cjs +1860 -0
  2. package/dist/main.d.ts +291 -0
  3. package/dist/main.js +1825 -0
  4. package/package.json +6 -2
  5. package/.eslintignore +0 -3
  6. package/.eslintrc.cjs +0 -119
  7. package/.gitattributes +0 -22
  8. package/.prettierrc +0 -6
  9. package/.vscode/settings.json +0 -3
  10. package/.vscode/tasks.json +0 -35
  11. package/fetch-orquestrator-scenarios.excalidraw +0 -10115
  12. package/scripts/check-if-is-sync.sh +0 -6
  13. package/src/collectionFetchOrquestrator.ts +0 -23
  14. package/src/collectionStore.ts +0 -608
  15. package/src/documentStore.ts +0 -272
  16. package/src/fetchOrquestrator.ts +0 -335
  17. package/src/listQueryStore.ts +0 -1190
  18. package/src/main.ts +0 -22
  19. package/src/storeShared.ts +0 -5
  20. package/src/useEnsureIsLoaded.ts +0 -50
  21. package/src/utils/filterAndMap.ts +0 -20
  22. package/src/utils/getCacheId.ts +0 -19
  23. package/src/utils/hooks.ts +0 -110
  24. package/src/utils/isObject.ts +0 -3
  25. package/src/utils/math.ts +0 -7
  26. package/src/utils/serializableClone.ts +0 -3
  27. package/src/utils/useLatestValue.ts +0 -16
  28. package/test/__snapshots__/listQueryStore.test.ts.snap +0 -146
  29. package/test/__snapshots__/listQueryStoreHooks.test.ts.snap +0 -9
  30. package/test/collectionStore.test.ts +0 -523
  31. package/test/collectionStoreHooks.test.tsx +0 -651
  32. package/test/documentStore.test.ts +0 -183
  33. package/test/documentStoreHooks.test.tsx +0 -857
  34. package/test/fetchOrquestrator.test.ts +0 -913
  35. package/test/listQueryStore.test.ts +0 -1158
  36. package/test/listQueryStoreHooks.test.tsx +0 -662
  37. package/test/listQueryStoreHooks2.test.tsx +0 -483
  38. package/test/listQueryStoreHooksMutations.test.tsx +0 -764
  39. package/test/mocks/fetchMock.ts +0 -296
  40. package/test/mocks/fetchOrquestratorEnv.ts +0 -370
  41. package/test/setup/setup.ts +0 -109
  42. package/test/testHelpers.test.ts +0 -88
  43. package/test/utils/RenderObjValues.tsx +0 -23
  44. package/test/utils/arrayUtils.ts +0 -13
  45. package/test/utils/createDefaultListQueryStore.ts +0 -275
  46. package/test/utils/createOrVariations.ts +0 -48
  47. package/test/utils/dedent.ts +0 -50
  48. package/test/utils/delayCall.ts +0 -25
  49. package/test/utils/math.ts +0 -3
  50. package/test/utils/objectUtils.ts +0 -18
  51. package/test/utils/range.ts +0 -19
  52. package/test/utils/sleep.ts +0 -3
  53. package/test/utils/storeUtils.ts +0 -460
  54. package/tsconfig.json +0 -24
  55. package/tsconfig.prod.json +0 -9
  56. package/tsup.config.ts +0 -12
  57. package/vitest.config.ts +0 -10
@@ -1,913 +0,0 @@
1
- import { describe, expect, test } from 'vitest';
2
- import { createTestStore, TestStore } from './mocks/fetchOrquestratorEnv';
3
- import { delayCall, waitTimeline } from './utils/delayCall';
4
- import { sleep } from './utils/sleep';
5
-
6
- /** default time 60ms */
7
- async function action(
8
- store: TestStore,
9
- newValue: number,
10
- {
11
- withRevalidation,
12
- withOptimisticUpdate,
13
- duration,
14
- revalidationDuration,
15
- triggerRTU,
16
- }: {
17
- withRevalidation?: boolean;
18
- withOptimisticUpdate?: boolean;
19
- duration?: number;
20
- revalidationDuration?: number;
21
- triggerRTU?: boolean;
22
- } = {},
23
- ) {
24
- if (withOptimisticUpdate) {
25
- store.optimisticUpdate(newValue);
26
- }
27
-
28
- const endMutation = store.startMutation();
29
-
30
- await store.mutateData(newValue, {
31
- duration,
32
- onServerDataChange: triggerRTU
33
- ? async () => {
34
- await sleep(5);
35
-
36
- store.fetch('realtimeUpdate', revalidationDuration);
37
- }
38
- : undefined,
39
- addServerDataChangeAction: triggerRTU,
40
- });
41
-
42
- endMutation();
43
-
44
- if (withRevalidation && !triggerRTU) {
45
- store.fetch('highPriority', revalidationDuration);
46
- }
47
- }
48
-
49
- test.concurrent(
50
- 'simple mutation with revalidation and optimistic update',
51
- async () => {
52
- const store = createTestStore(0);
53
-
54
- await action(store, 1, {
55
- withRevalidation: true,
56
- withOptimisticUpdate: true,
57
- });
58
-
59
- await store.waitForNoPendingRequests();
60
-
61
- expect(store.ui.history).toEqual([0, 1, 1]);
62
-
63
- expect(store.actions).toMatchTimeline(`
64
- "
65
- 1 - optimistic-ui-commit
66
- 1 - mutation-started
67
- 1 - mutation-finished
68
- fetch-started : 1
69
- 1 - fetch-finished : 1
70
- 1 - fetch-ui-commit
71
- "
72
- `);
73
- },
74
- );
75
-
76
- test.concurrent('simple mutation with optimistic update', async () => {
77
- const store = createTestStore(0);
78
-
79
- await action(store, 1, {
80
- withOptimisticUpdate: true,
81
- });
82
-
83
- await store.waitForNoPendingRequests();
84
-
85
- expect(store.ui.history).toEqual([0, 1]);
86
-
87
- expect(store.actions).toMatchTimeline(`
88
- "
89
- 1 - optimistic-ui-commit
90
- 1 - mutation-started
91
- 1 - mutation-finished
92
- "
93
- `);
94
- });
95
-
96
- test.concurrent('simple mutation without optimistic update', async () => {
97
- const store = createTestStore(0);
98
-
99
- await action(store, 1, {
100
- withRevalidation: true,
101
- });
102
-
103
- await store.waitForNoPendingRequests();
104
-
105
- expect(store.ui.history).toEqual([0, 1]);
106
-
107
- expect(store.actions).toMatchTimeline(`
108
- "
109
- 1 - mutation-started
110
- 1 - mutation-finished
111
- fetch-started : 1
112
- 1 - fetch-finished : 1
113
- 1 - fetch-ui-commit
114
- "
115
- `);
116
- });
117
-
118
- test.concurrent('prevent overfetch of low priority fetchs', async () => {
119
- const store = createTestStore(0);
120
-
121
- const promises = [
122
- delayCall(0, () => store.fetch('lowPriority')),
123
- delayCall(10, () => store.fetch('lowPriority')),
124
- delayCall(20, () => store.fetch('lowPriority')),
125
- delayCall(30, () => store.fetch('lowPriority')),
126
- ];
127
-
128
- await Promise.all(promises);
129
-
130
- await store.waitForNoPendingRequests();
131
-
132
- expect(store.numOfFetchs).toBe(1);
133
- expect(store.actions).toMatchTimeline(`
134
- "
135
- fetch-started : 1
136
- fetch-skipped
137
- fetch-skipped
138
- fetch-skipped
139
- fetch-finished : 1
140
- fetch-ui-commit
141
- "
142
- `);
143
- });
144
-
145
- test.concurrent(
146
- 'multiple mutations with revalidation in sequence',
147
- async () => {
148
- const store = createTestStore(0);
149
-
150
- const promises = [
151
- delayCall(0, () =>
152
- action(store, 1, {
153
- withOptimisticUpdate: true,
154
- withRevalidation: true,
155
- }),
156
- ),
157
- delayCall(110, () =>
158
- action(store, 2, {
159
- withOptimisticUpdate: true,
160
- withRevalidation: true,
161
- }),
162
- ),
163
- ];
164
-
165
- await Promise.all(promises);
166
-
167
- await store.waitForNoPendingRequests();
168
-
169
- expect(store.ui.changesHistory).toEqual([0, 1, 2]);
170
- expect(store.actions).toMatchTimeline(`
171
- "
172
- 1 - optimistic-ui-commit
173
- 1 - mutation-started
174
- 1 - mutation-finished
175
- fetch-started : 1
176
- 1 - fetch-finished : 1
177
- 1 - fetch-ui-commit
178
- 2 - optimistic-ui-commit
179
- 2 - mutation-started
180
- 2 - mutation-finished
181
- fetch-started : 2
182
- 2 - fetch-finished : 2
183
- 2 - fetch-ui-commit
184
- "
185
- `);
186
- },
187
- );
188
-
189
- test.concurrent(
190
- 'multiple mutations with revalidation in sequence 2',
191
- async () => {
192
- const store = createTestStore(0);
193
-
194
- const mutateValue = (value: number, revalidationDuration: number) =>
195
- action(store, value, {
196
- withOptimisticUpdate: true,
197
- withRevalidation: true,
198
- duration: 60,
199
- revalidationDuration,
200
- });
201
-
202
- const promises = [
203
- delayCall(0, () => store.fetch('lowPriority', 438)),
204
- delayCall(7, () => mutateValue(1, 400)),
205
- delayCall(283, () => mutateValue(2, 476)),
206
- delayCall(536, () => mutateValue(3, 400)),
207
- delayCall(781, () => mutateValue(4, 407)),
208
- delayCall(1_030, () => mutateValue(4, 233)),
209
- ];
210
-
211
- await Promise.all(promises);
212
-
213
- await store.waitForNoPendingRequests();
214
-
215
- await sleep(200);
216
-
217
- expect(store.ui.changesHistory).toEqual([0, 1, 2, 3, 4]);
218
- expect(store.actions).toMatchTimeline(`
219
- "
220
- fetch-started : 1
221
-
222
- 1 - optimistic-ui-commit
223
- 1 - mutation-started
224
- 1 - mutation-finished
225
-
226
- fetch-started : 2
227
-
228
- 2 - optimistic-ui-commit
229
- 2 - mutation-started
230
- 2 - mutation-finished
231
-
232
- fetch-started : 3
233
- fetch-aborted : 1
234
- fetch-aborted : 2
235
-
236
- 3 - optimistic-ui-commit
237
- 3 - mutation-started
238
- 3 - mutation-finished
239
-
240
- fetch-started : 4
241
-
242
- 4 - optimistic-ui-commit
243
- 4 - mutation-started
244
- ---
245
- fetch-aborted : 3
246
- 4 - mutation-finished
247
- OR
248
- 4 - mutation-finished
249
- fetch-aborted : 3
250
- ---
251
-
252
- fetch-started : 5
253
- fetch-aborted : 4
254
-
255
- 4 - optimistic-ui-commit
256
- 4 - mutation-started
257
- 4 - mutation-finished
258
-
259
- fetch-started : 6
260
- fetch-aborted : 5
261
- 4 - fetch-finished : 6
262
- 4 - fetch-ui-commit
263
- "
264
- `);
265
-
266
- expect(store.numOfFetchs).toBe(6);
267
- },
268
- );
269
-
270
- test.concurrent(
271
- 'multiple mutations with revalidation in sequence 3',
272
- async () => {
273
- const store = createTestStore(0);
274
-
275
- const mutateValue = (value: number, revalidationDuration: number) =>
276
- action(store, value, {
277
- withOptimisticUpdate: true,
278
- withRevalidation: true,
279
- duration: 60,
280
- revalidationDuration,
281
- });
282
-
283
- const promises = [
284
- delayCall(10, () => mutateValue(1, 400)),
285
- delayCall(283, () => mutateValue(2, 476)),
286
- delayCall(536, () => mutateValue(3, 400)),
287
- delayCall(781, () => mutateValue(4, 407)),
288
- delayCall(1_030, () => mutateValue(4, 233)),
289
- ];
290
-
291
- await Promise.all(promises);
292
-
293
- await store.waitForNoPendingRequests(10);
294
-
295
- await sleep(200);
296
-
297
- expect(store.ui.changesHistory).toEqual([0, 1, 2, 3, 4]);
298
- expect(store.actions).toMatchTimeline(`
299
- "
300
- 1 - optimistic-ui-commit
301
- 1 - mutation-started
302
- 1 - mutation-finished
303
-
304
- fetch-started : 1
305
-
306
- 2 - optimistic-ui-commit
307
- 2 - mutation-started
308
- 2 - mutation-finished
309
-
310
- fetch-started : 2
311
- fetch-aborted : 1
312
-
313
- 3 - optimistic-ui-commit
314
- 3 - mutation-started
315
- 3 - mutation-finished
316
-
317
- fetch-started : 3
318
-
319
- 4 - optimistic-ui-commit
320
- 4 - mutation-started
321
- ---
322
- fetch-aborted : 2
323
- 4 - mutation-finished
324
- OR
325
- 4 - mutation-finished
326
- fetch-aborted : 2
327
- ---
328
-
329
- fetch-started : 4
330
- fetch-aborted : 3
331
-
332
- 4 - optimistic-ui-commit
333
- 4 - mutation-started
334
- 4 - mutation-finished
335
-
336
- fetch-started : 5
337
- fetch-aborted : 4
338
- 4 - fetch-finished : 5
339
- 4 - fetch-ui-commit
340
- "
341
- `);
342
- },
343
- );
344
-
345
- test.concurrent(
346
- 'multiple mutations with revalidation in sequence, causing concurrent updates',
347
- async () => {
348
- const store = createTestStore(0);
349
-
350
- const promises = [
351
- delayCall(0, () =>
352
- action(store, 1, {
353
- withOptimisticUpdate: true,
354
- withRevalidation: true,
355
- }),
356
- ),
357
- delayCall(70, () =>
358
- action(store, 2, {
359
- withOptimisticUpdate: true,
360
- withRevalidation: true,
361
- }),
362
- ),
363
- ];
364
-
365
- await Promise.all(promises);
366
-
367
- await store.waitForNoPendingRequests();
368
-
369
- expect(store.ui.changesHistory).toEqual([0, 1, 2]);
370
- expect(store.actions).toMatchTimeline(`
371
- "
372
- 1 - optimistic-ui-commit
373
- 1 - mutation-started
374
- 1 - mutation-finished
375
- fetch-started : 1
376
- 2 - optimistic-ui-commit
377
- 2 - mutation-started
378
- fetch-aborted : 1
379
- 2 - mutation-finished
380
- fetch-started : 2
381
- 2 - fetch-finished : 2
382
- 2 - fetch-ui-commit
383
- "
384
- `);
385
- },
386
- );
387
-
388
- test.concurrent(
389
- 'multiple concurrent mutations with revalidation ',
390
- async () => {
391
- const store = createTestStore(0);
392
-
393
- const promises = [
394
- delayCall(0, () =>
395
- action(store, 1, {
396
- withOptimisticUpdate: true,
397
- withRevalidation: true,
398
- }),
399
- ),
400
- delayCall(50, () =>
401
- action(store, 2, {
402
- withOptimisticUpdate: true,
403
- withRevalidation: true,
404
- }),
405
- ),
406
- ];
407
-
408
- await Promise.all(promises);
409
-
410
- await store.waitForNoPendingRequests();
411
-
412
- expect(store.numOfFetchs).toBe(1);
413
-
414
- expect(store.ui.changesHistory).toEqual([0, 1, 2]);
415
- expect(store.server.history).toEqual([0, 1, 2]);
416
- expect(store.actions).toMatchTimeline(`
417
- "
418
- 1 - optimistic-ui-commit
419
- 1 - mutation-started
420
- 1 - mutation-finished
421
- 2 - optimistic-ui-commit
422
- 2 - mutation-started
423
- fetch-scheduled
424
- 2 - mutation-finished
425
- scheduled-fetch-started : 1
426
- fetch-skipped
427
- 2 - fetch-finished : 1
428
- 2 - fetch-ui-commit
429
- "
430
- `);
431
- },
432
- );
433
-
434
- test.concurrent('multiple high priority fetchs', async () => {
435
- const store = createTestStore(0);
436
-
437
- const promises = [
438
- delayCall(0, () => store.fetch('highPriority')),
439
- delayCall(5, () => store.fetch('highPriority')),
440
- delayCall(8, () => store.fetch('highPriority')),
441
- delayCall(15, () => store.fetch('highPriority')),
442
- delayCall(20, () => store.fetch('highPriority')),
443
- ];
444
-
445
- await Promise.all(promises);
446
-
447
- await store.waitForNoPendingRequests();
448
-
449
- expect(store.numOfFetchs).toBe(2);
450
- expect(store.actions).toMatchTimeline(`
451
- "
452
- fetch-started : 1
453
- fetch-skipped
454
- fetch-skipped
455
- fetch-scheduled
456
- fetch-scheduled
457
- fetch-finished : 1
458
- fetch-ui-commit
459
- scheduled-fetch-started : 2
460
- fetch-finished : 2
461
- fetch-ui-commit
462
- "
463
- `);
464
- });
465
-
466
- test.concurrent('throttle low priority updates', async () => {
467
- const store = createTestStore(0);
468
-
469
- const promises = [
470
- delayCall(0, () => store.fetch('lowPriority')),
471
- delayCall(100, () => store.fetch('lowPriority')),
472
- delayCall(110, () => store.fetch('lowPriority')),
473
- delayCall(120, () => store.fetch('lowPriority')),
474
- delayCall(210, () => store.fetch('lowPriority')),
475
- ];
476
-
477
- await Promise.all(promises);
478
-
479
- await store.waitForNoPendingRequests();
480
-
481
- expect(store.numOfFetchs).toBe(2);
482
-
483
- expect(store.actions).toMatchTimeline(`
484
- "
485
- fetch-started : 1
486
- fetch-finished : 1
487
- fetch-ui-commit
488
- fetch-skipped
489
- fetch-skipped
490
- fetch-skipped
491
- fetch-started : 2
492
- fetch-finished : 2
493
- fetch-ui-commit
494
- "
495
- `);
496
- });
497
-
498
- test.concurrent(
499
- 'multiple mutations with low priority fetch between',
500
- async () => {
501
- const store = createTestStore(0);
502
-
503
- const promises = [
504
- delayCall(0, () =>
505
- action(store, 1, {
506
- withOptimisticUpdate: true,
507
- withRevalidation: true,
508
- }),
509
- ),
510
- delayCall(50, () =>
511
- action(store, 2, {
512
- withOptimisticUpdate: true,
513
- withRevalidation: true,
514
- }),
515
- ),
516
- delayCall(70, () => store.fetch('lowPriority')),
517
- ];
518
-
519
- await Promise.all(promises);
520
-
521
- await store.waitForNoPendingRequests();
522
-
523
- expect(store.ui.changesHistory).toEqual([0, 1, 2]);
524
- expect(store.numOfFetchs).toBe(1);
525
- expect(store.actions).toMatchTimeline(`
526
- "
527
- 1 - optimistic-ui-commit
528
- 1 - mutation-started
529
- 1 - mutation-finished
530
- 2 - optimistic-ui-commit
531
- 2 - mutation-started
532
- ---
533
- fetch-scheduled
534
- fetch-skipped
535
- OR
536
- fetch-skipped
537
- fetch-scheduled
538
- ---
539
-
540
- 2 - mutation-finished
541
- scheduled-fetch-started : 1
542
- fetch-skipped
543
- 2 - fetch-finished : 1
544
- 2 - fetch-ui-commit
545
- "
546
- `);
547
- },
548
- );
549
-
550
- test.concurrent('very slow mutation with revalidation then mutation', async () => {
551
- const store = createTestStore(0);
552
-
553
- await waitTimeline([
554
- [
555
- 0,
556
- () =>
557
- action(store, 1, {
558
- withOptimisticUpdate: true,
559
- withRevalidation: true,
560
- revalidationDuration: 400,
561
- }),
562
- ],
563
- [
564
- 100,
565
- () =>
566
- action(store, 2, {
567
- withOptimisticUpdate: true,
568
- withRevalidation: true,
569
- }),
570
- ],
571
- ]);
572
-
573
- await store.waitForNoPendingRequests();
574
-
575
- await sleep(400);
576
-
577
- expect(store.ui.changesHistory).toEqual([0, 1, 2]);
578
- expect(store.numOfFetchs).toBe(2);
579
- expect(store.actions).toMatchTimeline(`
580
- "
581
- 1 - optimistic-ui-commit
582
- 1 - mutation-started
583
- 1 - mutation-finished
584
-
585
- fetch-started : 1
586
- 2 - optimistic-ui-commit
587
- 2 - mutation-started
588
- 2 - mutation-finished
589
- fetch-started : 2
590
- 2 - fetch-finished : 2
591
- 2 - fetch-ui-commit
592
- fetch-aborted : 1
593
- "
594
- `);
595
- });
596
-
597
- test.concurrent('fetch error', async () => {
598
- const store = createTestStore(0);
599
-
600
- await waitTimeline(
601
- [
602
- [0, () => store.fetch('lowPriority')],
603
- [50, () => store.errorInNextFetch()],
604
- [220, () => store.fetch('lowPriority')],
605
- ],
606
- 300,
607
- );
608
-
609
- expect(store.server.history).toEqual([0, 'error']);
610
- expect(store.ui.changesHistory).toEqual([0, 'error']);
611
- expect(store.numOfFetchs).toBe(2);
612
- expect(store.actions).toMatchTimeline(`
613
- "
614
- fetch-started : 1
615
- fetch-finished : 1
616
- fetch-ui-commit
617
- error - server-data-changed
618
- fetch-started : 2
619
- fetch-error : 2
620
- error - fetch-ui-commit
621
- "
622
- `);
623
- });
624
-
625
- const defaultRTUMutation = {
626
- withOptimisticUpdate: true,
627
- duration: 200 as const,
628
- triggerRTU: true,
629
- };
630
-
631
- describe('realtime updates', () => {
632
- test.concurrent('dynamically throttle realtime updates', async () => {
633
- const store = createTestStore(0);
634
-
635
- const slowDuration = 300;
636
-
637
- await waitTimeline([
638
- [0, () => store.emulateExternalRTU(1, slowDuration)],
639
- [slowDuration + 20, () => store.emulateExternalRTU(2)],
640
- [slowDuration + 30, () => store.emulateExternalRTU(3)],
641
- [slowDuration + 360, () => store.emulateExternalRTU(4)],
642
- ]);
643
-
644
- await sleep(400);
645
-
646
- expect(store.ui.changesHistory).toEqual([0, 1, 3, 4]);
647
-
648
- expect(store.numOfFetchs).toStrictEqual(3);
649
- expect(store.actions).toMatchTimeline(`
650
- "
651
- 1 - server-data-changed
652
- fetch-started : 1
653
- 1 - fetch-finished : 1
654
- 1 - fetch-ui-commit
655
- 2 - server-data-changed
656
- rt-fetch-scheduled
657
- 3 - server-data-changed
658
- rt-fetch-scheduled
659
-
660
- scheduled-rt-fetch-started : 2
661
-
662
- ---
663
- rt-fetch-scheduled
664
- 4 - server-data-changed
665
- 3 - fetch-finished : 2
666
- 3 - fetch-ui-commit
667
- scheduled-rt-fetch-started : 3
668
- OR
669
- 3 - fetch-finished : 2
670
- 3 - fetch-ui-commit
671
- 4 - server-data-changed
672
- rt-fetch-scheduled
673
- scheduled-rt-fetch-started : 3
674
- OR
675
- 4 - server-data-changed
676
- 3 - fetch-finished : 2
677
- 3 - fetch-ui-commit
678
- rt-fetch-scheduled
679
- scheduled-rt-fetch-started : 3
680
- OR
681
- 4 - server-data-changed
682
- rt-fetch-scheduled
683
- 3 - fetch-finished : 2
684
- 3 - fetch-ui-commit
685
- scheduled-rt-fetch-started : 3
686
- OR
687
- 3 - fetch-finished : 2
688
- 3 - fetch-ui-commit
689
- 4 - server-data-changed
690
- fetch-started : 3
691
- ---
692
-
693
- 4 - fetch-finished : 3
694
- 4 - fetch-ui-commit
695
- "
696
- `);
697
- });
698
-
699
- test.concurrent('simple mutation that triggers a RTU', async () => {
700
- const store = createTestStore(0);
701
-
702
- await waitTimeline(
703
- [
704
- [0, () => store.fetch('lowPriority', 20)],
705
- [
706
- 110,
707
- () =>
708
- action(store, 1, {
709
- withOptimisticUpdate: true,
710
- duration: 200,
711
- triggerRTU: true,
712
- }),
713
- ],
714
- ],
715
- 600,
716
- );
717
-
718
- expect(store.server.history).toEqual([0, 1]);
719
- expect(store.ui.changesHistory).toEqual([0, 1]);
720
- expect(store.numOfFetchs).toEqual(2);
721
-
722
- expect(store.actions).toMatchTimeline(`
723
- "
724
- .
725
- 1 - optimistic-ui-commit
726
- 1 - mutation-started
727
- 1 - server-data-changed
728
- 1 - mutation-finished
729
-
730
- rt-fetch-scheduled
731
- scheduled-rt-fetch-started : 2
732
- 1 - fetch-finished : 2
733
- 1 - fetch-ui-commit
734
- "
735
- `);
736
- });
737
-
738
- test.concurrent(
739
- 'slow mutation then external RTU while mutation RTU is running',
740
- async () => {
741
- const store = createTestStore(0);
742
-
743
- await waitTimeline(
744
- [
745
- [0, () => store.fetch('lowPriority', 20)],
746
- [110, () => action(store, 1, defaultRTUMutation)],
747
- [340, () => store.emulateExternalRTU(2)],
748
- ],
749
- 510,
750
- );
751
-
752
- expect(store.server.history).toEqual([0, 1, 2]);
753
- expect(store.ui.changesHistory).toEqual([0, 1, 2]);
754
- expect(store.numOfFetchs).toEqual(3);
755
-
756
- expect(store.actions).toMatchTimeline(`
757
- "
758
- .
759
- 1 - optimistic-ui-commit
760
- 1 - mutation-started
761
- 1 - server-data-changed
762
- 1 - mutation-finished
763
- rt-fetch-scheduled
764
- scheduled-rt-fetch-started : 2
765
- 2 - server-data-changed
766
- rt-fetch-scheduled
767
-
768
- ---
769
- 2 - fetch-finished : 2
770
- 2 - fetch-ui-commit
771
- OR
772
- 1 - fetch-finished : 2
773
- 1 - fetch-ui-commit
774
- ---
775
-
776
- scheduled-rt-fetch-started : 3
777
- 2 - fetch-finished : 3
778
- 2 - fetch-ui-commit
779
- "
780
- `);
781
- },
782
- );
783
-
784
- test.concurrent(
785
- 'slow mutation then new mutation while prev mutation RTU is running',
786
- async () => {
787
- const store = createTestStore(0);
788
-
789
- await waitTimeline(
790
- [
791
- [0, () => store.fetch('lowPriority', 20)],
792
- [110, () => action(store, 1, defaultRTUMutation)],
793
- [340, () => action(store, 2, defaultRTUMutation)],
794
- ],
795
- 600,
796
- );
797
-
798
- expect(store.server.history).toEqual([0, 1, 2]);
799
- expect(store.ui.changesHistory).toEqual([0, 1, 2]);
800
- expect(store.numOfFetchs).toEqual(3);
801
-
802
- expect(store.actions).toMatchTimeline(`
803
- "
804
- .
805
- 1 - optimistic-ui-commit
806
- 1 - mutation-started
807
- 1 - server-data-changed
808
- 1 - mutation-finished
809
- rt-fetch-scheduled
810
-
811
- scheduled-rt-fetch-started : 2
812
-
813
- 2 - optimistic-ui-commit
814
- 2 - mutation-started
815
-
816
- fetch-aborted : 2
817
-
818
- 2 - server-data-changed
819
- 2 - mutation-finished
820
- rt-fetch-scheduled
821
-
822
- scheduled-rt-fetch-started : 3
823
- 2 - fetch-finished : 3
824
- 2 - fetch-ui-commit
825
- "
826
- `);
827
- },
828
- );
829
-
830
- test.concurrent(
831
- 'slow mutation then new mutation while prev mutation is running',
832
- async () => {
833
- const store = createTestStore(0);
834
-
835
- await waitTimeline(
836
- [
837
- [0, () => store.fetch('lowPriority', 20)],
838
- [110, () => action(store, 1, defaultRTUMutation)],
839
- [200, () => action(store, 2, defaultRTUMutation)],
840
- ],
841
- 600,
842
- );
843
-
844
- expect(store.server.history).toEqual([0, 1, 2]);
845
- expect(store.ui.changesHistory).toEqual([0, 1, 2]);
846
- expect(store.numOfFetchs).toEqual(2);
847
-
848
- expect(store.actions).toMatchTimeline(`
849
- "
850
- .
851
- 1 - optimistic-ui-commit
852
- 1 - mutation-started
853
- 2 - optimistic-ui-commit
854
- 2 - mutation-started
855
- 1 - server-data-changed
856
- 1 - mutation-finished
857
- rt-fetch-scheduled
858
- 2 - server-data-changed
859
- 2 - mutation-finished
860
- rt-fetch-scheduled
861
- scheduled-rt-fetch-started : 2
862
- 2 - fetch-finished : 2
863
- 2 - fetch-ui-commit
864
- "
865
- `);
866
- },
867
- );
868
-
869
- test.concurrent('rtu mutations without optimistic updates', async () => {
870
- const store = createTestStore(0);
871
-
872
- const rtuWithoutOptimisticUpdate = {
873
- withOptimisticUpdate: false,
874
- duration: 200,
875
- triggerRTU: true,
876
- };
877
-
878
- await waitTimeline(
879
- [
880
- [0, () => store.fetch('lowPriority', 20)],
881
- [110, () => action(store, 1, rtuWithoutOptimisticUpdate)],
882
- [110 + 220, () => action(store, 2, rtuWithoutOptimisticUpdate)],
883
- ],
884
- 1000,
885
- );
886
-
887
- expect(store.server.history).toEqual([0, 1, 2]);
888
- expect(store.ui.changesHistory).toEqual([0, 2]);
889
-
890
- expect(store.numOfFetchs).toEqual(3);
891
-
892
- expect(store.actions).toMatchTimeline(`
893
- "
894
- fetch-started : 1
895
- fetch-finished : 1
896
- fetch-ui-commit
897
- 1 - mutation-started
898
- 1 - server-data-changed
899
- 1 - mutation-finished
900
- rt-fetch-scheduled
901
- scheduled-rt-fetch-started : 2
902
- 2 - mutation-started
903
- fetch-aborted : 2
904
- 2 - server-data-changed
905
- 2 - mutation-finished
906
- rt-fetch-scheduled
907
- scheduled-rt-fetch-started : 3
908
- 2 - fetch-finished : 3
909
- 2 - fetch-ui-commit
910
- "
911
- `);
912
- });
913
- });