@tanstack/query-core 5.102.7 → 5.103.0

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.
Files changed (301) hide show
  1. package/build/legacy/environmentManager.cjs +15 -1
  2. package/build/legacy/environmentManager.cjs.map +1 -1
  3. package/build/legacy/environmentManager.d.cts +15 -1
  4. package/build/legacy/environmentManager.d.cts.map +1 -1
  5. package/build/legacy/environmentManager.d.ts +15 -1
  6. package/build/legacy/environmentManager.d.ts.map +1 -1
  7. package/build/legacy/environmentManager.js +15 -1
  8. package/build/legacy/environmentManager.js.map +1 -1
  9. package/build/legacy/focusManager.cjs +57 -0
  10. package/build/legacy/focusManager.cjs.map +1 -1
  11. package/build/legacy/focusManager.d.cts +57 -0
  12. package/build/legacy/focusManager.d.cts.map +1 -1
  13. package/build/legacy/focusManager.d.ts +57 -0
  14. package/build/legacy/focusManager.d.ts.map +1 -1
  15. package/build/legacy/focusManager.js +57 -0
  16. package/build/legacy/focusManager.js.map +1 -1
  17. package/build/legacy/{hydration-Bjs0MSgg.d.ts → hydration-Cq7QYAzB.d.ts} +1424 -7
  18. package/build/legacy/hydration-Cq7QYAzB.d.ts.map +1 -0
  19. package/build/legacy/{hydration-DWGr3cFC.d.cts → hydration-DwR10Hi-.d.cts} +1424 -7
  20. package/build/legacy/hydration-DwR10Hi-.d.cts.map +1 -0
  21. package/build/legacy/hydration.cjs +57 -4
  22. package/build/legacy/hydration.cjs.map +1 -1
  23. package/build/legacy/hydration.d.cts +1 -1
  24. package/build/legacy/hydration.d.ts +1 -1
  25. package/build/legacy/hydration.js +57 -4
  26. package/build/legacy/hydration.js.map +1 -1
  27. package/build/legacy/index.cjs.map +1 -1
  28. package/build/legacy/index.d.cts +5 -5
  29. package/build/legacy/index.d.ts +5 -5
  30. package/build/legacy/index.js.map +1 -1
  31. package/build/legacy/infiniteQueryBehavior.d.cts +1 -1
  32. package/build/legacy/infiniteQueryBehavior.d.ts +1 -1
  33. package/build/legacy/infiniteQueryObserver.cjs +67 -0
  34. package/build/legacy/infiniteQueryObserver.cjs.map +1 -1
  35. package/build/legacy/infiniteQueryObserver.d.cts +68 -1
  36. package/build/legacy/infiniteQueryObserver.d.cts.map +1 -1
  37. package/build/legacy/infiniteQueryObserver.d.ts +68 -1
  38. package/build/legacy/infiniteQueryObserver.d.ts.map +1 -1
  39. package/build/legacy/infiniteQueryObserver.js +67 -0
  40. package/build/legacy/infiniteQueryObserver.js.map +1 -1
  41. package/build/legacy/mutation.cjs +74 -0
  42. package/build/legacy/mutation.cjs.map +1 -1
  43. package/build/legacy/mutation.d.cts +1 -1
  44. package/build/legacy/mutation.d.ts +1 -1
  45. package/build/legacy/mutation.js +74 -0
  46. package/build/legacy/mutation.js.map +1 -1
  47. package/build/legacy/mutationCache.cjs +74 -0
  48. package/build/legacy/mutationCache.cjs.map +1 -1
  49. package/build/legacy/mutationCache.d.cts +1 -1
  50. package/build/legacy/mutationCache.d.ts +1 -1
  51. package/build/legacy/mutationCache.js +74 -0
  52. package/build/legacy/mutationCache.js.map +1 -1
  53. package/build/legacy/mutationObserver.cjs +71 -0
  54. package/build/legacy/mutationObserver.cjs.map +1 -1
  55. package/build/legacy/mutationObserver.d.cts +1 -1
  56. package/build/legacy/mutationObserver.d.ts +1 -1
  57. package/build/legacy/mutationObserver.js +71 -0
  58. package/build/legacy/mutationObserver.js.map +1 -1
  59. package/build/legacy/notifyManager.cjs +45 -1
  60. package/build/legacy/notifyManager.cjs.map +1 -1
  61. package/build/legacy/notifyManager.d.cts +83 -2
  62. package/build/legacy/notifyManager.d.cts.map +1 -1
  63. package/build/legacy/notifyManager.d.ts +83 -2
  64. package/build/legacy/notifyManager.d.ts.map +1 -1
  65. package/build/legacy/notifyManager.js +45 -1
  66. package/build/legacy/notifyManager.js.map +1 -1
  67. package/build/legacy/onlineManager.cjs +47 -0
  68. package/build/legacy/onlineManager.cjs.map +1 -1
  69. package/build/legacy/onlineManager.d.cts +47 -0
  70. package/build/legacy/onlineManager.d.cts.map +1 -1
  71. package/build/legacy/onlineManager.d.ts +47 -0
  72. package/build/legacy/onlineManager.d.ts.map +1 -1
  73. package/build/legacy/onlineManager.js +47 -0
  74. package/build/legacy/onlineManager.js.map +1 -1
  75. package/build/legacy/queriesObserver.cjs +64 -0
  76. package/build/legacy/queriesObserver.cjs.map +1 -1
  77. package/build/legacy/queriesObserver.d.cts +73 -1
  78. package/build/legacy/queriesObserver.d.cts.map +1 -1
  79. package/build/legacy/queriesObserver.d.ts +73 -1
  80. package/build/legacy/queriesObserver.d.ts.map +1 -1
  81. package/build/legacy/queriesObserver.js +64 -0
  82. package/build/legacy/queriesObserver.js.map +1 -1
  83. package/build/legacy/query.cjs +141 -0
  84. package/build/legacy/query.cjs.map +1 -1
  85. package/build/legacy/query.d.cts +1 -1
  86. package/build/legacy/query.d.ts +1 -1
  87. package/build/legacy/query.js +141 -0
  88. package/build/legacy/query.js.map +1 -1
  89. package/build/legacy/queryCache.cjs +120 -0
  90. package/build/legacy/queryCache.cjs.map +1 -1
  91. package/build/legacy/queryCache.d.cts +1 -1
  92. package/build/legacy/queryCache.d.ts +1 -1
  93. package/build/legacy/queryCache.js +120 -0
  94. package/build/legacy/queryCache.js.map +1 -1
  95. package/build/legacy/queryClient.cjs +363 -0
  96. package/build/legacy/queryClient.cjs.map +1 -1
  97. package/build/legacy/queryClient.d.cts +1 -1
  98. package/build/legacy/queryClient.d.ts +1 -1
  99. package/build/legacy/queryClient.js +363 -0
  100. package/build/legacy/queryClient.js.map +1 -1
  101. package/build/legacy/queryObserver.cjs +116 -2
  102. package/build/legacy/queryObserver.cjs.map +1 -1
  103. package/build/legacy/queryObserver.d.cts +1 -1
  104. package/build/legacy/queryObserver.d.ts +1 -1
  105. package/build/legacy/queryObserver.js +116 -2
  106. package/build/legacy/queryObserver.js.map +1 -1
  107. package/build/legacy/retryer.cjs +18 -0
  108. package/build/legacy/retryer.cjs.map +1 -1
  109. package/build/legacy/retryer.d.cts +1 -1
  110. package/build/legacy/retryer.d.ts +1 -1
  111. package/build/legacy/retryer.js +18 -0
  112. package/build/legacy/retryer.js.map +1 -1
  113. package/build/legacy/streamedQuery.cjs +10 -1
  114. package/build/legacy/streamedQuery.cjs.map +1 -1
  115. package/build/legacy/streamedQuery.d.cts +26 -2
  116. package/build/legacy/streamedQuery.d.cts.map +1 -1
  117. package/build/legacy/streamedQuery.d.ts +26 -2
  118. package/build/legacy/streamedQuery.d.ts.map +1 -1
  119. package/build/legacy/streamedQuery.js +10 -1
  120. package/build/legacy/streamedQuery.js.map +1 -1
  121. package/build/legacy/timeoutManager.cjs +99 -0
  122. package/build/legacy/timeoutManager.cjs.map +1 -1
  123. package/build/legacy/timeoutManager.d.cts +105 -0
  124. package/build/legacy/timeoutManager.d.cts.map +1 -1
  125. package/build/legacy/timeoutManager.d.ts +105 -0
  126. package/build/legacy/timeoutManager.d.ts.map +1 -1
  127. package/build/legacy/timeoutManager.js +99 -0
  128. package/build/legacy/timeoutManager.js.map +1 -1
  129. package/build/legacy/types.cjs.map +1 -1
  130. package/build/legacy/types.d.cts +1 -1
  131. package/build/legacy/types.d.ts +1 -1
  132. package/build/legacy/types.js.map +1 -1
  133. package/build/legacy/utils.cjs +76 -0
  134. package/build/legacy/utils.cjs.map +1 -1
  135. package/build/legacy/utils.d.cts +1 -1
  136. package/build/legacy/utils.d.ts +1 -1
  137. package/build/legacy/utils.js +76 -0
  138. package/build/legacy/utils.js.map +1 -1
  139. package/build/modern/environmentManager.cjs +15 -1
  140. package/build/modern/environmentManager.cjs.map +1 -1
  141. package/build/modern/environmentManager.d.cts +15 -1
  142. package/build/modern/environmentManager.d.cts.map +1 -1
  143. package/build/modern/environmentManager.d.ts +15 -1
  144. package/build/modern/environmentManager.d.ts.map +1 -1
  145. package/build/modern/environmentManager.js +15 -1
  146. package/build/modern/environmentManager.js.map +1 -1
  147. package/build/modern/focusManager.cjs +57 -0
  148. package/build/modern/focusManager.cjs.map +1 -1
  149. package/build/modern/focusManager.d.cts +57 -0
  150. package/build/modern/focusManager.d.cts.map +1 -1
  151. package/build/modern/focusManager.d.ts +57 -0
  152. package/build/modern/focusManager.d.ts.map +1 -1
  153. package/build/modern/focusManager.js +57 -0
  154. package/build/modern/focusManager.js.map +1 -1
  155. package/build/modern/{hydration-Bjs0MSgg.d.ts → hydration-Cq7QYAzB.d.ts} +1424 -7
  156. package/build/modern/hydration-Cq7QYAzB.d.ts.map +1 -0
  157. package/build/modern/{hydration-DWGr3cFC.d.cts → hydration-DwR10Hi-.d.cts} +1424 -7
  158. package/build/modern/hydration-DwR10Hi-.d.cts.map +1 -0
  159. package/build/modern/hydration.cjs +57 -4
  160. package/build/modern/hydration.cjs.map +1 -1
  161. package/build/modern/hydration.d.cts +1 -1
  162. package/build/modern/hydration.d.ts +1 -1
  163. package/build/modern/hydration.js +57 -4
  164. package/build/modern/hydration.js.map +1 -1
  165. package/build/modern/index.cjs.map +1 -1
  166. package/build/modern/index.d.cts +5 -5
  167. package/build/modern/index.d.ts +5 -5
  168. package/build/modern/index.js.map +1 -1
  169. package/build/modern/infiniteQueryBehavior.d.cts +1 -1
  170. package/build/modern/infiniteQueryBehavior.d.ts +1 -1
  171. package/build/modern/infiniteQueryObserver.cjs +67 -0
  172. package/build/modern/infiniteQueryObserver.cjs.map +1 -1
  173. package/build/modern/infiniteQueryObserver.d.cts +68 -1
  174. package/build/modern/infiniteQueryObserver.d.cts.map +1 -1
  175. package/build/modern/infiniteQueryObserver.d.ts +68 -1
  176. package/build/modern/infiniteQueryObserver.d.ts.map +1 -1
  177. package/build/modern/infiniteQueryObserver.js +67 -0
  178. package/build/modern/infiniteQueryObserver.js.map +1 -1
  179. package/build/modern/mutation.cjs +74 -0
  180. package/build/modern/mutation.cjs.map +1 -1
  181. package/build/modern/mutation.d.cts +1 -1
  182. package/build/modern/mutation.d.ts +1 -1
  183. package/build/modern/mutation.js +74 -0
  184. package/build/modern/mutation.js.map +1 -1
  185. package/build/modern/mutationCache.cjs +74 -0
  186. package/build/modern/mutationCache.cjs.map +1 -1
  187. package/build/modern/mutationCache.d.cts +1 -1
  188. package/build/modern/mutationCache.d.ts +1 -1
  189. package/build/modern/mutationCache.js +74 -0
  190. package/build/modern/mutationCache.js.map +1 -1
  191. package/build/modern/mutationObserver.cjs +71 -0
  192. package/build/modern/mutationObserver.cjs.map +1 -1
  193. package/build/modern/mutationObserver.d.cts +1 -1
  194. package/build/modern/mutationObserver.d.ts +1 -1
  195. package/build/modern/mutationObserver.js +71 -0
  196. package/build/modern/mutationObserver.js.map +1 -1
  197. package/build/modern/notifyManager.cjs +45 -1
  198. package/build/modern/notifyManager.cjs.map +1 -1
  199. package/build/modern/notifyManager.d.cts +83 -2
  200. package/build/modern/notifyManager.d.cts.map +1 -1
  201. package/build/modern/notifyManager.d.ts +83 -2
  202. package/build/modern/notifyManager.d.ts.map +1 -1
  203. package/build/modern/notifyManager.js +45 -1
  204. package/build/modern/notifyManager.js.map +1 -1
  205. package/build/modern/onlineManager.cjs +47 -0
  206. package/build/modern/onlineManager.cjs.map +1 -1
  207. package/build/modern/onlineManager.d.cts +47 -0
  208. package/build/modern/onlineManager.d.cts.map +1 -1
  209. package/build/modern/onlineManager.d.ts +47 -0
  210. package/build/modern/onlineManager.d.ts.map +1 -1
  211. package/build/modern/onlineManager.js +47 -0
  212. package/build/modern/onlineManager.js.map +1 -1
  213. package/build/modern/queriesObserver.cjs +64 -0
  214. package/build/modern/queriesObserver.cjs.map +1 -1
  215. package/build/modern/queriesObserver.d.cts +73 -1
  216. package/build/modern/queriesObserver.d.cts.map +1 -1
  217. package/build/modern/queriesObserver.d.ts +73 -1
  218. package/build/modern/queriesObserver.d.ts.map +1 -1
  219. package/build/modern/queriesObserver.js +64 -0
  220. package/build/modern/queriesObserver.js.map +1 -1
  221. package/build/modern/query.cjs +141 -0
  222. package/build/modern/query.cjs.map +1 -1
  223. package/build/modern/query.d.cts +1 -1
  224. package/build/modern/query.d.ts +1 -1
  225. package/build/modern/query.js +141 -0
  226. package/build/modern/query.js.map +1 -1
  227. package/build/modern/queryCache.cjs +120 -0
  228. package/build/modern/queryCache.cjs.map +1 -1
  229. package/build/modern/queryCache.d.cts +1 -1
  230. package/build/modern/queryCache.d.ts +1 -1
  231. package/build/modern/queryCache.js +120 -0
  232. package/build/modern/queryCache.js.map +1 -1
  233. package/build/modern/queryClient.cjs +363 -0
  234. package/build/modern/queryClient.cjs.map +1 -1
  235. package/build/modern/queryClient.d.cts +1 -1
  236. package/build/modern/queryClient.d.ts +1 -1
  237. package/build/modern/queryClient.js +363 -0
  238. package/build/modern/queryClient.js.map +1 -1
  239. package/build/modern/queryObserver.cjs +116 -2
  240. package/build/modern/queryObserver.cjs.map +1 -1
  241. package/build/modern/queryObserver.d.cts +1 -1
  242. package/build/modern/queryObserver.d.ts +1 -1
  243. package/build/modern/queryObserver.js +116 -2
  244. package/build/modern/queryObserver.js.map +1 -1
  245. package/build/modern/retryer.cjs +18 -0
  246. package/build/modern/retryer.cjs.map +1 -1
  247. package/build/modern/retryer.d.cts +1 -1
  248. package/build/modern/retryer.d.ts +1 -1
  249. package/build/modern/retryer.js +18 -0
  250. package/build/modern/retryer.js.map +1 -1
  251. package/build/modern/streamedQuery.cjs +10 -1
  252. package/build/modern/streamedQuery.cjs.map +1 -1
  253. package/build/modern/streamedQuery.d.cts +26 -2
  254. package/build/modern/streamedQuery.d.cts.map +1 -1
  255. package/build/modern/streamedQuery.d.ts +26 -2
  256. package/build/modern/streamedQuery.d.ts.map +1 -1
  257. package/build/modern/streamedQuery.js +10 -1
  258. package/build/modern/streamedQuery.js.map +1 -1
  259. package/build/modern/timeoutManager.cjs +99 -0
  260. package/build/modern/timeoutManager.cjs.map +1 -1
  261. package/build/modern/timeoutManager.d.cts +105 -0
  262. package/build/modern/timeoutManager.d.cts.map +1 -1
  263. package/build/modern/timeoutManager.d.ts +105 -0
  264. package/build/modern/timeoutManager.d.ts.map +1 -1
  265. package/build/modern/timeoutManager.js +99 -0
  266. package/build/modern/timeoutManager.js.map +1 -1
  267. package/build/modern/types.cjs.map +1 -1
  268. package/build/modern/types.d.cts +1 -1
  269. package/build/modern/types.d.ts +1 -1
  270. package/build/modern/types.js.map +1 -1
  271. package/build/modern/utils.cjs +76 -0
  272. package/build/modern/utils.cjs.map +1 -1
  273. package/build/modern/utils.d.cts +1 -1
  274. package/build/modern/utils.d.ts +1 -1
  275. package/build/modern/utils.js +76 -0
  276. package/build/modern/utils.js.map +1 -1
  277. package/package.json +9 -9
  278. package/src/environmentManager.ts +15 -1
  279. package/src/focusManager.ts +57 -0
  280. package/src/hydration.ts +82 -16
  281. package/src/index.ts +3 -0
  282. package/src/infiniteQueryObserver.ts +67 -0
  283. package/src/mutation.ts +108 -0
  284. package/src/mutationCache.ts +91 -0
  285. package/src/mutationObserver.ts +71 -0
  286. package/src/notifyManager.ts +46 -1
  287. package/src/onlineManager.ts +47 -0
  288. package/src/queriesObserver.ts +72 -0
  289. package/src/query.ts +193 -0
  290. package/src/queryCache.ts +134 -0
  291. package/src/queryClient.ts +369 -0
  292. package/src/queryObserver.ts +117 -4
  293. package/src/retryer.ts +18 -0
  294. package/src/streamedQuery.ts +25 -1
  295. package/src/timeoutManager.ts +105 -0
  296. package/src/types.ts +147 -5
  297. package/src/utils.ts +107 -0
  298. package/build/legacy/hydration-Bjs0MSgg.d.ts.map +0 -1
  299. package/build/legacy/hydration-DWGr3cFC.d.cts.map +0 -1
  300. package/build/modern/hydration-Bjs0MSgg.d.ts.map +0 -1
  301. package/build/modern/hydration-DWGr3cFC.d.cts.map +0 -1
