@tanstack/vue-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.
@@ -6,21 +6,24 @@
6
6
 
7
7
  class Subscribable {
8
8
  constructor() {
9
- this.listeners = [];
9
+ this.listeners = new Set();
10
10
  this.subscribe = this.subscribe.bind(this);
11
11
  }
12
12
 
13
13
  subscribe(listener) {
14
- this.listeners.push(listener);
14
+ const identity = {
15
+ listener
16
+ };
17
+ this.listeners.add(identity);
15
18
  this.onSubscribe();
16
19
  return () => {
17
- this.listeners = this.listeners.filter(x => x !== listener);
20
+ this.listeners.delete(identity);
18
21
  this.onUnsubscribe();
19
22
  };
20
23
  }
21
24
 
22
25
  hasListeners() {
23
- return this.listeners.length > 0;
26
+ return this.listeners.size > 0;
24
27
  }
25
28
 
26
29
  onSubscribe() {// Do nothing
@@ -411,7 +414,9 @@
411
414
  }
412
415
 
413
416
  onFocus() {
414
- this.listeners.forEach(listener => {
417
+ this.listeners.forEach(({
418
+ listener
419
+ }) => {
415
420
  listener();
416
421
  });
417
422
  }
@@ -432,6 +437,7 @@
432
437
  }
433
438
  const focusManager = new FocusManager();
434
439
 
440
+ const onlineEvents = ['online', 'offline'];
435
441
  class OnlineManager extends Subscribable {
436
442
  constructor() {
437
443
  super();
@@ -443,12 +449,14 @@
443
449
  const listener = () => onOnline(); // Listen to online
444
450
 
445
451
 
446
- window.addEventListener('online', listener, false);
447
- window.addEventListener('offline', listener, false);
452
+ onlineEvents.forEach(event => {
453
+ window.addEventListener(event, listener, false);
454
+ });
448
455
  return () => {
449
456
  // Be sure to unsubscribe if a new handler is set
450
- window.removeEventListener('online', listener);
451
- window.removeEventListener('offline', listener);
457
+ onlineEvents.forEach(event => {
458
+ window.removeEventListener(event, listener);
459
+ });
452
460
  };
453
461
  }
454
462
 
@@ -494,7 +502,9 @@
494
502
  }
495
503
 
496
504
  onOnline() {
497
- this.listeners.forEach(listener => {
505
+ this.listeners.forEach(({
506
+ listener
507
+ }) => {
498
508
  listener();
499
509
  });
500
510
  }
@@ -1361,7 +1371,9 @@
1361
1371
 
1362
1372
  notify(event) {
1363
1373
  notifyManager.batch(() => {
1364
- this.listeners.forEach(listener => {
1374
+ this.listeners.forEach(({
1375
+ listener
1376
+ }) => {
1365
1377
  listener(event);
1366
1378
  });
1367
1379
  });
@@ -1703,7 +1715,9 @@
1703
1715
 
1704
1716
  notify(event) {
1705
1717
  notifyManager.batch(() => {
1706
- this.listeners.forEach(listener => {
1718
+ this.listeners.forEach(({
1719
+ listener
1720
+ }) => {
1707
1721
  listener(event);
1708
1722
  });
1709
1723
  });
@@ -2229,7 +2243,7 @@
2229
2243
  }
2230
2244
 
2231
2245
  onSubscribe() {
2232
- if (this.listeners.length === 1) {
2246
+ if (this.listeners.size === 1) {
2233
2247
  this.currentQuery.addObserver(this);
2234
2248
 
2235
2249
  if (shouldFetchOnMount(this.currentQuery, this.options)) {
@@ -2241,7 +2255,7 @@
2241
2255
  }
2242
2256
 
2243
2257
  onUnsubscribe() {
2244
- if (!this.listeners.length) {
2258
+ if (!this.hasListeners()) {
2245
2259
  this.destroy();
2246
2260
  }
2247
2261
  }
@@ -2255,7 +2269,7 @@
2255
2269
  }
2256
2270
 
2257
2271
  destroy() {
2258
- this.listeners = [];
2272
+ this.listeners = new Set();
2259
2273
  this.clearStaleTimeout();
2260
2274
  this.clearRefetchInterval();
2261
2275
  this.currentQuery.removeObserver(this);
@@ -2684,7 +2698,9 @@
2684
2698
 
2685
2699
 
2686
2700
  if (notifyOptions.listeners) {
2687
- this.listeners.forEach(listener => {
2701
+ this.listeners.forEach(({
2702
+ listener
2703
+ }) => {
2688
2704
  listener(this.currentResult);
2689
2705
  });
2690
2706
  } // Then the cache listeners
@@ -2741,7 +2757,7 @@
2741
2757
  }
2742
2758
 
2743
2759
  onSubscribe() {
2744
- if (this.listeners.length === 1) {
2760
+ if (this.listeners.size === 1) {
2745
2761
  this.observers.forEach(observer => {
2746
2762
  observer.subscribe(result => {
2747
2763
  this.onUpdate(observer, result);
@@ -2751,13 +2767,13 @@
2751
2767
  }
2752
2768
 
2753
2769
  onUnsubscribe() {
2754
- if (!this.listeners.length) {
2770
+ if (!this.listeners.size) {
2755
2771
  this.destroy();
2756
2772
  }
2757
2773
  }
2758
2774
 
2759
2775
  destroy() {
2760
- this.listeners = [];
2776
+ this.listeners = new Set();
2761
2777
  this.observers.forEach(observer => {
2762
2778
  observer.destroy();
2763
2779
  });
@@ -2877,7 +2893,9 @@
2877
2893
 
2878
2894
  notify() {
2879
2895
  notifyManager.batch(() => {
2880
- this.listeners.forEach(listener => {
2896
+ this.listeners.forEach(({
2897
+ listener
2898
+ }) => {
2881
2899
  listener(this.result);
2882
2900
  });
2883
2901
  });
@@ -2998,7 +3016,7 @@
2998
3016
  }
2999
3017
 
3000
3018
  onUnsubscribe() {
3001
- if (!this.listeners.length) {
3019
+ if (!this.hasListeners()) {
3002
3020
  var _this$currentMutation2;
3003
3021
 
3004
3022
  (_this$currentMutation2 = this.currentMutation) == null ? void 0 : _this$currentMutation2.removeObserver(this);
@@ -3079,7 +3097,9 @@
3079
3097
 
3080
3098
 
3081
3099
  if (options.listeners) {
3082
- this.listeners.forEach(listener => {
3100
+ this.listeners.forEach(({
3101
+ listener
3102
+ }) => {
3083
3103
  listener(this.currentResult);
3084
3104
  });
3085
3105
  }