@tanstack/react-query 4.29.5 → 4.29.10
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.
|
@@ -30,21 +30,24 @@
|
|
|
30
30
|
|
|
31
31
|
class Subscribable {
|
|
32
32
|
constructor() {
|
|
33
|
-
this.listeners =
|
|
33
|
+
this.listeners = new Set();
|
|
34
34
|
this.subscribe = this.subscribe.bind(this);
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
subscribe(listener) {
|
|
38
|
-
|
|
38
|
+
const identity = {
|
|
39
|
+
listener
|
|
40
|
+
};
|
|
41
|
+
this.listeners.add(identity);
|
|
39
42
|
this.onSubscribe();
|
|
40
43
|
return () => {
|
|
41
|
-
this.listeners
|
|
44
|
+
this.listeners.delete(identity);
|
|
42
45
|
this.onUnsubscribe();
|
|
43
46
|
};
|
|
44
47
|
}
|
|
45
48
|
|
|
46
49
|
hasListeners() {
|
|
47
|
-
return this.listeners.
|
|
50
|
+
return this.listeners.size > 0;
|
|
48
51
|
}
|
|
49
52
|
|
|
50
53
|
onSubscribe() {// Do nothing
|
|
@@ -435,7 +438,9 @@
|
|
|
435
438
|
}
|
|
436
439
|
|
|
437
440
|
onFocus() {
|
|
438
|
-
this.listeners.forEach(
|
|
441
|
+
this.listeners.forEach(({
|
|
442
|
+
listener
|
|
443
|
+
}) => {
|
|
439
444
|
listener();
|
|
440
445
|
});
|
|
441
446
|
}
|
|
@@ -456,6 +461,7 @@
|
|
|
456
461
|
}
|
|
457
462
|
const focusManager = new FocusManager();
|
|
458
463
|
|
|
464
|
+
const onlineEvents = ['online', 'offline'];
|
|
459
465
|
class OnlineManager extends Subscribable {
|
|
460
466
|
constructor() {
|
|
461
467
|
super();
|
|
@@ -467,12 +473,14 @@
|
|
|
467
473
|
const listener = () => onOnline(); // Listen to online
|
|
468
474
|
|
|
469
475
|
|
|
470
|
-
|
|
471
|
-
|
|
476
|
+
onlineEvents.forEach(event => {
|
|
477
|
+
window.addEventListener(event, listener, false);
|
|
478
|
+
});
|
|
472
479
|
return () => {
|
|
473
480
|
// Be sure to unsubscribe if a new handler is set
|
|
474
|
-
|
|
475
|
-
|
|
481
|
+
onlineEvents.forEach(event => {
|
|
482
|
+
window.removeEventListener(event, listener);
|
|
483
|
+
});
|
|
476
484
|
};
|
|
477
485
|
}
|
|
478
486
|
|
|
@@ -518,7 +526,9 @@
|
|
|
518
526
|
}
|
|
519
527
|
|
|
520
528
|
onOnline() {
|
|
521
|
-
this.listeners.forEach(
|
|
529
|
+
this.listeners.forEach(({
|
|
530
|
+
listener
|
|
531
|
+
}) => {
|
|
522
532
|
listener();
|
|
523
533
|
});
|
|
524
534
|
}
|
|
@@ -1385,7 +1395,9 @@
|
|
|
1385
1395
|
|
|
1386
1396
|
notify(event) {
|
|
1387
1397
|
notifyManager.batch(() => {
|
|
1388
|
-
this.listeners.forEach(
|
|
1398
|
+
this.listeners.forEach(({
|
|
1399
|
+
listener
|
|
1400
|
+
}) => {
|
|
1389
1401
|
listener(event);
|
|
1390
1402
|
});
|
|
1391
1403
|
});
|
|
@@ -1727,7 +1739,9 @@
|
|
|
1727
1739
|
|
|
1728
1740
|
notify(event) {
|
|
1729
1741
|
notifyManager.batch(() => {
|
|
1730
|
-
this.listeners.forEach(
|
|
1742
|
+
this.listeners.forEach(({
|
|
1743
|
+
listener
|
|
1744
|
+
}) => {
|
|
1731
1745
|
listener(event);
|
|
1732
1746
|
});
|
|
1733
1747
|
});
|
|
@@ -2253,7 +2267,7 @@
|
|
|
2253
2267
|
}
|
|
2254
2268
|
|
|
2255
2269
|
onSubscribe() {
|
|
2256
|
-
if (this.listeners.
|
|
2270
|
+
if (this.listeners.size === 1) {
|
|
2257
2271
|
this.currentQuery.addObserver(this);
|
|
2258
2272
|
|
|
2259
2273
|
if (shouldFetchOnMount(this.currentQuery, this.options)) {
|
|
@@ -2265,7 +2279,7 @@
|
|
|
2265
2279
|
}
|
|
2266
2280
|
|
|
2267
2281
|
onUnsubscribe() {
|
|
2268
|
-
if (!this.
|
|
2282
|
+
if (!this.hasListeners()) {
|
|
2269
2283
|
this.destroy();
|
|
2270
2284
|
}
|
|
2271
2285
|
}
|
|
@@ -2279,7 +2293,7 @@
|
|
|
2279
2293
|
}
|
|
2280
2294
|
|
|
2281
2295
|
destroy() {
|
|
2282
|
-
this.listeners =
|
|
2296
|
+
this.listeners = new Set();
|
|
2283
2297
|
this.clearStaleTimeout();
|
|
2284
2298
|
this.clearRefetchInterval();
|
|
2285
2299
|
this.currentQuery.removeObserver(this);
|
|
@@ -2708,7 +2722,9 @@
|
|
|
2708
2722
|
|
|
2709
2723
|
|
|
2710
2724
|
if (notifyOptions.listeners) {
|
|
2711
|
-
this.listeners.forEach(
|
|
2725
|
+
this.listeners.forEach(({
|
|
2726
|
+
listener
|
|
2727
|
+
}) => {
|
|
2712
2728
|
listener(this.currentResult);
|
|
2713
2729
|
});
|
|
2714
2730
|
} // Then the cache listeners
|
|
@@ -2765,7 +2781,7 @@
|
|
|
2765
2781
|
}
|
|
2766
2782
|
|
|
2767
2783
|
onSubscribe() {
|
|
2768
|
-
if (this.listeners.
|
|
2784
|
+
if (this.listeners.size === 1) {
|
|
2769
2785
|
this.observers.forEach(observer => {
|
|
2770
2786
|
observer.subscribe(result => {
|
|
2771
2787
|
this.onUpdate(observer, result);
|
|
@@ -2775,13 +2791,13 @@
|
|
|
2775
2791
|
}
|
|
2776
2792
|
|
|
2777
2793
|
onUnsubscribe() {
|
|
2778
|
-
if (!this.listeners.
|
|
2794
|
+
if (!this.listeners.size) {
|
|
2779
2795
|
this.destroy();
|
|
2780
2796
|
}
|
|
2781
2797
|
}
|
|
2782
2798
|
|
|
2783
2799
|
destroy() {
|
|
2784
|
-
this.listeners =
|
|
2800
|
+
this.listeners = new Set();
|
|
2785
2801
|
this.observers.forEach(observer => {
|
|
2786
2802
|
observer.destroy();
|
|
2787
2803
|
});
|
|
@@ -2901,7 +2917,9 @@
|
|
|
2901
2917
|
|
|
2902
2918
|
notify() {
|
|
2903
2919
|
notifyManager.batch(() => {
|
|
2904
|
-
this.listeners.forEach(
|
|
2920
|
+
this.listeners.forEach(({
|
|
2921
|
+
listener
|
|
2922
|
+
}) => {
|
|
2905
2923
|
listener(this.result);
|
|
2906
2924
|
});
|
|
2907
2925
|
});
|
|
@@ -3022,7 +3040,7 @@
|
|
|
3022
3040
|
}
|
|
3023
3041
|
|
|
3024
3042
|
onUnsubscribe() {
|
|
3025
|
-
if (!this.
|
|
3043
|
+
if (!this.hasListeners()) {
|
|
3026
3044
|
var _this$currentMutation2;
|
|
3027
3045
|
|
|
3028
3046
|
(_this$currentMutation2 = this.currentMutation) == null ? void 0 : _this$currentMutation2.removeObserver(this);
|
|
@@ -3103,7 +3121,9 @@
|
|
|
3103
3121
|
|
|
3104
3122
|
|
|
3105
3123
|
if (options.listeners) {
|
|
3106
|
-
this.listeners.forEach(
|
|
3124
|
+
this.listeners.forEach(({
|
|
3125
|
+
listener
|
|
3126
|
+
}) => {
|
|
3107
3127
|
listener(this.currentResult);
|
|
3108
3128
|
});
|
|
3109
3129
|
}
|