@@ -4,13 +4,27 @@ type NotifyFunction = (callback: () => void) => void;
4
4
  type BatchNotifyFunction = (callback: () => void) => void;
5
5
  type BatchCallsCallback<T extends Array<unknown>> = (...args: T) => void;
6
6
  type ScheduleFunction = (callback: () => void) => void;
7
+ /**
8
+ * Default scheduling function used by the notify manager.
9
+ * Schedules the callback with the system's `setTimeout(callback, 0)`.
10
+ */
7
11
  declare const defaultScheduler: ScheduleFunction;
8
12
  declare function createNotifyManager(): {
13
+ /**
14
+ * Batches all updates scheduled inside the passed callback.
15
+ * This is mainly used internally to optimize query client updating.
16
+ * Batches can be nested; the queue is only flushed once the outermost `batch` call finishes.
17
+ * The return value of `callback` is passed through.
18
+ */
9
19
  readonly batch: <T>(callback: () => T) => T;
10
20
  /**
11
21
  * All calls to the wrapped function will be batched.
12
22
  */
13
23
  readonly batchCalls: <T extends Array<unknown>>(callback: BatchCallsCallback<T>) => BatchCallsCallback<T>;
24
+ /**
25
+ * Schedules a function to be run on the next batch.
26
+ * By default, the batch is run with a `setTimeout`, but this can be configured via `setScheduler`.
27
+ */
14
28
  readonly schedule: (callback: NotifyCallback) => void;
15
29
  /**
16
30
  * Use this method to set a custom notify function.
@@ -19,17 +33,57 @@ declare function createNotifyManager(): {
19
33
  readonly setNotifyFunction: (fn: NotifyFunction) => void;
20
34
  /**
21
35
  * Use this method to set a custom function to batch notifications together into a single tick.
22
- * By default React Query will use the batch function provided by ReactDOM or React Native.
36
+ * Framework adapters use this to plug in their own batching primitive, so that a single query
37
+ * update only triggers one re-render instead of one per subscriber.
38
+ *
39
+ * @example
40
+ * ```ts
41
+ * import { notifyManager } from '@tanstack/query-core'
42
+ * import { batch } from 'solid-js'
43
+ *
44
+ * notifyManager.setBatchNotifyFunction(batch)
45
+ * ```
23
46
  */
24
47
  readonly setBatchNotifyFunction: (fn: BatchNotifyFunction) => void;
48
+ /**
49
+ * Configures a custom callback that schedules when the next batch runs.
50
+ * The default behavior is `setTimeout(callback, 0)`.
51
+ *
52
+ * @example
53
+ * ```ts
54
+ * import { notifyManager } from '@tanstack/query-core'
55
+ *
56
+ * // Schedule batches in the next microtask
57
+ * notifyManager.setScheduler(queueMicrotask)
58
+ *
59
+ * // Schedule batches before the next frame is rendered
60
+ * notifyManager.setScheduler(requestAnimationFrame)
61
+ *
62
+ * // Schedule batches some time in the future
63
+ * notifyManager.setScheduler((cb) => setTimeout(cb, 10))
64
+ * ```
65
+ */
25
66
  readonly setScheduler: (fn: ScheduleFunction) => void;
26
67
  };
