@tanstack/react-query 4.29.5 → 4.29.7

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
- this.listeners.push(listener);
38
+ const identity = {
39
+ listener
40
+ };
41
+ this.listeners.add(identity);
39
42
  this.onSubscribe();
40
43
  return () => {
41
- this.listeners = this.listeners.filter(x => x !== listener);
44
+ this.listeners.delete(identity);
42
45
  this.onUnsubscribe();
43
46
  };
44
47
  }
45
48
 
46
49
  hasListeners() {
47
- return this.listeners.length > 0;
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(listener => {
441
+ this.listeners.forEach(({
442
+ listener
443
+ }) => {
439
444
  listener();
440
445
  });
441
446
  }
@@ -518,7 +523,9 @@
518
523
  }
519
524
 
520
525
  onOnline() {
521
- this.listeners.forEach(listener => {
526
+ this.listeners.forEach(({
527
+ listener
528
+ }) => {
522
529
  listener();
523
530
  });
524
531
  }
@@ -1385,7 +1392,9 @@
1385
1392
 
1386
1393
  notify(event) {
1387
1394
  notifyManager.batch(() => {
1388
- this.listeners.forEach(listener => {
1395
+ this.listeners.forEach(({
1396
+ listener
1397
+ }) => {
1389
1398
  listener(event);
1390
1399
  });
1391
1400
  });
@@ -1727,7 +1736,9 @@
1727
1736
 
1728
1737
  notify(event) {
1729
1738
  notifyManager.batch(() => {
1730
- this.listeners.forEach(listener => {
1739
+ this.listeners.forEach(({
1740
+ listener
1741
+ }) => {
1731
1742
  listener(event);
1732
1743
  });
1733
1744
  });
@@ -2253,7 +2264,7 @@
2253
2264
  }
2254
2265
 
2255
2266
  onSubscribe() {
2256
- if (this.listeners.length === 1) {
2267
+ if (this.listeners.size === 1) {
2257
2268
  this.currentQuery.addObserver(this);
2258
2269
 
2259
2270
  if (shouldFetchOnMount(this.currentQuery, this.options)) {
@@ -2265,7 +2276,7 @@
2265
2276
  }
2266
2277
 
2267
2278
  onUnsubscribe() {
2268
- if (!this.listeners.length) {
2279
+ if (!this.hasListeners()) {
2269
2280
  this.destroy();
2270
2281
  }
2271
2282
  }
@@ -2279,7 +2290,7 @@
2279
2290
  }
2280
2291
 
2281
2292
  destroy() {
2282
- this.listeners = [];
2293
+ this.listeners = new Set();
2283
2294
  this.clearStaleTimeout();
2284
2295
  this.clearRefetchInterval();
2285
2296
  this.currentQuery.removeObserver(this);
@@ -2708,7 +2719,9 @@
2708
2719
 
2709
2720
 
2710
2721
  if (notifyOptions.listeners) {
2711
- this.listeners.forEach(listener => {
2722
+ this.listeners.forEach(({
2723
+ listener
2724
+ }) => {
2712
2725
  listener(this.currentResult);
2713
2726
  });
2714
2727
  } // Then the cache listeners
@@ -2765,7 +2778,7 @@
2765
2778
  }
2766
2779
 
2767
2780
  onSubscribe() {
2768
- if (this.listeners.length === 1) {
2781
+ if (this.listeners.size === 1) {
2769
2782
  this.observers.forEach(observer => {
2770
2783
  observer.subscribe(result => {
2771
2784
  this.onUpdate(observer, result);
@@ -2775,13 +2788,13 @@
2775
2788
  }
2776
2789
 
2777
2790
  onUnsubscribe() {
2778
- if (!this.listeners.length) {
2791
+ if (!this.listeners.size) {
2779
2792
  this.destroy();
2780
2793
  }
2781
2794
  }
2782
2795
 
2783
2796
  destroy() {
2784
- this.listeners = [];
2797
+ this.listeners = new Set();
2785
2798
  this.observers.forEach(observer => {
2786
2799
  observer.destroy();
2787
2800
  });
@@ -2901,7 +2914,9 @@
2901
2914
 
2902
2915
  notify() {
2903
2916
  notifyManager.batch(() => {
2904
- this.listeners.forEach(listener => {
2917
+ this.listeners.forEach(({
2918
+ listener
2919
+ }) => {
2905
2920
  listener(this.result);
2906
2921
  });
2907
2922
  });
@@ -3022,7 +3037,7 @@
3022
3037
  }
3023
3038
 
3024
3039
  onUnsubscribe() {
3025
- if (!this.listeners.length) {
3040
+ if (!this.hasListeners()) {
3026
3041
  var _this$currentMutation2;
3027
3042
 
3028
3043
  (_this$currentMutation2 = this.currentMutation) == null ? void 0 : _this$currentMutation2.removeObserver(this);
@@ -3103,7 +3118,9 @@
3103
3118
 
3104
3119
 
3105
3120
  if (options.listeners) {
3106
- this.listeners.forEach(listener => {
3121
+ this.listeners.forEach(({
3122
+ listener
3123
+ }) => {
3107
3124
  listener(this.currentResult);
3108
3125
  });
3109
3126
  }