@tanstack/vue-query 5.0.0-alpha.31 → 5.0.0-alpha.32

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,19 +6,19 @@
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
  subscribe(listener) {
13
- this.listeners.push(listener);
13
+ this.listeners.add(listener);
14
14
  this.onSubscribe();
15
15
  return () => {
16
- this.listeners = this.listeners.filter(x => x !== listener);
16
+ this.listeners.delete(listener);
17
17
  this.onUnsubscribe();
18
18
  };
19
19
  }
20
20
  hasListeners() {
21
- return this.listeners.length > 0;
21
+ return this.listeners.size > 0;
22
22
  }
23
23
  onSubscribe() {
24
24
  // Do nothing
@@ -1875,7 +1875,7 @@
1875
1875
  this.refetch = this.refetch.bind(this);
1876
1876
  }
1877
1877
  onSubscribe() {
1878
- if (this.listeners.length === 1) {
1878
+ if (this.listeners.size === 1) {
1879
1879
  this.#currentQuery.addObserver(this);
1880
1880
  if (shouldFetchOnMount(this.#currentQuery, this.options)) {
1881
1881
  this.#executeFetch();
@@ -1884,7 +1884,7 @@
1884
1884
  }
1885
1885
  }
1886
1886
  onUnsubscribe() {
1887
- if (!this.listeners.length) {
1887
+ if (!this.hasListeners()) {
1888
1888
  this.destroy();
1889
1889
  }
1890
1890
  }
@@ -1895,7 +1895,7 @@
1895
1895
  return shouldFetchOn(this.#currentQuery, this.options, this.options.refetchOnWindowFocus);
1896
1896
  }
1897
1897
  destroy() {
1898
- this.listeners = [];
1898
+ this.listeners = new Set();
1899
1899
  this.#clearStaleTimeout();
1900
1900
  this.#clearRefetchInterval();
1901
1901
  this.#currentQuery.removeObserver(this);
@@ -2290,7 +2290,7 @@
2290
2290
  }
2291
2291
  }
2292
2292
  onSubscribe() {
2293
- if (this.listeners.length === 1) {
2293
+ if (this.listeners.size === 1) {
2294
2294
  this.#observers.forEach(observer => {
2295
2295
  observer.subscribe(result => {
2296
2296
  this.#onUpdate(observer, result);
@@ -2299,12 +2299,12 @@
2299
2299
  }
2300
2300
  }
2301
2301
  onUnsubscribe() {
2302
- if (!this.listeners.length) {
2302
+ if (!this.listeners.size) {
2303
2303
  this.destroy();
2304
2304
  }
2305
2305
  }
2306
2306
  destroy() {
2307
- this.listeners = [];
2307
+ this.listeners = new Set();
2308
2308
  this.#observers.forEach(observer => {
2309
2309
  observer.destroy();
2310
2310
  });
@@ -2500,7 +2500,7 @@
2500
2500
  this.#currentMutation?.setOptions(this.options);
2501
2501
  }
2502
2502
  onUnsubscribe() {
2503
- if (!this.listeners.length) {
2503
+ if (!this.hasListeners()) {
2504
2504
  this.#currentMutation?.removeObserver(this);
2505
2505
  }
2506
2506
  }