68
+ /**
69
+ * Handles scheduling and batching callbacks in TanStack Query.
70
+ */
27
71
  declare const notifyManager: {
72
+ /**
73
+ * Batches all updates scheduled inside the passed callback.
74
+ * This is mainly used internally to optimize query client updating.
75
+ * Batches can be nested; the queue is only flushed once the outermost `batch` call finishes.
76
+ * The return value of `callback` is passed through.
77
+ */
28
78
  readonly batch: <T>(callback: () => T) => T;
29
79
  /**
30
80
  * All calls to the wrapped function will be batched.
31
81
  */
32
82
  readonly batchCalls: <T extends Array<unknown>>(callback: BatchCallsCallback<T>) => BatchCallsCallback<T>;
83
+ /**
84
+ * Schedules a function to be run on the next batch.
85
+ * By default, the batch is run with a `setTimeout`, but this can be configured via `setScheduler`.
86
+ */
33
87
  readonly schedule: (callback: NotifyCallback) => void;
34
88
  /**
35
89
  * Use this method to set a custom notify function.
@@ -38,9 +92,36 @@ declare const notifyManager: {
38
92
  readonly setNotifyFunction: (fn: NotifyFunction) => void;
39
93
  /**
40
94
  * Use this method to set a custom function to batch notifications together into a single tick.
41
- * By default React Query will use the batch function provided by ReactDOM or React Native.
95
+ * Framework adapters use this to plug in their own batching primitive, so that a single query
96
+ * update only triggers one re-render instead of one per subscriber.
97
+ *
98
+ * @example
99
+ * ```ts
100
+ * import { notifyManager } from '@tanstack/query-core'
101
+ * import { batch } from 'solid-js'
102
+ *
103
+ * notifyManager.setBatchNotifyFunction(batch)
104
+ * ```
42
105
  */
43
106
  readonly setBatchNotifyFunction: (fn: BatchNotifyFunction) => void;
107
+ /**
108
+ * Configures a custom callback that schedules when the next batch runs.
109
+ * The default behavior is `setTimeout(callback, 0)`.
110
+ *
111
+ * @example
112
+ * ```ts
113
+ * import { notifyManager } from '@tanstack/query-core'
114
+ *
115
+ * // Schedule batches in the next microtask
116
+ * notifyManager.setScheduler(queueMicrotask)
117
+ *
118
+ * // Schedule batches before the next frame is rendered
119
+ * notifyManager.setScheduler(requestAnimationFrame)
120
+ *
121
+ * // Schedule batches some time in the future
122
+ * notifyManager.setScheduler((cb) => setTimeout(cb, 10))
123
+ * ```
124
+ */
44
125
  readonly setScheduler: (fn: ScheduleFunction) => void;
45
126
  };
