@tanstack/react-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.
@@ -25,19 +25,19 @@
25
25
 
26
26
  class Subscribable {
27
27
  constructor() {
28
- this.listeners = [];
28
+ this.listeners = new Set();
29
29
  this.subscribe = this.subscribe.bind(this);
30
30
  }
31
31
  subscribe(listener) {
32
- this.listeners.push(listener);
32
+ this.listeners.add(listener);
33
33
  this.onSubscribe();
34
34
  return () => {
35
- this.listeners = this.listeners.filter(x => x !== listener);
35
+ this.listeners.delete(listener);
36
36
  this.onUnsubscribe();
37
37
  };
38
38
  }
39
39
  hasListeners() {
40
- return this.listeners.length > 0;
40
+ return this.listeners.size > 0;
41
41
  }
42
42
  onSubscribe() {
43
43
  // Do nothing
@@ -1894,7 +1894,7 @@
1894
1894
  this.refetch = this.refetch.bind(this);
1895
1895
  }
1896
1896
  onSubscribe() {
1897
- if (this.listeners.length === 1) {
1897
+ if (this.listeners.size === 1) {
1898
1898
  this.#currentQuery.addObserver(this);
1899
1899
  if (shouldFetchOnMount(this.#currentQuery, this.options)) {
1900
1900
  this.#executeFetch();
@@ -1903,7 +1903,7 @@
1903
1903
  }
1904
1904
  }
1905
1905
  onUnsubscribe() {
1906
- if (!this.listeners.length) {
1906
+ if (!this.hasListeners()) {
1907
1907
  this.destroy();
1908
1908
  }
1909
1909
  }
@@ -1914,7 +1914,7 @@
1914
1914
  return shouldFetchOn(this.#currentQuery, this.options, this.options.refetchOnWindowFocus);
1915
1915
  }
1916
1916
  destroy() {
1917
- this.listeners = [];
1917
+ this.listeners = new Set();
1918
1918
  this.#clearStaleTimeout();
1919
1919
  this.#clearRefetchInterval();
1920
1920
  this.#currentQuery.removeObserver(this);
@@ -2309,7 +2309,7 @@
2309
2309
  }
2310
2310
  }
2311
2311
  onSubscribe() {
2312
- if (this.listeners.length === 1) {
2312
+ if (this.listeners.size === 1) {
2313
2313
  this.#observers.forEach(observer => {
2314
2314
  observer.subscribe(result => {
2315
2315
  this.#onUpdate(observer, result);
@@ -2318,12 +2318,12 @@
2318
2318
  }
2319
2319
  }
2320
2320
  onUnsubscribe() {
2321
- if (!this.listeners.length) {
2321
+ if (!this.listeners.size) {
2322
2322
  this.destroy();
2323
2323
  }
2324
2324
  }
2325
2325
  destroy() {
2326
- this.listeners = [];
2326
+ this.listeners = new Set();
2327
2327
  this.#observers.forEach(observer => {
2328
2328
  observer.destroy();
2329
2329
  });
@@ -2519,7 +2519,7 @@
2519
2519
  this.#currentMutation?.setOptions(this.options);
2520
2520
  }
2521
2521
  onUnsubscribe() {
2522
- if (!this.listeners.length) {
2522
+ if (!this.hasListeners()) {
2523
2523
  this.#currentMutation?.removeObserver(this);
2524
2524
  }
2525
2525
  }