46
127
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"notifyManager.d.cts","names":[],"sources":["../../src/notifyManager.ts"],"mappings":";KAIK;KAEA,kBAAkB;KAElB,uBAAuB;KAEvB,mBAAmB,UAAU,sBAAsB,MAAM;KAEzD,oBAAoB;cAEZ,kBAAkB;iBAEf;WAmCJ,QAAA,GAAC,gBAAkB,MAAI;;;;WAgBlB,aAAA,UAAU,gBAAc,UACzB,mBAAmB,OAC5B,mBAAmB;WA1CI,WAAA,UAAA;;;;;WAsDF,oBAAA,IAAA;;;;;WAOK,yBAAA,IAAA;WAGV,eAAA,IAAA;;cAOV;WA/CD,QAAA,GAAC,gBAAkB,MAAI;;;;WAgBlB,aAAA,UAAU,gBAAc,UACzB,mBAAmB,OAC5B,mBAAmB;WA1CI,WAAA,UAAA;;;;;WAsDF,oBAAA,IAAA;;;;;WAOK,yBAAA,IAAA;WAGV,eAAA,IAAA"}
1
+ {"version":3,"file":"notifyManager.d.cts","names":[],"sources":["../../src/notifyManager.ts"],"mappings":";KAIK;KAEA,kBAAkB;KAElB,uBAAuB;KAEvB,mBAAmB,UAAU,sBAAsB,MAAM;KAEzD,oBAAoB;;;;;cAMZ,kBAAkB;iBAEf;;;;;;;WAyCJ,QAAA,GAAC,gBAAkB,MAAI;;;;WAgBlB,aAAA,UAAU,gBAAc,UACzB,mBAAmB,OAC5B,mBAAmB;;;;;WAhDI,WAAA,UAAA;;;;;WAgEF,oBAAA,IAAA;;;;;;;;;;;;;;WAgBK,yBAAA,IAAA;;;;;;;;;;;;;;;;;;;WAqBV,eAAA,IAAA;;;;;cAWV;;;;;;;WAlFD,QAAA,GAAC,gBAAkB,MAAI;;;;WAgBlB,aAAA,UAAU,gBAAc,UACzB,mBAAmB,OAC5B,mBAAmB;;;;;WAhDI,WAAA,UAAA;;;;;WAgEF,oBAAA,IAAA;;;;;;;;;;;;;;WAgBK,yBAAA,IAAA;;;;;;;;;;;;;;;;;;;WAqBV,eAAA,IAAA"}
@@ -4,13 +4,27 @@ type NotifyFunction = (callback: () => void) => void;
4
4
  type BatchNotifyFunction = (callback: () => void) => void;
5
5
  type BatchCallsCallback<T extends Array<unknown>> = (...args: T) => void;
6
6
  type ScheduleFunction = (callback: () => void) => void;
7
+ /**
8
+ * Default scheduling function used by the notify manager.
9
+ * Schedules the callback with the system's `setTimeout(callback, 0)`.
10
+ */
7
11
  declare const defaultScheduler: ScheduleFunction;
8
12
  declare function createNotifyManager(): {
13
+ /**
14
+ * Batches all updates scheduled inside the passed callback.
15
+ * This is mainly used internally to optimize query client updating.
16
+ * Batches can be nested; the queue is only flushed once the outermost `batch` call finishes.
17
+ * The return value of `callback` is passed through.
18
+ */
9
19
  readonly batch: <T>(callback: () => T) => T;
10
20
  /**
11
21
  * All calls to the wrapped function will be batched.
12
22
  */
13
23
  readonly batchCalls: <T extends Array<unknown>>(callback: BatchCallsCallback<T>) => BatchCallsCallback<T>;
24
+ /**
25
+ * Schedules a function to be run on the next batch.
26
+ * By default, the batch is run with a `setTimeout`, but this can be configured via `setScheduler`.
27
+ */
14
28
  readonly schedule: (callback: NotifyCallback) => void;
15
29
  /**
16
30
  * Use this method to set a custom notify function.
@@ -19,17 +33,57 @@ declare function createNotifyManager(): {
19
33
  readonly setNotifyFunction: (fn: NotifyFunction) => void;
20
34
  /**
21
35
  * Use this method to set a custom function to batch notifications together into a single tick.
22
- * By default React Query will use the batch function provided by ReactDOM or React Native.
36
+ * Framework adapters use this to plug in their own batching primitive, so that a single query
37
+ * update only triggers one re-render instead of one per subscriber.
38
+ *
39
+ * @example
40
+ * ```ts
41
+ * import { notifyManager } from '@tanstack/query-core'
42
+ * import { batch } from 'solid-js'
43
+ *
44
+ * notifyManager.setBatchNotifyFunction(batch)
45
+ * ```
23
46
  */
24
47
  readonly setBatchNotifyFunction: (fn: BatchNotifyFunction) => void;
48
+ /**
49
+ * Configures a custom callback that schedules when the next batch runs.
50
+ * The default behavior is `setTimeout(callback, 0)`.
51
+ *
52
+ * @example
53
+ * ```ts
54
+ * import { notifyManager } from '@tanstack/query-core'
55
+ *
56
+ * // Schedule batches in the next microtask
57
+ * notifyManager.setScheduler(queueMicrotask)
58
+ *
59
+ * // Schedule batches before the next frame is rendered
60
+ * notifyManager.setScheduler(requestAnimationFrame)
61
+ *
62
+ * // Schedule batches some time in the future
63
+ * notifyManager.setScheduler((cb) => setTimeout(cb, 10))
64
+ * ```
65
+ */
25
66
  readonly setScheduler: (fn: ScheduleFunction) => void;
26
67
  };
68
+ /**
69
+ * Handles scheduling and batching callbacks in TanStack Query.
70
+ */
27
71
  declare const notifyManager: {
72
+ /**
73
+ * Batches all updates scheduled inside the passed callback.
74
+ * This is mainly used internally to optimize query client updating.
75
+ * Batches can be nested; the queue is only flushed once the outermost `batch` call finishes.
76
+ * The return value of `callback` is passed through.
77
+ */
28
78
  readonly batch: <T>(callback: () => T) => T;
29
79
  /**
30
80
  * All calls to the wrapped function will be batched.
31
81
  */
32
82
  readonly batchCalls: <T extends Array<unknown>>(callback: BatchCallsCallback<T>) => BatchCallsCallback<T>;
83
+ /**
84
+ * Schedules a function to be run on the next batch.
85
+ * By default, the batch is run with a `setTimeout`, but this can be configured via `setScheduler`.
86
+ */
33
87
  readonly schedule: (callback: NotifyCallback) => void;
34
88
  /**
35
89
  * Use this method to set a custom notify function.
@@ -38,9 +92,36 @@ declare const notifyManager: {
38
92
  readonly setNotifyFunction: (fn: NotifyFunction) => void;
39
93
  /**
40
94
  * Use this method to set a custom function to batch notifications together into a single tick.
41
- * By default React Query will use the batch function provided by ReactDOM or React Native.
95
+ * Framework adapters use this to plug in their own batching primitive, so that a single query
96
+ * update only triggers one re-render instead of one per subscriber.
97
+ *
98
+ * @example
99
+ * ```ts
100
+ * import { notifyManager } from '@tanstack/query-core'
101
+ * import { batch } from 'solid-js'
102
+ *
103
+ * notifyManager.setBatchNotifyFunction(batch)
104
+ * ```
42
105
  */
43
106
  readonly setBatchNotifyFunction: (fn: BatchNotifyFunction) => void;
107
+ /**
108
+ * Configures a custom callback that schedules when the next batch runs.
109
+ * The default behavior is `setTimeout(callback, 0)`.
110
+ *
111
+ * @example
112
+ * ```ts
113
+ * import { notifyManager } from '@tanstack/query-core'
114
+ *
115
+ * // Schedule batches in the next microtask
116
+ * notifyManager.setScheduler(queueMicrotask)
117
+ *
118
+ * // Schedule batches before the next frame is rendered
119
+ * notifyManager.setScheduler(requestAnimationFrame)
120
+ *
121
+ * // Schedule batches some time in the future
122
+ * notifyManager.setScheduler((cb) => setTimeout(cb, 10))
123
+ * ```
124
+ */
44
125
  readonly setScheduler: (fn: ScheduleFunction) => void;
45
126
  };
46
127
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"notifyManager.d.ts","names":[],"sources":["../../src/notifyManager.ts"],"mappings":";KAIK;KAEA,kBAAkB;KAElB,uBAAuB;KAEvB,mBAAmB,UAAU,sBAAsB,MAAM;KAEzD,oBAAoB;cAEZ,kBAAkB;iBAEf;WAmCJ,QAAA,GAAC,gBAAkB,MAAI;;;;WAgBlB,aAAA,UAAU,gBAAc,UACzB,mBAAmB,OAC5B,mBAAmB;WA1CI,WAAA,UAAA;;;;;WAsDF,oBAAA,IAAA;;;;;WAOK,yBAAA,IAAA;WAGV,eAAA,IAAA;;cAOV;WA/CD,QAAA,GAAC,gBAAkB,MAAI;;;;WAgBlB,aAAA,UAAU,gBAAc,UACzB,mBAAmB,OAC5B,mBAAmB;WA1CI,WAAA,UAAA;;;;;WAsDF,oBAAA,IAAA;;;;;WAOK,yBAAA,IAAA;WAGV,eAAA,IAAA"}
1
+ {"version":3,"file":"notifyManager.d.ts","names":[],"sources":["../../src/notifyManager.ts"],"mappings":";KAIK;KAEA,kBAAkB;KAElB,uBAAuB;KAEvB,mBAAmB,UAAU,sBAAsB,MAAM;KAEzD,oBAAoB;;;;;cAMZ,kBAAkB;iBAEf;;;;;;;WAyCJ,QAAA,GAAC,gBAAkB,MAAI;;;;WAgBlB,aAAA,UAAU,gBAAc,UACzB,mBAAmB,OAC5B,mBAAmB;;;;;WAhDI,WAAA,UAAA;;;;;WAgEF,oBAAA,IAAA;;;;;;;;;;;;;;WAgBK,yBAAA,IAAA;;;;;;;;;;;;;;;;;;;WAqBV,eAAA,IAAA;;;;;cAWV;;;;;;;WAlFD,QAAA,GAAC,gBAAkB,MAAI;;;;WAgBlB,aAAA,UAAU,gBAAc,UACzB,mBAAmB,OAC5B,mBAAmB;;;;;WAhDI,WAAA,UAAA;;;;;WAgEF,oBAAA,IAAA;;;;;;;;;;;;;;WAgBK,yBAAA,IAAA;;;;;;;;;;;;;;;;;;;WAqBV,eAAA,IAAA"}
@@ -1,5 +1,9 @@
1
1
  import { systemSetTimeoutZero } from "./timeoutManager.js";
2
2
  //#region src/notifyManager.ts
3
+ /**
4
+ * Default scheduling function used by the notify manager.
5
+ * Schedules the callback with the system's `setTimeout(callback, 0)`.
6
+ */
3
7
  const defaultScheduler = systemSetTimeoutZero;
4
8
  function createNotifyManager() {
5
9
  let queue = [];
@@ -29,6 +33,12 @@ function createNotifyManager() {
29
33
  });
30
34
  };
31
35
  return {
36
+ /**
37
+ * Batches all updates scheduled inside the passed callback.
38
+ * This is mainly used internally to optimize query client updating.
39
+ * Batches can be nested; the queue is only flushed once the outermost `batch` call finishes.
40
+ * The return value of `callback` is passed through.
41
+ */
32
42
  batch: (callback) => {
33
43
  let result;
34
44
  transactions++;
@@ -50,6 +60,10 @@ function createNotifyManager() {
50
60
  });
51
61
  };
52
62
  },
63
+ /**
64
+ * Schedules a function to be run on the next batch.
65
+ * By default, the batch is run with a `setTimeout`, but this can be configured via `setScheduler`.
66
+ */
53
67
  schedule,
54
68
  /**
55
69
  * Use this method to set a custom notify function.
@@ -60,16 +74,46 @@ function createNotifyManager() {
60
74
  },
61
75
  /**
62
76
  * Use this method to set a custom function to batch notifications together into a single tick.
63
- * By default React Query will use the batch function provided by ReactDOM or React Native.
77
+ * Framework adapters use this to plug in their own batching primitive, so that a single query
78
+ * update only triggers one re-render instead of one per subscriber.
79
+ *
80
+ * @example
81
+ * ```ts
82
+ * import { notifyManager } from '@tanstack/query-core'
83
+ * import { batch } from 'solid-js'
84
+ *
85
+ * notifyManager.setBatchNotifyFunction(batch)
86
+ * ```
64
87
  */
65
88
  setBatchNotifyFunction: (fn) => {
66
89
  batchNotifyFn = fn;
67
90
  },
91
+ /**
92
+ * Configures a custom callback that schedules when the next batch runs.
93
+ * The default behavior is `setTimeout(callback, 0)`.
94
+ *
95
+ * @example
96
+ * ```ts
97
+ * import { notifyManager } from '@tanstack/query-core'
98
+ *
99
+ * // Schedule batches in the next microtask
100
+ * notifyManager.setScheduler(queueMicrotask)
101
+ *
102
+ * // Schedule batches before the next frame is rendered
103
+ * notifyManager.setScheduler(requestAnimationFrame)
104
+ *
105
+ * // Schedule batches some time in the future
106
+ * notifyManager.setScheduler((cb) => setTimeout(cb, 10))
107
+ * ```
108
+ */
68
109
  setScheduler: (fn) => {
69
110
  scheduleFn = fn;
70
111
  }
71
112
  };
72
113
  }
114
+ /**
115
+ * Handles scheduling and batching callbacks in TanStack Query.
116
+ */
73
117
  const notifyManager = createNotifyManager();
74
118
  //#endregion
75
119
  export { createNotifyManager, defaultScheduler, notifyManager };
@@ -1 +1 @@
1
- {"version":3,"file":"notifyManager.js","names":[],"sources":["../../src/notifyManager.ts"],"sourcesContent":["// TYPES\n\nimport { systemSetTimeoutZero } from './timeoutManager'\n\ntype NotifyCallback = () => void\n\ntype NotifyFunction = (callback: () => void) => void\n\ntype BatchNotifyFunction = (callback: () => void) => void\n\ntype BatchCallsCallback<T extends Array<unknown>> = (...args: T) => void\n\ntype ScheduleFunction = (callback: () => void) => void\n\nexport const defaultScheduler: ScheduleFunction = systemSetTimeoutZero\n\nexport function createNotifyManager() {\n let queue: Array<NotifyCallback> = []\n let transactions = 0\n let notifyFn: NotifyFunction = (callback) => {\n callback()\n }\n let batchNotifyFn: BatchNotifyFunction = (callback: () => void) => {\n callback()\n }\n let scheduleFn = defaultScheduler\n\n const schedule = (callback: NotifyCallback): void => {\n if (transactions) {\n queue.push(callback)\n } else {\n scheduleFn(() => {\n notifyFn(callback)\n })\n }\n }\n const flush = (): void => {\n const originalQueue = queue\n queue = []\n if (originalQueue.length) {\n scheduleFn(() => {\n batchNotifyFn(() => {\n originalQueue.forEach((callback) => {\n notifyFn(callback)\n })\n })\n })\n }\n }\n\n return {\n batch: <T>(callback: () => T): T => {\n let result\n transactions++\n try {\n result = callback()\n } finally {\n transactions--\n if (!transactions) {\n flush()\n }\n }\n return result\n },\n /**\n * All calls to the wrapped function will be batched.\n */\n batchCalls: <T extends Array<unknown>>(\n callback: BatchCallsCallback<T>,\n ): BatchCallsCallback<T> => {\n return (...args) => {\n schedule(() => {\n callback(...args)\n })\n }\n },\n schedule,\n /**\n * Use this method to set a custom notify function.\n * This can be used to for example wrap notifications with `React.act` while running tests.\n */\n setNotifyFunction: (fn: NotifyFunction) => {\n notifyFn = fn\n },\n /**\n * Use this method to set a custom function to batch notifications together into a single tick.\n * By default React Query will use the batch function provided by ReactDOM or React Native.\n */\n setBatchNotifyFunction: (fn: BatchNotifyFunction) => {\n batchNotifyFn = fn\n },\n setScheduler: (fn: ScheduleFunction) => {\n scheduleFn = fn\n },\n } as const\n}\n\n// SINGLETON\nexport const notifyManager = createNotifyManager()\n"],"mappings":";;AAcA,MAAa,mBAAqC;AAElD,SAAgB,sBAAsB;CACpC,IAAI,QAA+B,CAAC;CACpC,IAAI,eAAe;CACnB,IAAI,YAA4B,aAAa;EAC3C,SAAS;CACX;CACA,IAAI,iBAAsC,aAAyB;EACjE,SAAS;CACX;CACA,IAAI,aAAa;CAEjB,MAAM,YAAY,aAAmC;EACnD,IAAI,cACF,MAAM,KAAK,QAAQ;OAEnB,iBAAiB;GACf,SAAS,QAAQ;EACnB,CAAC;CAEL;CACA,MAAM,cAAoB;EACxB,MAAM,gBAAgB;EACtB,QAAQ,CAAC;EACT,IAAI,cAAc,QAChB,iBAAiB;GACf,oBAAoB;IAClB,cAAc,SAAS,aAAa;KAClC,SAAS,QAAQ;IACnB,CAAC;GACH,CAAC;EACH,CAAC;CAEL;CAEA,OAAO;EACL,QAAW,aAAyB;GAClC,IAAI;GACJ;GACA,IAAI;IACF,SAAS,SAAS;GACpB,UAAU;IACR;IACA,IAAI,CAAC,cACH,MAAM;GAEV;GACA,OAAO;EACT;;;;EAIA,aACE,aAC0B;GAC1B,QAAQ,GAAG,SAAS;IAClB,eAAe;KACb,SAAS,GAAG,IAAI;IAClB,CAAC;GACH;EACF;EACA;;;;;EAKA,oBAAoB,OAAuB;GACzC,WAAW;EACb;;;;;EAKA,yBAAyB,OAA4B;GACnD,gBAAgB;EAClB;EACA,eAAe,OAAyB;GACtC,aAAa;EACf;CACF;AACF;AAGA,MAAa,gBAAgB,oBAAoB"}
1
+ {"version":3,"file":"notifyManager.js","names":[],"sources":["../../src/notifyManager.ts"],"sourcesContent":["// TYPES\n\nimport { systemSetTimeoutZero } from './timeoutManager'\n\ntype NotifyCallback = () => void\n\ntype NotifyFunction = (callback: () => void) => void\n\ntype BatchNotifyFunction = (callback: () => void) => void\n\ntype BatchCallsCallback<T extends Array<unknown>> = (...args: T) => void\n\ntype ScheduleFunction = (callback: () => void) => void\n\n/**\n * Default scheduling function used by the notify manager.\n * Schedules the callback with the system's `setTimeout(callback, 0)`.\n */\nexport const defaultScheduler: ScheduleFunction = systemSetTimeoutZero\n\nexport function createNotifyManager() {\n let queue: Array<NotifyCallback> = []\n let transactions = 0\n let notifyFn: NotifyFunction = (callback) => {\n callback()\n }\n let batchNotifyFn: BatchNotifyFunction = (callback: () => void) => {\n callback()\n }\n let scheduleFn = defaultScheduler\n\n const schedule = (callback: NotifyCallback): void => {\n if (transactions) {\n queue.push(callback)\n } else {\n scheduleFn(() => {\n notifyFn(callback)\n })\n }\n }\n const flush = (): void => {\n const originalQueue = queue\n queue = []\n if (originalQueue.length) {\n scheduleFn(() => {\n batchNotifyFn(() => {\n originalQueue.forEach((callback) => {\n notifyFn(callback)\n })\n })\n })\n }\n }\n\n return {\n /**\n * Batches all updates scheduled inside the passed callback.\n * This is mainly used internally to optimize query client updating.\n * Batches can be nested; the queue is only flushed once the outermost `batch` call finishes.\n * The return value of `callback` is passed through.\n */\n batch: <T>(callback: () => T): T => {\n let result\n transactions++\n try {\n result = callback()\n } finally {\n transactions--\n if (!transactions) {\n flush()\n }\n }\n return result\n },\n /**\n * All calls to the wrapped function will be batched.\n */\n batchCalls: <T extends Array<unknown>>(\n callback: BatchCallsCallback<T>,\n ): BatchCallsCallback<T> => {\n return (...args) => {\n schedule(() => {\n callback(...args)\n })\n }\n },\n /**\n * Schedules a function to be run on the next batch.\n * By default, the batch is run with a `setTimeout`, but this can be configured via `setScheduler`.\n */\n schedule,\n /**\n * Use this method to set a custom notify function.\n * This can be used to for example wrap notifications with `React.act` while running tests.\n */\n setNotifyFunction: (fn: NotifyFunction) => {\n notifyFn = fn\n },\n /**\n * Use this method to set a custom function to batch notifications together into a single tick.\n * Framework adapters use this to plug in their own batching primitive, so that a single query\n * update only triggers one re-render instead of one per subscriber.\n *\n * @example\n * ```ts\n * import { notifyManager } from '@tanstack/query-core'\n * import { batch } from 'solid-js'\n *\n * notifyManager.setBatchNotifyFunction(batch)\n * ```\n */\n setBatchNotifyFunction: (fn: BatchNotifyFunction) => {\n batchNotifyFn = fn\n },\n /**\n * Configures a custom callback that schedules when the next batch runs.\n * The default behavior is `setTimeout(callback, 0)`.\n *\n * @example\n * ```ts\n * import { notifyManager } from '@tanstack/query-core'\n *\n * // Schedule batches in the next microtask\n * notifyManager.setScheduler(queueMicrotask)\n *\n * // Schedule batches before the next frame is rendered\n * notifyManager.setScheduler(requestAnimationFrame)\n *\n * // Schedule batches some time in the future\n * notifyManager.setScheduler((cb) => setTimeout(cb, 10))\n * ```\n */\n setScheduler: (fn: ScheduleFunction) => {\n scheduleFn = fn\n },\n } as const\n}\n\n// SINGLETON\n\n/**\n * Handles scheduling and batching callbacks in TanStack Query.\n */\nexport const notifyManager = createNotifyManager()\n"],"mappings":";;;;;;AAkBA,MAAa,mBAAqC;AAElD,SAAgB,sBAAsB;CACpC,IAAI,QAA+B,CAAC;CACpC,IAAI,eAAe;CACnB,IAAI,YAA4B,aAAa;EAC3C,SAAS;CACX;CACA,IAAI,iBAAsC,aAAyB;EACjE,SAAS;CACX;CACA,IAAI,aAAa;CAEjB,MAAM,YAAY,aAAmC;EACnD,IAAI,cACF,MAAM,KAAK,QAAQ;OAEnB,iBAAiB;GACf,SAAS,QAAQ;EACnB,CAAC;CAEL;CACA,MAAM,cAAoB;EACxB,MAAM,gBAAgB;EACtB,QAAQ,CAAC;EACT,IAAI,cAAc,QAChB,iBAAiB;GACf,oBAAoB;IAClB,cAAc,SAAS,aAAa;KAClC,SAAS,QAAQ;IACnB,CAAC;GACH,CAAC;EACH,CAAC;CAEL;CAEA,OAAO;;;;;;;EAOL,QAAW,aAAyB;GAClC,IAAI;GACJ;GACA,IAAI;IACF,SAAS,SAAS;GACpB,UAAU;IACR;IACA,IAAI,CAAC,cACH,MAAM;GAEV;GACA,OAAO;EACT;;;;EAIA,aACE,aAC0B;GAC1B,QAAQ,GAAG,SAAS;IAClB,eAAe;KACb,SAAS,GAAG,IAAI;IAClB,CAAC;GACH;EACF;;;;;EAKA;;;;;EAKA,oBAAoB,OAAuB;GACzC,WAAW;EACb;;;;;;;;;;;;;;EAcA,yBAAyB,OAA4B;GACnD,gBAAgB;EAClB;;;;;;;;;;;;;;;;;;;EAmBA,eAAe,OAAyB;GACtC,aAAa;EACf;CACF;AACF;;;;AAOA,MAAa,gBAAgB,oBAAoB"}
@@ -1,6 +1,15 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_subscribable = require("./subscribable.cjs");
3
3
  //#region src/onlineManager.ts
4
+ /**
5
+ * The `OnlineManager` manages the online state within TanStack Query. It can
6
+ * be used to change the default event listeners or to manually change the
7
+ * online state.
8
+ *
9
+ * By default, the `onlineManager` assumes an active network connection, and
10
+ * listens to the `online` and `offline` events on the `window` object to
11
+ * detect changes.
12
+ */
4
13
  var OnlineManager = class extends require_subscribable.Subscribable {
5
14
  #online = true;
6
15
  #cleanup;
@@ -29,11 +38,43 @@ var OnlineManager = class extends require_subscribable.Subscribable {
29
38
  this.#cleanup = void 0;
30
39
  }
31
40
  }
41
+ /**
42
+ * `setEventListener` can be used to set a custom event listener that will
43
+ * be used to determine the online state. The provided `setup` function
44
+ * receives a `setOnline` callback that should be called with a `boolean`
45
+ * whenever the online state changes.
46
+ *
47
+ * @example
48
+ * ```ts
49
+ * import NetInfo from '@react-native-community/netinfo'
50
+ * import { onlineManager } from '@tanstack/query-core'
51
+ *
52
+ * onlineManager.setEventListener((setOnline) => {
53
+ * return NetInfo.addEventListener((state) => {
54
+ * setOnline(!!state.isConnected)
55
+ * })
56
+ * })
57
+ * ```
58
+ */
32
59
  setEventListener(setup) {
33
60
  this.#setup = setup;
34
61
  this.#cleanup?.();
35
62
  this.#cleanup = setup(this.setOnline.bind(this));
36
63
  }
64
+ /**
65
+ * `setOnline` can be used to manually set the online state.
66
+ *
67
+ * @example
68
+ * ```ts
69
+ * import { onlineManager } from '@tanstack/query-core'
70
+ *
71
+ * // Set to online
72
+ * onlineManager.setOnline(true)
73
+ *
74
+ * // Set to offline
75
+ * onlineManager.setOnline(false)
76
+ * ```
77
+ */
37
78
  setOnline(online) {
38
79
  if (this.#online !== online) {
39
80
  this.#online = online;
@@ -42,10 +83,16 @@ var OnlineManager = class extends require_subscribable.Subscribable {
42
83
  });
43
84
  }
44
85
  }
86
+ /**
87
+ * `isOnline` can be used to get the current online state.
88
+ */
45
89
  isOnline() {
46
90
  return this.#online;
47
91
  }
48
92
  };
93
+ /**
94
+ * Singleton instance of {@link OnlineManager}, used to manage and observe the online state within TanStack Query.
95
+ */
49
96
  const onlineManager = new OnlineManager();
50
97
  //#endregion
51
98
  exports.OnlineManager = OnlineManager;
@@ -1 +1 @@
1
- {"version":3,"file":"onlineManager.cjs","names":["Subscribable","#setup","#cleanup","#online"],"sources":["../../src/onlineManager.ts"],"sourcesContent":["import { Subscribable } from './subscribable'\n\ntype Listener = (online: boolean) => void\ntype SetupFn = (setOnline: Listener) => (() => void) | undefined\n\nexport class OnlineManager extends Subscribable<Listener> {\n #online = true\n #cleanup?: () => void\n\n #setup: SetupFn\n\n constructor() {\n super()\n this.#setup = (onOnline) => {\n // addEventListener does not exist in React Native, but window does\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (typeof window !== 'undefined' && window.addEventListener) {\n const onlineListener = () => onOnline(true)\n const offlineListener = () => onOnline(false)\n // Listen to online\n window.addEventListener('online', onlineListener, false)\n window.addEventListener('offline', offlineListener, false)\n\n return () => {\n // Be sure to unsubscribe if a new handler is set\n window.removeEventListener('online', onlineListener)\n window.removeEventListener('offline', offlineListener)\n }\n }\n\n return\n }\n }\n\n protected onSubscribe(): void {\n if (!this.#cleanup) {\n this.setEventListener(this.#setup)\n }\n }\n\n protected onUnsubscribe() {\n if (!this.hasListeners()) {\n this.#cleanup?.()\n this.#cleanup = undefined\n }\n }\n\n setEventListener(setup: SetupFn): void {\n this.#setup = setup\n this.#cleanup?.()\n this.#cleanup = setup(this.setOnline.bind(this))\n }\n\n setOnline(online: boolean): void {\n const changed = this.#online !== online\n\n if (changed) {\n this.#online = online\n this.listeners.forEach((listener) => {\n listener(online)\n })\n }\n }\n\n isOnline(): boolean {\n return this.#online\n }\n}\n\nexport const onlineManager = new OnlineManager()\n"],"mappings":";;;AAKA,IAAa,gBAAb,cAAmCA,qBAAAA,aAAuB;CACxD,UAAU;CACV;CAEA;CAEA,cAAc;EACZ,MAAM;EACN,KAAKC,UAAU,aAAa;GAG1B,IAAI,OAAO,WAAW,eAAe,OAAO,kBAAkB;IAC5D,MAAM,uBAAuB,SAAS,IAAI;IAC1C,MAAM,wBAAwB,SAAS,KAAK;IAE5C,OAAO,iBAAiB,UAAU,gBAAgB,KAAK;IACvD,OAAO,iBAAiB,WAAW,iBAAiB,KAAK;IAEzD,aAAa;KAEX,OAAO,oBAAoB,UAAU,cAAc;KACnD,OAAO,oBAAoB,WAAW,eAAe;IACvD;GACF;EAGF;CACF;CAEA,cAA8B;EAC5B,IAAI,CAAC,KAAKC,UACR,KAAK,iBAAiB,KAAKD,MAAM;CAErC;CAEA,gBAA0B;EACxB,IAAI,CAAC,KAAK,aAAa,GAAG;GACxB,KAAKC,WAAW;GAChB,KAAKA,WAAW,KAAA;EAClB;CACF;CAEA,iBAAiB,OAAsB;EACrC,KAAKD,SAAS;EACd,KAAKC,WAAW;EAChB,KAAKA,WAAW,MAAM,KAAK,UAAU,KAAK,IAAI,CAAC;CACjD;CAEA,UAAU,QAAuB;EAG/B,IAFgB,KAAKC,YAAY,QAEpB;GACX,KAAKA,UAAU;GACf,KAAK,UAAU,SAAS,aAAa;IACnC,SAAS,MAAM;GACjB,CAAC;EACH;CACF;CAEA,WAAoB;EAClB,OAAO,KAAKA;CACd;AACF;AAEA,MAAa,gBAAgB,IAAI,cAAc"}
1
+ {"version":3,"file":"onlineManager.cjs","names":["Subscribable","#setup","#cleanup","#online"],"sources":["../../src/onlineManager.ts"],"sourcesContent":["import { Subscribable } from './subscribable'\n\ntype Listener = (online: boolean) => void\ntype SetupFn = (setOnline: Listener) => (() => void) | undefined\n\n/**\n * The `OnlineManager` manages the online state within TanStack Query. It can\n * be used to change the default event listeners or to manually change the\n * online state.\n *\n * By default, the `onlineManager` assumes an active network connection, and\n * listens to the `online` and `offline` events on the `window` object to\n * detect changes.\n */\nexport class OnlineManager extends Subscribable<Listener> {\n #online = true\n #cleanup?: () => void\n\n #setup: SetupFn\n\n constructor() {\n super()\n this.#setup = (onOnline) => {\n // addEventListener does not exist in React Native, but window does\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (typeof window !== 'undefined' && window.addEventListener) {\n const onlineListener = () => onOnline(true)\n const offlineListener = () => onOnline(false)\n // Listen to online\n window.addEventListener('online', onlineListener, false)\n window.addEventListener('offline', offlineListener, false)\n\n return () => {\n // Be sure to unsubscribe if a new handler is set\n window.removeEventListener('online', onlineListener)\n window.removeEventListener('offline', offlineListener)\n }\n }\n\n return\n }\n }\n\n protected onSubscribe(): void {\n if (!this.#cleanup) {\n this.setEventListener(this.#setup)\n }\n }\n\n protected onUnsubscribe() {\n if (!this.hasListeners()) {\n this.#cleanup?.()\n this.#cleanup = undefined\n }\n }\n\n /**\n * `setEventListener` can be used to set a custom event listener that will\n * be used to determine the online state. The provided `setup` function\n * receives a `setOnline` callback that should be called with a `boolean`\n * whenever the online state changes.\n *\n * @example\n * ```ts\n * import NetInfo from '@react-native-community/netinfo'\n * import { onlineManager } from '@tanstack/query-core'\n *\n * onlineManager.setEventListener((setOnline) => {\n * return NetInfo.addEventListener((state) => {\n * setOnline(!!state.isConnected)\n * })\n * })\n * ```\n */\n setEventListener(setup: SetupFn): void {\n this.#setup = setup\n this.#cleanup?.()\n this.#cleanup = setup(this.setOnline.bind(this))\n }\n\n /**\n * `setOnline` can be used to manually set the online state.\n *\n * @example\n * ```ts\n * import { onlineManager } from '@tanstack/query-core'\n *\n * // Set to online\n * onlineManager.setOnline(true)\n *\n * // Set to offline\n * onlineManager.setOnline(false)\n * ```\n */\n setOnline(online: boolean): void {\n const changed = this.#online !== online\n\n if (changed) {\n this.#online = online\n this.listeners.forEach((listener) => {\n listener(online)\n })\n }\n }\n\n /**\n * `isOnline` can be used to get the current online state.\n */\n isOnline(): boolean {\n return this.#online\n }\n}\n\n/**\n * Singleton instance of {@link OnlineManager}, used to manage and observe the online state within TanStack Query.\n */\nexport const onlineManager = new OnlineManager()\n"],"mappings":";;;;;;;;;;;;AAcA,IAAa,gBAAb,cAAmCA,qBAAAA,aAAuB;CACxD,UAAU;CACV;CAEA;CAEA,cAAc;EACZ,MAAM;EACN,KAAKC,UAAU,aAAa;GAG1B,IAAI,OAAO,WAAW,eAAe,OAAO,kBAAkB;IAC5D,MAAM,uBAAuB,SAAS,IAAI;IAC1C,MAAM,wBAAwB,SAAS,KAAK;IAE5C,OAAO,iBAAiB,UAAU,gBAAgB,KAAK;IACvD,OAAO,iBAAiB,WAAW,iBAAiB,KAAK;IAEzD,aAAa;KAEX,OAAO,oBAAoB,UAAU,cAAc;KACnD,OAAO,oBAAoB,WAAW,eAAe;IACvD;GACF;EAGF;CACF;CAEA,cAA8B;EAC5B,IAAI,CAAC,KAAKC,UACR,KAAK,iBAAiB,KAAKD,MAAM;CAErC;CAEA,gBAA0B;EACxB,IAAI,CAAC,KAAK,aAAa,GAAG;GACxB,KAAKC,WAAW;GAChB,KAAKA,WAAW,KAAA;EAClB;CACF;;;;;;;;;;;;;;;;;;;CAoBA,iBAAiB,OAAsB;EACrC,KAAKD,SAAS;EACd,KAAKC,WAAW;EAChB,KAAKA,WAAW,MAAM,KAAK,UAAU,KAAK,IAAI,CAAC;CACjD;;;;;;;;;;;;;;;CAgBA,UAAU,QAAuB;EAG/B,IAFgB,KAAKC,YAAY,QAEpB;GACX,KAAKA,UAAU;GACf,KAAK,UAAU,SAAS,aAAa;IACnC,SAAS,MAAM;GACjB,CAAC;EACH;CACF;;;;CAKA,WAAoB;EAClB,OAAO,KAAKA;CACd;AACF;;;;AAKA,MAAa,gBAAgB,IAAI,cAAc"}
@@ -2,15 +2,62 @@ import { t as Subscribable } from "./subscribable-CbifVTKz.cjs";
2
2
  //#region src/onlineManager.d.ts
3
3
  type Listener = (online: boolean) => void;
4
4
  type SetupFn = (setOnline: Listener) => (() => void) | undefined;
5
+ /**
6
+ * The `OnlineManager` manages the online state within TanStack Query. It can
7
+ * be used to change the default event listeners or to manually change the
8
+ * online state.
9
+ *
10
+ * By default, the `onlineManager` assumes an active network connection, and
11
+ * listens to the `online` and `offline` events on the `window` object to
12
+ * detect changes.
13
+ */
5
14
  declare class OnlineManager extends Subscribable<Listener> {
6
15
  #private;
7
16
  constructor();
8
17
  protected onSubscribe(): void;
9
18
  protected onUnsubscribe(): void;
19
+ /**
20
+ * `setEventListener` can be used to set a custom event listener that will
21
+ * be used to determine the online state. The provided `setup` function
22
+ * receives a `setOnline` callback that should be called with a `boolean`
23
+ * whenever the online state changes.
24
+ *
25
+ * @example
26
+ * ```ts
27
+ * import NetInfo from '@react-native-community/netinfo'
28
+ * import { onlineManager } from '@tanstack/query-core'
29
+ *
30
+ * onlineManager.setEventListener((setOnline) => {
31
+ * return NetInfo.addEventListener((state) => {
32
+ * setOnline(!!state.isConnected)
33
+ * })
34
+ * })
35
+ * ```
36
+ */
10
37
  setEventListener(setup: SetupFn): void;
38
+ /**
39
+ * `setOnline` can be used to manually set the online state.
40
+ *
41
+ * @example
42
+ * ```ts
43
+ * import { onlineManager } from '@tanstack/query-core'
44
+ *
45
+ * // Set to online
46
+ * onlineManager.setOnline(true)
47
+ *
48
+ * // Set to offline
49
+ * onlineManager.setOnline(false)
50
+ * ```
51
+ */
11
52
  setOnline(online: boolean): void;
53
+ /**
54
+ * `isOnline` can be used to get the current online state.
55
+ */
12
56
  isOnline(): boolean;
13
57
  }
58
+ /**
59
+ * Singleton instance of {@link OnlineManager}, used to manage and observe the online state within TanStack Query.
60
+ */
14
61
  declare const onlineManager: OnlineManager;
15
62
  //#endregion
16
63
  export { OnlineManager, onlineManager };
@@ -1 +1 @@
1
- {"version":3,"file":"onlineManager.d.cts","names":[],"sources":["../../src/onlineManager.ts"],"mappings":";;KAEK,YAAY;KACZ,WAAW,WAAW;cAEd,sBAAsB,aAAa;;;YA6BpC;YAMA;EAOV,iBAAiB,OAAO;EAMxB,UAAU;EAWV;;cAKW,eAAa"}
1
+ {"version":3,"file":"onlineManager.d.cts","names":[],"sources":["../../src/onlineManager.ts"],"mappings":";;KAEK,YAAY;KACZ,WAAW,WAAW;;;;;;;;;;cAWd,sBAAsB,aAAa;;;YA6BpC;YAMA;;;;;;;;;;;;;;;;;;;EAyBV,iBAAiB,OAAO;;;;;;;;;;;;;;;EAoBxB,UAAU;;;;EAcV;;;;;cAQW,eAAa"}
@@ -2,15 +2,62 @@ import { t as Subscribable } from "./subscribable-CbifVTKz.js";
2
2
  //#region src/onlineManager.d.ts
3
3
  type Listener = (online: boolean) => void;
4
4
  type SetupFn = (setOnline: Listener) => (() => void) | undefined;
5
+ /**
6
+ * The `OnlineManager` manages the online state within TanStack Query. It can
7
+ * be used to change the default event listeners or to manually change the
8
+ * online state.
9
+ *
10
+ * By default, the `onlineManager` assumes an active network connection, and
11
+ * listens to the `online` and `offline` events on the `window` object to
12
+ * detect changes.
13
+ */
5
14
  declare class OnlineManager extends Subscribable<Listener> {
6
15
  #private;
7
16
  constructor();
8
17
  protected onSubscribe(): void;
9
18
  protected onUnsubscribe(): void;
19
+ /**
20
+ * `setEventListener` can be used to set a custom event listener that will
21
+ * be used to determine the online state. The provided `setup` function
22
+ * receives a `setOnline` callback that should be called with a `boolean`
23
+ * whenever the online state changes.
24
+ *
25
+ * @example
26
+ * ```ts
27
+ * import NetInfo from '@react-native-community/netinfo'
28
+ * import { onlineManager } from '@tanstack/query-core'
29
+ *
30
+ * onlineManager.setEventListener((setOnline) => {
31
+ * return NetInfo.addEventListener((state) => {
32
+ * setOnline(!!state.isConnected)
33
+ * })
34
+ * })
35
+ * ```
36
+ */
10
37
  setEventListener(setup: SetupFn): void;
38
+ /**
39
+ * `setOnline` can be used to manually set the online state.
40
+ *
41
+ * @example
42
+ * ```ts
43
+ * import { onlineManager } from '@tanstack/query-core'
44
+ *
45
+ * // Set to online
46
+ * onlineManager.setOnline(true)
47
+ *
48
+ * // Set to offline
49
+ * onlineManager.setOnline(false)
50
+ * ```
51
+ */
11
52
  setOnline(online: boolean): void;
53
+ /**
54
+ * `isOnline` can be used to get the current online state.
55
+ */
12
56
  isOnline(): boolean;
13
57
  }
58
+ /**
59
+ * Singleton instance of {@link OnlineManager}, used to manage and observe the online state within TanStack Query.
60
+ */
14
61
  declare const onlineManager: OnlineManager;
15
62
  //#endregion
16
63
  export { OnlineManager, onlineManager };
@@ -1 +1 @@
1
- {"version":3,"file":"onlineManager.d.ts","names":[],"sources":["../../src/onlineManager.ts"],"mappings":";;KAEK,YAAY;KACZ,WAAW,WAAW;cAEd,sBAAsB,aAAa;;;YA6BpC;YAMA;EAOV,iBAAiB,OAAO;EAMxB,UAAU;EAWV;;cAKW,eAAa"}
1
+ {"version":3,"file":"onlineManager.d.ts","names":[],"sources":["../../src/onlineManager.ts"],"mappings":";;KAEK,YAAY;KACZ,WAAW,WAAW;;;;;;;;;;cAWd,sBAAsB,aAAa;;;YA6BpC;YAMA;;;;;;;;;;;;;;;;;;;EAyBV,iBAAiB,OAAO;;;;;;;;;;;;;;;EAoBxB,UAAU;;;;EAcV;;;;;cAQW,eAAa"}