@tanstack/query-core 5.104.1 → 5.104.3

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 (359) hide show
  1. package/build/legacy/environmentManager.cjs +3 -1
  2. package/build/legacy/environmentManager.cjs.map +1 -1
  3. package/build/legacy/environmentManager.d.cts +6 -1
  4. package/build/legacy/environmentManager.d.cts.map +1 -1
  5. package/build/legacy/environmentManager.d.ts +6 -1
  6. package/build/legacy/environmentManager.d.ts.map +1 -1
  7. package/build/legacy/environmentManager.js +3 -1
  8. package/build/legacy/environmentManager.js.map +1 -1
  9. package/build/legacy/focusManager.cjs +4 -2
  10. package/build/legacy/focusManager.cjs.map +1 -1
  11. package/build/legacy/focusManager.d.cts +5 -3
  12. package/build/legacy/focusManager.d.cts.map +1 -1
  13. package/build/legacy/focusManager.d.ts +5 -3
  14. package/build/legacy/focusManager.d.ts.map +1 -1
  15. package/build/legacy/focusManager.js +4 -2
  16. package/build/legacy/focusManager.js.map +1 -1
  17. package/build/legacy/{hydration-B9t5w6NC.d.ts → hydration-Bf0oMcwO.d.ts} +1411 -129
  18. package/build/legacy/hydration-Bf0oMcwO.d.ts.map +1 -0
  19. package/build/legacy/{hydration-Br9VIGXa.d.cts → hydration-C6zghADG.d.cts} +1411 -129
  20. package/build/legacy/hydration-C6zghADG.d.cts.map +1 -0
  21. package/build/legacy/hydration.cjs +35 -0
  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 +35 -0
  26. package/build/legacy/hydration.js.map +1 -1
  27. package/build/legacy/index.d.cts +1 -1
  28. package/build/legacy/index.d.ts +1 -1
  29. package/build/legacy/infiniteQueryBehavior.cjs +29 -0
  30. package/build/legacy/infiniteQueryBehavior.cjs.map +1 -1
  31. package/build/legacy/infiniteQueryBehavior.d.cts +16 -1
  32. package/build/legacy/infiniteQueryBehavior.d.cts.map +1 -1
  33. package/build/legacy/infiniteQueryBehavior.d.ts +16 -1
  34. package/build/legacy/infiniteQueryBehavior.d.ts.map +1 -1
  35. package/build/legacy/infiniteQueryBehavior.js +29 -0
  36. package/build/legacy/infiniteQueryBehavior.js.map +1 -1
  37. package/build/legacy/infiniteQueryObserver.cjs +13 -7
  38. package/build/legacy/infiniteQueryObserver.cjs.map +1 -1
  39. package/build/legacy/infiniteQueryObserver.d.cts +15 -9
  40. package/build/legacy/infiniteQueryObserver.d.cts.map +1 -1
  41. package/build/legacy/infiniteQueryObserver.d.ts +15 -9
  42. package/build/legacy/infiniteQueryObserver.d.ts.map +1 -1
  43. package/build/legacy/infiniteQueryObserver.js +13 -7
  44. package/build/legacy/infiniteQueryObserver.js.map +1 -1
  45. package/build/legacy/mutation.cjs +27 -10
  46. package/build/legacy/mutation.cjs.map +1 -1
  47. package/build/legacy/mutation.d.cts +1 -1
  48. package/build/legacy/mutation.d.ts +1 -1
  49. package/build/legacy/mutation.js +27 -10
  50. package/build/legacy/mutation.js.map +1 -1
  51. package/build/legacy/mutationCache.cjs +53 -12
  52. package/build/legacy/mutationCache.cjs.map +1 -1
  53. package/build/legacy/mutationCache.d.cts +1 -1
  54. package/build/legacy/mutationCache.d.ts +1 -1
  55. package/build/legacy/mutationCache.js +53 -12
  56. package/build/legacy/mutationCache.js.map +1 -1
  57. package/build/legacy/mutationObserver.cjs +27 -16
  58. package/build/legacy/mutationObserver.cjs.map +1 -1
  59. package/build/legacy/mutationObserver.d.cts +1 -1
  60. package/build/legacy/mutationObserver.d.ts +1 -1
  61. package/build/legacy/mutationObserver.js +27 -16
  62. package/build/legacy/mutationObserver.js.map +1 -1
  63. package/build/legacy/notifyManager.cjs +12 -2
  64. package/build/legacy/notifyManager.cjs.map +1 -1
  65. package/build/legacy/notifyManager.d.cts +19 -4
  66. package/build/legacy/notifyManager.d.cts.map +1 -1
  67. package/build/legacy/notifyManager.d.ts +19 -4
  68. package/build/legacy/notifyManager.d.ts.map +1 -1
  69. package/build/legacy/notifyManager.js +12 -2
  70. package/build/legacy/notifyManager.js.map +1 -1
  71. package/build/legacy/onlineManager.cjs +4 -2
  72. package/build/legacy/onlineManager.cjs.map +1 -1
  73. package/build/legacy/onlineManager.d.cts +5 -3
  74. package/build/legacy/onlineManager.d.cts.map +1 -1
  75. package/build/legacy/onlineManager.d.ts +5 -3
  76. package/build/legacy/onlineManager.d.ts.map +1 -1
  77. package/build/legacy/onlineManager.js +4 -2
  78. package/build/legacy/onlineManager.js.map +1 -1
  79. package/build/legacy/queriesObserver.cjs +15 -3
  80. package/build/legacy/queriesObserver.cjs.map +1 -1
  81. package/build/legacy/queriesObserver.d.cts +14 -5
  82. package/build/legacy/queriesObserver.d.cts.map +1 -1
  83. package/build/legacy/queriesObserver.d.ts +14 -5
  84. package/build/legacy/queriesObserver.d.ts.map +1 -1
  85. package/build/legacy/queriesObserver.js +15 -3
  86. package/build/legacy/queriesObserver.js.map +1 -1
  87. package/build/legacy/query.cjs +89 -15
  88. package/build/legacy/query.cjs.map +1 -1
  89. package/build/legacy/query.d.cts +1 -1
  90. package/build/legacy/query.d.ts +1 -1
  91. package/build/legacy/query.js +89 -15
  92. package/build/legacy/query.js.map +1 -1
  93. package/build/legacy/queryCache.cjs +34 -12
  94. package/build/legacy/queryCache.cjs.map +1 -1
  95. package/build/legacy/queryCache.d.cts +1 -1
  96. package/build/legacy/queryCache.d.ts +1 -1
  97. package/build/legacy/queryCache.js +34 -12
  98. package/build/legacy/queryCache.js.map +1 -1
  99. package/build/legacy/queryClient.cjs +104 -32
  100. package/build/legacy/queryClient.cjs.map +1 -1
  101. package/build/legacy/queryClient.d.cts +1 -1
  102. package/build/legacy/queryClient.d.ts +1 -1
  103. package/build/legacy/queryClient.js +104 -32
  104. package/build/legacy/queryClient.js.map +1 -1
  105. package/build/legacy/queryObserver.cjs +78 -6
  106. package/build/legacy/queryObserver.cjs.map +1 -1
  107. package/build/legacy/queryObserver.d.cts +1 -1
  108. package/build/legacy/queryObserver.d.ts +1 -1
  109. package/build/legacy/queryObserver.js +78 -6
  110. package/build/legacy/queryObserver.js.map +1 -1
  111. package/build/{modern/removable-0GzhW1PK.d.cts → legacy/removable-Cw9GNGyK.d.cts} +17 -1
  112. package/build/legacy/removable-Cw9GNGyK.d.cts.map +1 -0
  113. package/build/legacy/{removable-0GzhW1PK.d.cts → removable-Cw9GNGyK.d.ts} +17 -1
  114. package/build/legacy/removable-Cw9GNGyK.d.ts.map +1 -0
  115. package/build/legacy/removable.cjs +12 -0
  116. package/build/legacy/removable.cjs.map +1 -1
  117. package/build/legacy/removable.d.cts +1 -1
  118. package/build/legacy/removable.d.ts +1 -1
  119. package/build/legacy/removable.js +12 -0
  120. package/build/legacy/removable.js.map +1 -1
  121. package/build/legacy/retryer.cjs +26 -4
  122. package/build/legacy/retryer.cjs.map +1 -1
  123. package/build/legacy/retryer.d.cts +1 -1
  124. package/build/legacy/retryer.d.ts +1 -1
  125. package/build/legacy/retryer.js +26 -4
  126. package/build/legacy/retryer.js.map +1 -1
  127. package/build/legacy/streamedQuery.cjs +3 -1
  128. package/build/legacy/streamedQuery.cjs.map +1 -1
  129. package/build/legacy/streamedQuery.d.cts +4 -2
  130. package/build/legacy/streamedQuery.d.cts.map +1 -1
  131. package/build/legacy/streamedQuery.d.ts +4 -2
  132. package/build/legacy/streamedQuery.d.ts.map +1 -1
  133. package/build/legacy/streamedQuery.js +3 -1
  134. package/build/legacy/streamedQuery.js.map +1 -1
  135. package/build/{modern/subscribable-CysQ0tne.d.cts → legacy/subscribable-czlHOxMP.d.cts} +11 -1
  136. package/build/legacy/subscribable-czlHOxMP.d.cts.map +1 -0
  137. package/build/legacy/{subscribable-CysQ0tne.d.cts → subscribable-czlHOxMP.d.ts} +11 -1
  138. package/build/legacy/subscribable-czlHOxMP.d.ts.map +1 -0
  139. package/build/legacy/subscribable.cjs +10 -0
  140. package/build/legacy/subscribable.cjs.map +1 -1
  141. package/build/legacy/subscribable.d.cts +1 -1
  142. package/build/legacy/subscribable.d.ts +1 -1
  143. package/build/legacy/subscribable.js +10 -0
  144. package/build/legacy/subscribable.js.map +1 -1
  145. package/build/legacy/timeoutManager.cjs +11 -6
  146. package/build/legacy/timeoutManager.cjs.map +1 -1
  147. package/build/legacy/timeoutManager.d.cts +23 -6
  148. package/build/legacy/timeoutManager.d.cts.map +1 -1
  149. package/build/legacy/timeoutManager.d.ts +23 -6
  150. package/build/legacy/timeoutManager.d.ts.map +1 -1
  151. package/build/legacy/timeoutManager.js +11 -6
  152. package/build/legacy/timeoutManager.js.map +1 -1
  153. package/build/legacy/types.cjs.map +1 -1
  154. package/build/legacy/types.d.cts +1 -1
  155. package/build/legacy/types.d.ts +1 -1
  156. package/build/legacy/types.js.map +1 -1
  157. package/build/legacy/utils.cjs +117 -8
  158. package/build/legacy/utils.cjs.map +1 -1
  159. package/build/legacy/utils.d.cts +1 -1
  160. package/build/legacy/utils.d.ts +1 -1
  161. package/build/legacy/utils.js +117 -8
  162. package/build/legacy/utils.js.map +1 -1
  163. package/build/modern/environmentManager.cjs +3 -1
  164. package/build/modern/environmentManager.cjs.map +1 -1
  165. package/build/modern/environmentManager.d.cts +6 -1
  166. package/build/modern/environmentManager.d.cts.map +1 -1
  167. package/build/modern/environmentManager.d.ts +6 -1
  168. package/build/modern/environmentManager.d.ts.map +1 -1
  169. package/build/modern/environmentManager.js +3 -1
  170. package/build/modern/environmentManager.js.map +1 -1
  171. package/build/modern/focusManager.cjs +4 -2
  172. package/build/modern/focusManager.cjs.map +1 -1
  173. package/build/modern/focusManager.d.cts +5 -3
  174. package/build/modern/focusManager.d.cts.map +1 -1
  175. package/build/modern/focusManager.d.ts +5 -3
  176. package/build/modern/focusManager.d.ts.map +1 -1
  177. package/build/modern/focusManager.js +4 -2
  178. package/build/modern/focusManager.js.map +1 -1
  179. package/build/modern/{hydration-B9t5w6NC.d.ts → hydration-Bf0oMcwO.d.ts} +1411 -129
  180. package/build/modern/hydration-Bf0oMcwO.d.ts.map +1 -0
  181. package/build/modern/{hydration-Br9VIGXa.d.cts → hydration-C6zghADG.d.cts} +1411 -129
  182. package/build/modern/hydration-C6zghADG.d.cts.map +1 -0
  183. package/build/modern/hydration.cjs +35 -0
  184. package/build/modern/hydration.cjs.map +1 -1
  185. package/build/modern/hydration.d.cts +1 -1
  186. package/build/modern/hydration.d.ts +1 -1
  187. package/build/modern/hydration.js +35 -0
  188. package/build/modern/hydration.js.map +1 -1
  189. package/build/modern/index.d.cts +1 -1
  190. package/build/modern/index.d.ts +1 -1
  191. package/build/modern/infiniteQueryBehavior.cjs +29 -0
  192. package/build/modern/infiniteQueryBehavior.cjs.map +1 -1
  193. package/build/modern/infiniteQueryBehavior.d.cts +16 -1
  194. package/build/modern/infiniteQueryBehavior.d.cts.map +1 -1
  195. package/build/modern/infiniteQueryBehavior.d.ts +16 -1
  196. package/build/modern/infiniteQueryBehavior.d.ts.map +1 -1
  197. package/build/modern/infiniteQueryBehavior.js +29 -0
  198. package/build/modern/infiniteQueryBehavior.js.map +1 -1
  199. package/build/modern/infiniteQueryObserver.cjs +13 -7
  200. package/build/modern/infiniteQueryObserver.cjs.map +1 -1
  201. package/build/modern/infiniteQueryObserver.d.cts +15 -9
  202. package/build/modern/infiniteQueryObserver.d.cts.map +1 -1
  203. package/build/modern/infiniteQueryObserver.d.ts +15 -9
  204. package/build/modern/infiniteQueryObserver.d.ts.map +1 -1
  205. package/build/modern/infiniteQueryObserver.js +13 -7
  206. package/build/modern/infiniteQueryObserver.js.map +1 -1
  207. package/build/modern/mutation.cjs +27 -10
  208. package/build/modern/mutation.cjs.map +1 -1
  209. package/build/modern/mutation.d.cts +1 -1
  210. package/build/modern/mutation.d.ts +1 -1
  211. package/build/modern/mutation.js +27 -10
  212. package/build/modern/mutation.js.map +1 -1
  213. package/build/modern/mutationCache.cjs +53 -12
  214. package/build/modern/mutationCache.cjs.map +1 -1
  215. package/build/modern/mutationCache.d.cts +1 -1
  216. package/build/modern/mutationCache.d.ts +1 -1
  217. package/build/modern/mutationCache.js +53 -12
  218. package/build/modern/mutationCache.js.map +1 -1
  219. package/build/modern/mutationObserver.cjs +23 -12
  220. package/build/modern/mutationObserver.cjs.map +1 -1
  221. package/build/modern/mutationObserver.d.cts +1 -1
  222. package/build/modern/mutationObserver.d.ts +1 -1
  223. package/build/modern/mutationObserver.js +23 -12
  224. package/build/modern/mutationObserver.js.map +1 -1
  225. package/build/modern/notifyManager.cjs +12 -2
  226. package/build/modern/notifyManager.cjs.map +1 -1
  227. package/build/modern/notifyManager.d.cts +19 -4
  228. package/build/modern/notifyManager.d.cts.map +1 -1
  229. package/build/modern/notifyManager.d.ts +19 -4
  230. package/build/modern/notifyManager.d.ts.map +1 -1
  231. package/build/modern/notifyManager.js +12 -2
  232. package/build/modern/notifyManager.js.map +1 -1
  233. package/build/modern/onlineManager.cjs +4 -2
  234. package/build/modern/onlineManager.cjs.map +1 -1
  235. package/build/modern/onlineManager.d.cts +5 -3
  236. package/build/modern/onlineManager.d.cts.map +1 -1
  237. package/build/modern/onlineManager.d.ts +5 -3
  238. package/build/modern/onlineManager.d.ts.map +1 -1
  239. package/build/modern/onlineManager.js +4 -2
  240. package/build/modern/onlineManager.js.map +1 -1
  241. package/build/modern/queriesObserver.cjs +15 -3
  242. package/build/modern/queriesObserver.cjs.map +1 -1
  243. package/build/modern/queriesObserver.d.cts +14 -5
  244. package/build/modern/queriesObserver.d.cts.map +1 -1
  245. package/build/modern/queriesObserver.d.ts +14 -5
  246. package/build/modern/queriesObserver.d.ts.map +1 -1
  247. package/build/modern/queriesObserver.js +15 -3
  248. package/build/modern/queriesObserver.js.map +1 -1
  249. package/build/modern/query.cjs +89 -15
  250. package/build/modern/query.cjs.map +1 -1
  251. package/build/modern/query.d.cts +1 -1
  252. package/build/modern/query.d.ts +1 -1
  253. package/build/modern/query.js +89 -15
  254. package/build/modern/query.js.map +1 -1
  255. package/build/modern/queryCache.cjs +34 -12
  256. package/build/modern/queryCache.cjs.map +1 -1
  257. package/build/modern/queryCache.d.cts +1 -1
  258. package/build/modern/queryCache.d.ts +1 -1
  259. package/build/modern/queryCache.js +34 -12
  260. package/build/modern/queryCache.js.map +1 -1
  261. package/build/modern/queryClient.cjs +104 -32
  262. package/build/modern/queryClient.cjs.map +1 -1
  263. package/build/modern/queryClient.d.cts +1 -1
  264. package/build/modern/queryClient.d.ts +1 -1
  265. package/build/modern/queryClient.js +104 -32
  266. package/build/modern/queryClient.js.map +1 -1
  267. package/build/modern/queryObserver.cjs +78 -6
  268. package/build/modern/queryObserver.cjs.map +1 -1
  269. package/build/modern/queryObserver.d.cts +1 -1
  270. package/build/modern/queryObserver.d.ts +1 -1
  271. package/build/modern/queryObserver.js +78 -6
  272. package/build/modern/queryObserver.js.map +1 -1
  273. package/build/modern/{removable-0GzhW1PK.d.ts → removable-Cw9GNGyK.d.cts} +17 -1
  274. package/build/modern/removable-Cw9GNGyK.d.cts.map +1 -0
  275. package/build/{legacy/removable-0GzhW1PK.d.ts → modern/removable-Cw9GNGyK.d.ts} +17 -1
  276. package/build/modern/removable-Cw9GNGyK.d.ts.map +1 -0
  277. package/build/modern/removable.cjs +12 -0
  278. package/build/modern/removable.cjs.map +1 -1
  279. package/build/modern/removable.d.cts +1 -1
  280. package/build/modern/removable.d.ts +1 -1
  281. package/build/modern/removable.js +12 -0
  282. package/build/modern/removable.js.map +1 -1
  283. package/build/modern/retryer.cjs +26 -4
  284. package/build/modern/retryer.cjs.map +1 -1
  285. package/build/modern/retryer.d.cts +1 -1
  286. package/build/modern/retryer.d.ts +1 -1
  287. package/build/modern/retryer.js +26 -4
  288. package/build/modern/retryer.js.map +1 -1
  289. package/build/modern/streamedQuery.cjs +3 -1
  290. package/build/modern/streamedQuery.cjs.map +1 -1
  291. package/build/modern/streamedQuery.d.cts +4 -2
  292. package/build/modern/streamedQuery.d.cts.map +1 -1
  293. package/build/modern/streamedQuery.d.ts +4 -2
  294. package/build/modern/streamedQuery.d.ts.map +1 -1
  295. package/build/modern/streamedQuery.js +3 -1
  296. package/build/modern/streamedQuery.js.map +1 -1
  297. package/build/modern/{subscribable-CysQ0tne.d.ts → subscribable-czlHOxMP.d.cts} +11 -1
  298. package/build/modern/subscribable-czlHOxMP.d.cts.map +1 -0
  299. package/build/{legacy/subscribable-CysQ0tne.d.ts → modern/subscribable-czlHOxMP.d.ts} +11 -1
  300. package/build/modern/subscribable-czlHOxMP.d.ts.map +1 -0
  301. package/build/modern/subscribable.cjs +10 -0
  302. package/build/modern/subscribable.cjs.map +1 -1
  303. package/build/modern/subscribable.d.cts +1 -1
  304. package/build/modern/subscribable.d.ts +1 -1
  305. package/build/modern/subscribable.js +10 -0
  306. package/build/modern/subscribable.js.map +1 -1
  307. package/build/modern/timeoutManager.cjs +11 -6
  308. package/build/modern/timeoutManager.cjs.map +1 -1
  309. package/build/modern/timeoutManager.d.cts +23 -6
  310. package/build/modern/timeoutManager.d.cts.map +1 -1
  311. package/build/modern/timeoutManager.d.ts +23 -6
  312. package/build/modern/timeoutManager.d.ts.map +1 -1
  313. package/build/modern/timeoutManager.js +11 -6
  314. package/build/modern/timeoutManager.js.map +1 -1
  315. package/build/modern/types.cjs.map +1 -1
  316. package/build/modern/types.d.cts +1 -1
  317. package/build/modern/types.d.ts +1 -1
  318. package/build/modern/types.js.map +1 -1
  319. package/build/modern/utils.cjs +117 -8
  320. package/build/modern/utils.cjs.map +1 -1
  321. package/build/modern/utils.d.cts +1 -1
  322. package/build/modern/utils.d.ts +1 -1
  323. package/build/modern/utils.js +117 -8
  324. package/build/modern/utils.js.map +1 -1
  325. package/package.json +3 -3
  326. package/src/environmentManager.ts +6 -1
  327. package/src/focusManager.ts +8 -6
  328. package/src/hydration.ts +42 -1
  329. package/src/infiniteQueryBehavior.ts +29 -0
  330. package/src/infiniteQueryObserver.ts +20 -14
  331. package/src/mutation.ts +32 -11
  332. package/src/mutationCache.ts +53 -12
  333. package/src/mutationObserver.ts +29 -14
  334. package/src/notifyManager.ts +12 -2
  335. package/src/onlineManager.ts +7 -5
  336. package/src/queriesObserver.ts +20 -5
  337. package/src/query.ts +153 -20
  338. package/src/queryCache.ts +54 -13
  339. package/src/queryClient.ts +114 -42
  340. package/src/queryObserver.ts +88 -12
  341. package/src/removable.ts +16 -0
  342. package/src/retryer.ts +57 -4
  343. package/src/streamedQuery.ts +4 -3
  344. package/src/subscribable.ts +10 -0
  345. package/src/timeoutManager.ts +23 -6
  346. package/src/types.ts +801 -27
  347. package/src/utils.ts +130 -10
  348. package/build/legacy/hydration-B9t5w6NC.d.ts.map +0 -1
  349. package/build/legacy/hydration-Br9VIGXa.d.cts.map +0 -1
  350. package/build/legacy/removable-0GzhW1PK.d.cts.map +0 -1
  351. package/build/legacy/removable-0GzhW1PK.d.ts.map +0 -1
  352. package/build/legacy/subscribable-CysQ0tne.d.cts.map +0 -1
  353. package/build/legacy/subscribable-CysQ0tne.d.ts.map +0 -1
  354. package/build/modern/hydration-B9t5w6NC.d.ts.map +0 -1
  355. package/build/modern/hydration-Br9VIGXa.d.cts.map +0 -1
  356. package/build/modern/removable-0GzhW1PK.d.cts.map +0 -1
  357. package/build/modern/removable-0GzhW1PK.d.ts.map +0 -1
  358. package/build/modern/subscribable-CysQ0tne.d.cts.map +0 -1
  359. package/build/modern/subscribable-CysQ0tne.d.ts.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"mutationObserver.js","names":[],"sources":["../../src/mutationObserver.ts"],"sourcesContent":["import { getDefaultState } from './mutation'\nimport { notifyManager } from './notifyManager'\nimport { Subscribable } from './subscribable'\nimport { hashKey, shallowEqualObjects } from './utils'\nimport type { QueryClient } from './queryClient'\nimport type {\n DefaultError,\n MutateOptions,\n MutationFunctionContext,\n MutationObserverOptions,\n MutationObserverResult,\n} from './types'\nimport type { Action, Mutation } from './mutation'\n\n// TYPES\n\ntype MutationObserverListener<TData, TError, TVariables, TOnMutateResult> = (\n result: MutationObserverResult<TData, TError, TVariables, TOnMutateResult>,\n) => void\n\n// CLASS\n\n/**\n * Observes a single mutation and derives a `MutationObserverResult` from it.\n * A framework hook like `useMutation` creates one `MutationObserver` per hook\n * call, keeps it stable across re-renders, calls `setOptions` when the options\n * passed to the hook change, subscribes to it to re-render on updates, and\n * reads `getCurrentResult()` for the value to return. Calling `mutate()`\n * builds a new underlying `Mutation` in the `MutationCache` and executes it.\n *\n * @example\n * ```ts\n * const observer = new MutationObserver(queryClient, {\n * mutationFn: (variables: { title: string }) => addPost(variables),\n * })\n * ```\n */\nexport class MutationObserver<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TOnMutateResult = unknown,\n> extends Subscribable<\n MutationObserverListener<TData, TError, TVariables, TOnMutateResult>\n> {\n options!: MutationObserverOptions<TData, TError, TVariables, TOnMutateResult>\n\n #client: QueryClient\n #currentResult: MutationObserverResult<\n TData,\n TError,\n TVariables,\n TOnMutateResult\n > = undefined!\n #currentMutation?: Mutation<TData, TError, TVariables, TOnMutateResult>\n #mutateOptions?: MutateOptions<TData, TError, TVariables, TOnMutateResult>\n\n constructor(\n client: QueryClient,\n options: MutationObserverOptions<\n TData,\n TError,\n TVariables,\n TOnMutateResult\n >,\n ) {\n super()\n\n this.#client = client\n this.setOptions(options)\n this.bindMethods()\n this.#updateResult()\n }\n\n protected bindMethods(): void {\n this.mutate = this.mutate.bind(this)\n this.reset = this.reset.bind(this)\n }\n\n /**\n * Updates the observer's options.\n *\n * If the new `mutationKey` differs from the previous one (and both were\n * defined), the observer is reset, detaching it from the mutation it was\n * observing. Otherwise, if the currently observed mutation is still\n * `pending`, its options are updated in place as well.\n *\n * @example\n * ```ts\n * observer.setOptions({\n * mutationFn: (variables: { title: string }) => addPost(variables),\n * onSuccess: (data) => console.log(data),\n * })\n * ```\n */\n setOptions(\n options: MutationObserverOptions<\n TData,\n TError,\n TVariables,\n TOnMutateResult\n >,\n ) {\n const prevOptions = this.options as\n | MutationObserverOptions<TData, TError, TVariables, TOnMutateResult>\n | undefined\n this.options = this.#client.defaultMutationOptions(options)\n if (!shallowEqualObjects(this.options, prevOptions)) {\n this.#client.getMutationCache().notify({\n type: 'observerOptionsUpdated',\n mutation: this.#currentMutation,\n observer: this,\n })\n }\n\n if (\n prevOptions?.mutationKey &&\n this.options.mutationKey &&\n hashKey(prevOptions.mutationKey) !== hashKey(this.options.mutationKey)\n ) {\n this.reset()\n } else if (this.#currentMutation?.state.status === 'pending') {\n this.#currentMutation.setOptions(this.options)\n }\n }\n\n protected onSubscribe(): void {\n if (this.listeners.size === 1 && this.#currentMutation) {\n this.#currentMutation.addObserver(this)\n\n this.#updateResult()\n }\n }\n\n protected onUnsubscribe(): void {\n if (!this.hasListeners()) {\n this.#currentMutation?.removeObserver(this)\n }\n }\n\n /** @internal */\n onMutationUpdate(\n action: Action<TData, TError, TVariables, TOnMutateResult>,\n ): void {\n this.#updateResult()\n\n this.#notify(action)\n }\n\n /**\n * Returns the observer's current result, derived from the observed\n * mutation's state (or the default, `idle` state if no mutation has been\n * built yet, e.g. before the first `mutate()` call or after `reset()`).\n */\n getCurrentResult(): MutationObserverResult<\n TData,\n TError,\n TVariables,\n TOnMutateResult\n > {\n return this.#currentResult\n }\n\n /**\n * Detaches the observer from the mutation it is currently observing (if\n * any) and resets the observed result back to its default, `idle` state.\n *\n * This does not cancel an in-flight mutation; the mutation itself keeps\n * running to completion and its own callbacks still fire, but this\n * observer stops reflecting its state and a subsequent `mutate()` call\n * will build a brand new mutation.\n *\n * @example\n * ```ts\n * observer.reset()\n * ```\n *\n * @see {@link MutationObserver#mutate}\n */\n reset(): void {\n // reset needs to remove the observer from the mutation because there is no way to \"get it back\"\n // another mutate call will yield a new mutation!\n this.#currentMutation?.removeObserver(this)\n this.#currentMutation = undefined\n this.#updateResult()\n this.#notify()\n }\n\n /**\n * Builds a new `Mutation` in the `MutationCache` using the observer's\n * current options, detaches this observer from any previously observed\n * mutation, attaches it to the new one, and executes it with the given\n * variables.\n *\n * The optional per-call `options` (`onSuccess`/`onError`/`onSettled`) are\n * invoked once the mutation settles, in addition to any callbacks defined\n * on the observer's own options.\n *\n * @example\n * ```ts\n * await observer.mutate(\n * { title: 'New post' },\n * { onSuccess: (data) => console.log(data) },\n * )\n * ```\n */\n mutate(\n variables: TVariables,\n options?: MutateOptions<TData, TError, TVariables, TOnMutateResult>,\n ): Promise<TData> {\n this.#mutateOptions = options\n\n this.#currentMutation?.removeObserver(this)\n\n this.#currentMutation = this.#client\n .getMutationCache()\n .build(this.#client, this.options)\n\n this.#currentMutation.addObserver(this)\n\n return this.#currentMutation.execute(variables)\n }\n\n #updateResult(): void {\n const state =\n this.#currentMutation?.state ??\n getDefaultState<TData, TError, TVariables, TOnMutateResult>()\n\n this.#currentResult = {\n ...state,\n isPending: state.status === 'pending',\n isSuccess: state.status === 'success',\n isError: state.status === 'error',\n isIdle: state.status === 'idle',\n mutate: this.mutate,\n reset: this.reset,\n } as MutationObserverResult<TData, TError, TVariables, TOnMutateResult>\n }\n\n #notify(action?: Action<TData, TError, TVariables, TOnMutateResult>): void {\n notifyManager.batch(() => {\n // First trigger the mutate callbacks\n if (this.#mutateOptions && this.hasListeners()) {\n const variables = this.#currentResult.variables!\n const onMutateResult = this.#currentResult.context\n\n const context = {\n client: this.#client,\n meta: this.options.meta,\n mutationKey: this.options.mutationKey,\n } satisfies MutationFunctionContext\n\n if (action?.type === 'success') {\n try {\n this.#mutateOptions.onSuccess?.(\n action.data,\n variables,\n onMutateResult,\n context,\n )\n } catch (e) {\n void Promise.reject(e)\n }\n try {\n this.#mutateOptions.onSettled?.(\n action.data,\n null,\n variables,\n onMutateResult,\n context,\n )\n } catch (e) {\n void Promise.reject(e)\n }\n } else if (action?.type === 'error') {\n try {\n this.#mutateOptions.onError?.(\n action.error,\n variables,\n onMutateResult,\n context,\n )\n } catch (e) {\n void Promise.reject(e)\n }\n try {\n this.#mutateOptions.onSettled?.(\n undefined,\n action.error,\n variables,\n onMutateResult,\n context,\n )\n } catch (e) {\n void Promise.reject(e)\n }\n }\n }\n\n // Then trigger the listeners\n this.listeners.forEach((listener) => {\n listener(this.#currentResult)\n })\n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;KACF,CAAA,2BAAA,0BAAA,uBAAA,gBAAA,IAAA,EAAA,CAAoB,eAAA,QAAA,4BAAA,KAAA,KAAA,wBAAA,KAAA,yBAClB,KAAA,GACA,OAAO,OACP,WACA,gBACA,OACF;IACF,SAAS,GAAG;KACV,QAAa,OAAO,CAAC;IACvB;GACF;EACF;EAGA,KAAK,UAAU,SAAS,aAAa;GACnC,SAAA,uBAAA,gBAAS,IAAA,CAAmB;EAC9B,CAAC;CACH,CAAC;AACH"}
1
+ {"version":3,"file":"mutationObserver.js","names":[],"sources":["../../src/mutationObserver.ts"],"sourcesContent":["import { getDefaultState } from './mutation'\nimport { notifyManager } from './notifyManager'\nimport { Subscribable } from './subscribable'\nimport { hashKey, shallowEqualObjects } from './utils'\nimport type { QueryClient } from './queryClient'\nimport type {\n DefaultError,\n MutateOptions,\n MutationFunctionContext,\n MutationObserverOptions,\n MutationObserverResult,\n} from './types'\nimport type { Action, Mutation } from './mutation'\n\n// TYPES\n\ntype MutationObserverListener<TData, TError, TVariables, TOnMutateResult> = (\n result: MutationObserverResult<TData, TError, TVariables, TOnMutateResult>,\n) => void\n\n// CLASS\n\n/**\n * Observes a single mutation and derives a `MutationObserverResult` from it.\n * A framework hook like `useMutation` creates one `MutationObserver` per hook\n * call, keeps it stable across re-renders, calls `setOptions` when the options\n * passed to the hook change, subscribes to it to re-render on updates, and\n * reads `getCurrentResult()` for the value to return. Calling `mutate()`\n * builds a new underlying `Mutation` in the `MutationCache` and executes it.\n * @example\n * ```ts\n * const observer = new MutationObserver(queryClient, {\n * mutationFn: (variables: { title: string }) => addPost(variables),\n * })\n * ```\n */\nexport class MutationObserver<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TOnMutateResult = unknown,\n> extends Subscribable<\n MutationObserverListener<TData, TError, TVariables, TOnMutateResult>\n> {\n options!: MutationObserverOptions<TData, TError, TVariables, TOnMutateResult>\n\n #client: QueryClient\n #currentResult: MutationObserverResult<\n TData,\n TError,\n TVariables,\n TOnMutateResult\n > = undefined!\n #currentMutation?: Mutation<TData, TError, TVariables, TOnMutateResult>\n #mutateOptions?: MutateOptions<TData, TError, TVariables, TOnMutateResult>\n\n constructor(\n client: QueryClient,\n options: MutationObserverOptions<\n TData,\n TError,\n TVariables,\n TOnMutateResult\n >,\n ) {\n super()\n\n this.#client = client\n this.setOptions(options)\n this.bindMethods()\n this.#updateResult()\n }\n\n /**\n * Binds the methods of the result (`mutate` and `reset`) to the observer, so they keep working when\n * destructured from it.\n */\n protected bindMethods(): void {\n this.mutate = this.mutate.bind(this)\n this.reset = this.reset.bind(this)\n }\n\n /**\n * Updates the observer's options.\n *\n * If the new `mutationKey` differs from the previous one (and both were\n * defined), the observer is reset, detaching it from the mutation it was\n * observing. Otherwise, if the currently observed mutation is still\n * `pending`, its options are updated in place as well.\n * @param options - The new mutation observer options. They are defaulted with {@link\n * QueryClient#defaultMutationOptions} before being applied.\n * @example\n * ```ts\n * observer.setOptions({\n * mutationFn: (variables: { title: string }) => addPost(variables),\n * onSuccess: (data) => console.log(data),\n * })\n * ```\n */\n setOptions(\n options: MutationObserverOptions<\n TData,\n TError,\n TVariables,\n TOnMutateResult\n >,\n ) {\n const prevOptions = this.options as\n | MutationObserverOptions<TData, TError, TVariables, TOnMutateResult>\n | undefined\n this.options = this.#client.defaultMutationOptions(options)\n if (!shallowEqualObjects(this.options, prevOptions)) {\n this.#client.getMutationCache().notify({\n type: 'observerOptionsUpdated',\n mutation: this.#currentMutation,\n observer: this,\n })\n }\n\n if (\n prevOptions?.mutationKey &&\n this.options.mutationKey &&\n hashKey(prevOptions.mutationKey) !== hashKey(this.options.mutationKey)\n ) {\n this.reset()\n } else if (this.#currentMutation?.state.status === 'pending') {\n this.#currentMutation.setOptions(this.options)\n }\n }\n\n protected override onSubscribe(): void {\n if (this.listeners.size === 1 && this.#currentMutation) {\n this.#currentMutation.addObserver(this)\n\n this.#updateResult()\n }\n }\n\n protected override onUnsubscribe(): void {\n if (!this.hasListeners()) {\n this.#currentMutation?.removeObserver(this)\n }\n }\n\n /**\n * Updates the observer's result when the observed mutation changes, and notifies its listeners.\n * @internal\n * @param action - The action that updated the observed mutation, passed on to the observer's\n * callbacks.\n */\n onMutationUpdate(\n action: Action<TData, TError, TVariables, TOnMutateResult>,\n ): void {\n this.#updateResult()\n\n this.#notify(action)\n }\n\n /**\n * Returns the observer's current result, derived from the observed\n * mutation's state (or the default, `idle` state if no mutation has been\n * built yet, e.g. before the first `mutate()` call or after `reset()`).\n * @returns The observer's latest result.\n */\n getCurrentResult(): MutationObserverResult<\n TData,\n TError,\n TVariables,\n TOnMutateResult\n > {\n return this.#currentResult\n }\n\n /**\n * Detaches the observer from the mutation it is currently observing (if\n * any) and resets the observed result back to its default, `idle` state.\n *\n * This does not cancel an in-flight mutation; the mutation itself keeps\n * running to completion and its own callbacks still fire, but this\n * observer stops reflecting its state and a subsequent `mutate()` call\n * will build a brand new mutation.\n * @see {@link MutationObserver#mutate}\n * @example\n * ```ts\n * observer.reset()\n * ```\n */\n reset(): void {\n // reset needs to remove the observer from the mutation because there is no way to \"get it back\"\n // another mutate call will yield a new mutation!\n this.#currentMutation?.removeObserver(this)\n this.#currentMutation = undefined\n this.#updateResult()\n this.#notify()\n }\n\n /**\n * Builds a new `Mutation` in the `MutationCache` using the observer's\n * current options, detaches this observer from any previously observed\n * mutation, attaches it to the new one, and executes it with the given\n * variables.\n *\n * The optional per-call `options` (`onSuccess`/`onError`/`onSettled`) are\n * invoked once the mutation settles, in addition to any callbacks defined\n * on the observer's own options.\n * @param variables - The variables passed to the `mutationFn`.\n * @param options - Per-call `onSuccess`, `onError`, and `onSettled` callbacks.\n * @returns A promise that resolves with the mutation's data, or rejects with its error.\n * @example\n * ```ts\n * await observer.mutate(\n * { title: 'New post' },\n * { onSuccess: (data) => console.log(data) },\n * )\n * ```\n */\n mutate(\n variables: TVariables,\n options?: MutateOptions<TData, TError, TVariables, TOnMutateResult>,\n ): Promise<TData> {\n this.#mutateOptions = options\n\n this.#currentMutation?.removeObserver(this)\n\n this.#currentMutation = this.#client\n .getMutationCache()\n .build(this.#client, this.options)\n\n this.#currentMutation.addObserver(this)\n\n return this.#currentMutation.execute(variables)\n }\n\n #updateResult(): void {\n const state =\n this.#currentMutation?.state ??\n getDefaultState<TData, TError, TVariables, TOnMutateResult>()\n\n this.#currentResult = {\n ...state,\n isPending: state.status === 'pending',\n isSuccess: state.status === 'success',\n isError: state.status === 'error',\n isIdle: state.status === 'idle',\n mutate: this.mutate,\n reset: this.reset,\n } as MutationObserverResult<TData, TError, TVariables, TOnMutateResult>\n }\n\n #notify(action?: Action<TData, TError, TVariables, TOnMutateResult>): void {\n notifyManager.batch(() => {\n // First trigger the mutate callbacks\n // Snapshot mutateOptions before dispatching — a callback (e.g. onSuccess)\n // may call mutate() again, which overwrites this.#mutateOptions in place.\n // Without the snapshot, onSettled would fire with the *next* mutation's\n // options but the *current* mutation's data/variables.\n const mutateOptions = this.#mutateOptions\n if (mutateOptions && this.hasListeners()) {\n const variables = this.#currentResult.variables!\n const onMutateResult = this.#currentResult.context\n\n const context = {\n client: this.#client,\n meta: this.options.meta,\n mutationKey: this.options.mutationKey,\n } satisfies MutationFunctionContext\n\n if (action?.type === 'success') {\n try {\n mutateOptions.onSuccess?.(\n action.data,\n variables,\n onMutateResult,\n context,\n )\n } catch (e) {\n void Promise.reject(e)\n }\n try {\n mutateOptions.onSettled?.(\n action.data,\n null,\n variables,\n onMutateResult,\n context,\n )\n } catch (e) {\n void Promise.reject(e)\n }\n } else if (action?.type === 'error') {\n try {\n mutateOptions.onError?.(\n action.error,\n variables,\n onMutateResult,\n context,\n )\n } catch (e) {\n void Promise.reject(e)\n }\n try {\n mutateOptions.onSettled?.(\n undefined,\n action.error,\n variables,\n onMutateResult,\n context,\n )\n } catch (e) {\n void Promise.reject(e)\n }\n }\n }\n\n // Then trigger the listeners\n this.listeners.forEach((listener) => {\n listener(this.#currentResult)\n })\n })\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;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GAAG;KACV,QAAa,OAAO,CAAC;IACvB;GACF;EACF;EAGA,KAAK,UAAU,SAAS,aAAa;GACnC,SAAA,uBAAA,gBAAS,IAAA,CAAmB;EAC9B,CAAC;CACH,CAAC;AACH"}
@@ -5,6 +5,11 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
5
5
  * Schedules the callback with the system's `setTimeout(callback, 0)`.
6
6
  */
7
7
  const defaultScheduler = require("./timeoutManager.cjs").systemSetTimeoutZero;
8
+ /**
9
+ * Creates a notify manager, which schedules and batches notifications to subscribers. Query uses a
10
+ * single instance of it, exported as {@link notifyManager}.
11
+ * @returns A new notify manager.
12
+ */
8
13
  function createNotifyManager() {
9
14
  let queue = [];
10
15
  let transactions = 0;
@@ -38,6 +43,8 @@ function createNotifyManager() {
38
43
  * This is mainly used internally to optimize query client updating.
39
44
  * Batches can be nested; the queue is only flushed once the outermost `batch` call finishes.
40
45
  * The return value of `callback` is passed through.
46
+ * @param callback - The function to run in the batch.
47
+ * @returns The return value of `callback`.
41
48
  */
42
49
  batch: (callback) => {
43
50
  let result;
@@ -52,6 +59,8 @@ function createNotifyManager() {
52
59
  },
53
60
  /**
54
61
  * All calls to the wrapped function will be batched.
62
+ * @param callback - The function to wrap.
63
+ * @returns A function that schedules a call to `callback` with the given arguments.
55
64
  */
56
65
  batchCalls: (callback) => {
57
66
  return (...args) => {
@@ -68,6 +77,7 @@ function createNotifyManager() {
68
77
  /**
69
78
  * Use this method to set a custom notify function.
70
79
  * This can be used to for example wrap notifications with `React.act` while running tests.
80
+ * @param fn - Receives each notification callback and must call it.
71
81
  */
72
82
  setNotifyFunction: (fn) => {
73
83
  notifyFn = fn;
@@ -76,7 +86,7 @@ function createNotifyManager() {
76
86
  * Use this method to set a custom function to batch notifications together into a single tick.
77
87
  * Framework adapters use this to plug in their own batching primitive, so that a single query
78
88
  * update only triggers one re-render instead of one per subscriber.
79
- *
89
+ * @param fn - Receives a function that runs a batch of notifications and must call it.
80
90
  * @example
81
91
  * ```ts
82
92
  * import { notifyManager } from '@tanstack/query-core'
@@ -91,7 +101,7 @@ function createNotifyManager() {
91
101
  /**
92
102
  * Configures a custom callback that schedules when the next batch runs.
93
103
  * The default behavior is `setTimeout(callback, 0)`.
94
- *
104
+ * @param fn - Receives a callback that runs the next batch, and schedules it.
95
105
  * @example
96
106
  * ```ts
97
107
  * import { notifyManager } from '@tanstack/query-core'
@@ -1 +1 @@
1
- {"version":3,"file":"notifyManager.cjs","names":["systemSetTimeoutZero"],"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,iDAAqCA,CAAAA,CAAAA;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
+ {"version":3,"file":"notifyManager.cjs","names":["systemSetTimeoutZero"],"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\n/**\n * Creates a notify manager, which schedules and batches notifications to subscribers. Query uses a\n * single instance of it, exported as {@link notifyManager}.\n * @returns A new notify manager.\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 * @param callback - The function to run in the batch.\n * @returns The return value of `callback`.\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 * @param callback - The function to wrap.\n * @returns A function that schedules a call to `callback` with the given arguments.\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 * @param fn - Receives each notification callback and must call it.\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 * @param fn - Receives a function that runs a batch of notifications and must call it.\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 * @param fn - Receives a callback that runs the next batch, and schedules it.\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,iDAAqCA,CAAAA,CAAAA;;;;;;AAOlD,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;;;;;;;;;EASL,QAAW,aAAyB;GAClC,IAAI;GACJ;GACA,IAAI;IACF,SAAS,SAAS;GACpB,UAAU;IACR;IACA,IAAI,CAAC,cACH,MAAM;GAEV;GACA,OAAO;EACT;;;;;;EAMA,aACE,aAC0B;GAC1B,QAAQ,GAAG,SAAS;IAClB,eAAe;KACb,SAAS,GAAG,IAAI;IAClB,CAAC;GACH;EACF;;;;;EAKA;;;;;;EAMA,oBAAoB,OAAuB;GACzC,WAAW;EACb;;;;;;;;;;;;;;EAcA,yBAAyB,OAA4B;GACnD,gBAAgB;EAClB;;;;;;;;;;;;;;;;;;;EAmBA,eAAe,OAAyB;GACtC,aAAa;EACf;CACF;AACF;;;;AAOA,MAAa,gBAAgB,oBAAoB"}
@@ -9,16 +9,25 @@ type ScheduleFunction = (callback: () => void) => void;
9
9
  * Schedules the callback with the system's `setTimeout(callback, 0)`.
10
10
  */
11
11
  export declare const defaultScheduler: ScheduleFunction;
12
+ /**
13
+ * Creates a notify manager, which schedules and batches notifications to subscribers. Query uses a
14
+ * single instance of it, exported as {@link notifyManager}.
15
+ * @returns A new notify manager.
16
+ */
12
17
  export declare function createNotifyManager(): {
13
18
  /**
14
19
  * Batches all updates scheduled inside the passed callback.
15
20
  * This is mainly used internally to optimize query client updating.
16
21
  * Batches can be nested; the queue is only flushed once the outermost `batch` call finishes.
17
22
  * The return value of `callback` is passed through.
23
+ * @param callback - The function to run in the batch.
24
+ * @returns The return value of `callback`.
18
25
  */
19
26
  readonly batch: <T>(callback: () => T) => T;
20
27
  /**
21
28
  * All calls to the wrapped function will be batched.
29
+ * @param callback - The function to wrap.
30
+ * @returns A function that schedules a call to `callback` with the given arguments.
22
31
  */
23
32
  readonly batchCalls: <T extends Array<unknown>>(callback: BatchCallsCallback<T>) => BatchCallsCallback<T>;
24
33
  /**
@@ -29,13 +38,14 @@ export declare function createNotifyManager(): {
29
38
  /**
30
39
  * Use this method to set a custom notify function.
31
40
  * This can be used to for example wrap notifications with `React.act` while running tests.
41
+ * @param fn - Receives each notification callback and must call it.
32
42
  */
33
43
  readonly setNotifyFunction: (fn: NotifyFunction) => void;
34
44
  /**
35
45
  * Use this method to set a custom function to batch notifications together into a single tick.
36
46
  * Framework adapters use this to plug in their own batching primitive, so that a single query
37
47
  * update only triggers one re-render instead of one per subscriber.
38
- *
48
+ * @param fn - Receives a function that runs a batch of notifications and must call it.
39
49
  * @example
40
50
  * ```ts
41
51
  * import { notifyManager } from '@tanstack/query-core'
@@ -48,7 +58,7 @@ export declare function createNotifyManager(): {
48
58
  /**
49
59
  * Configures a custom callback that schedules when the next batch runs.
50
60
  * The default behavior is `setTimeout(callback, 0)`.
51
- *
61
+ * @param fn - Receives a callback that runs the next batch, and schedules it.
52
62
  * @example
53
63
  * ```ts
54
64
  * import { notifyManager } from '@tanstack/query-core'
@@ -74,10 +84,14 @@ export declare const notifyManager: {
74
84
  * This is mainly used internally to optimize query client updating.
75
85
  * Batches can be nested; the queue is only flushed once the outermost `batch` call finishes.
76
86
  * The return value of `callback` is passed through.
87
+ * @param callback - The function to run in the batch.
88
+ * @returns The return value of `callback`.
77
89
  */
78
90
  readonly batch: <T>(callback: () => T) => T;
79
91
  /**
80
92
  * All calls to the wrapped function will be batched.
93
+ * @param callback - The function to wrap.
94
+ * @returns A function that schedules a call to `callback` with the given arguments.
81
95
  */
82
96
  readonly batchCalls: <T extends Array<unknown>>(callback: BatchCallsCallback<T>) => BatchCallsCallback<T>;
83
97
  /**
@@ -88,13 +102,14 @@ export declare const notifyManager: {
88
102
  /**
89
103
  * Use this method to set a custom notify function.
90
104
  * This can be used to for example wrap notifications with `React.act` while running tests.
105
+ * @param fn - Receives each notification callback and must call it.
91
106
  */
92
107
  readonly setNotifyFunction: (fn: NotifyFunction) => void;
93
108
  /**
94
109
  * Use this method to set a custom function to batch notifications together into a single tick.
95
110
  * Framework adapters use this to plug in their own batching primitive, so that a single query
96
111
  * update only triggers one re-render instead of one per subscriber.
97
- *
112
+ * @param fn - Receives a function that runs a batch of notifications and must call it.
98
113
  * @example
99
114
  * ```ts
100
115
  * import { notifyManager } from '@tanstack/query-core'
@@ -107,7 +122,7 @@ export declare const notifyManager: {
107
122
  /**
108
123
  * Configures a custom callback that schedules when the next batch runs.
109
124
  * The default behavior is `setTimeout(callback, 0)`.
110
- *
125
+ * @param fn - Receives a callback that runs the next batch, and schedules it.
111
126
  * @example
112
127
  * ```ts
113
128
  * import { notifyManager } from '@tanstack/query-core'
@@ -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;;;;;qBAMZ,kBAAkB;wBAEf;;;;;;;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;;;;;qBAWV;;;;;;;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
+ {"version":3,"file":"notifyManager.d.cts","names":[],"sources":["../../src/notifyManager.ts"],"mappings":";KAIK;KAEA,kBAAkB;KAElB,uBAAuB;KAEvB,mBAAmB,UAAU,sBAAsB,MAAM;KAEzD,oBAAoB;;;;;qBAMZ,kBAAkB;;;;;;wBAOf;;;;;;;;;WA2CJ,QAAA,GAAC,gBAAkB,MAAI;;;;;;WAkBlB,aAAA,UAAU,gBAAc,UACzB,mBAAmB,OAC5B,mBAAmB;;;;;WApDI,WAAA,UAAA;;;;;;WAqEF,oBAAA,IAAA;;;;;;;;;;;;;;WAgBK,yBAAA,IAAA;;;;;;;;;;;;;;;;;;;WAqBV,eAAA,IAAA;;;;;qBAWV;;;;;;;;;WArFD,QAAA,GAAC,gBAAkB,MAAI;;;;;;WAkBlB,aAAA,UAAU,gBAAc,UACzB,mBAAmB,OAC5B,mBAAmB;;;;;WApDI,WAAA,UAAA;;;;;;WAqEF,oBAAA,IAAA;;;;;;;;;;;;;;WAgBK,yBAAA,IAAA;;;;;;;;;;;;;;;;;;;WAqBV,eAAA,IAAA"}
@@ -9,16 +9,25 @@ type ScheduleFunction = (callback: () => void) => void;
9
9
  * Schedules the callback with the system's `setTimeout(callback, 0)`.
10
10
  */
11
11
  export declare const defaultScheduler: ScheduleFunction;
12
+ /**
13
+ * Creates a notify manager, which schedules and batches notifications to subscribers. Query uses a
14
+ * single instance of it, exported as {@link notifyManager}.
15
+ * @returns A new notify manager.
16
+ */
12
17
  export declare function createNotifyManager(): {
13
18
  /**
14
19
  * Batches all updates scheduled inside the passed callback.
15
20
  * This is mainly used internally to optimize query client updating.
16
21
  * Batches can be nested; the queue is only flushed once the outermost `batch` call finishes.
17
22
  * The return value of `callback` is passed through.
23
+ * @param callback - The function to run in the batch.
24
+ * @returns The return value of `callback`.
18
25
  */
19
26
  readonly batch: <T>(callback: () => T) => T;
20
27
  /**
21
28
  * All calls to the wrapped function will be batched.
29
+ * @param callback - The function to wrap.
30
+ * @returns A function that schedules a call to `callback` with the given arguments.
22
31
  */
23
32
  readonly batchCalls: <T extends Array<unknown>>(callback: BatchCallsCallback<T>) => BatchCallsCallback<T>;
24
33
  /**
@@ -29,13 +38,14 @@ export declare function createNotifyManager(): {
29
38
  /**
30
39
  * Use this method to set a custom notify function.
31
40
  * This can be used to for example wrap notifications with `React.act` while running tests.
41
+ * @param fn - Receives each notification callback and must call it.
32
42
  */
33
43
  readonly setNotifyFunction: (fn: NotifyFunction) => void;
34
44
  /**
35
45
  * Use this method to set a custom function to batch notifications together into a single tick.
36
46
  * Framework adapters use this to plug in their own batching primitive, so that a single query
37
47
  * update only triggers one re-render instead of one per subscriber.
38
- *
48
+ * @param fn - Receives a function that runs a batch of notifications and must call it.
39
49
  * @example
40
50
  * ```ts
41
51
  * import { notifyManager } from '@tanstack/query-core'
@@ -48,7 +58,7 @@ export declare function createNotifyManager(): {
48
58
  /**
49
59
  * Configures a custom callback that schedules when the next batch runs.
50
60
  * The default behavior is `setTimeout(callback, 0)`.
51
- *
61
+ * @param fn - Receives a callback that runs the next batch, and schedules it.
52
62
  * @example
53
63
  * ```ts
54
64
  * import { notifyManager } from '@tanstack/query-core'
@@ -74,10 +84,14 @@ export declare const notifyManager: {
74
84
  * This is mainly used internally to optimize query client updating.
75
85
  * Batches can be nested; the queue is only flushed once the outermost `batch` call finishes.
76
86
  * The return value of `callback` is passed through.
87
+ * @param callback - The function to run in the batch.
88
+ * @returns The return value of `callback`.
77
89
  */
78
90
  readonly batch: <T>(callback: () => T) => T;
79
91
  /**
80
92
  * All calls to the wrapped function will be batched.
93
+ * @param callback - The function to wrap.
94
+ * @returns A function that schedules a call to `callback` with the given arguments.
81
95
  */
82
96
  readonly batchCalls: <T extends Array<unknown>>(callback: BatchCallsCallback<T>) => BatchCallsCallback<T>;
83
97
  /**
@@ -88,13 +102,14 @@ export declare const notifyManager: {
88
102
  /**
89
103
  * Use this method to set a custom notify function.
90
104
  * This can be used to for example wrap notifications with `React.act` while running tests.
105
+ * @param fn - Receives each notification callback and must call it.
91
106
  */
92
107
  readonly setNotifyFunction: (fn: NotifyFunction) => void;
93
108
  /**
94
109
  * Use this method to set a custom function to batch notifications together into a single tick.
95
110
  * Framework adapters use this to plug in their own batching primitive, so that a single query
96
111
  * update only triggers one re-render instead of one per subscriber.
97
- *
112
+ * @param fn - Receives a function that runs a batch of notifications and must call it.
98
113
  * @example
99
114
  * ```ts
100
115
  * import { notifyManager } from '@tanstack/query-core'
@@ -107,7 +122,7 @@ export declare const notifyManager: {
107
122
  /**
108
123
  * Configures a custom callback that schedules when the next batch runs.
109
124
  * The default behavior is `setTimeout(callback, 0)`.
110
- *
125
+ * @param fn - Receives a callback that runs the next batch, and schedules it.
111
126
  * @example
112
127
  * ```ts
113
128
  * import { notifyManager } from '@tanstack/query-core'
@@ -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;;;;;qBAMZ,kBAAkB;wBAEf;;;;;;;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;;;;;qBAWV;;;;;;;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
+ {"version":3,"file":"notifyManager.d.ts","names":[],"sources":["../../src/notifyManager.ts"],"mappings":";KAIK;KAEA,kBAAkB;KAElB,uBAAuB;KAEvB,mBAAmB,UAAU,sBAAsB,MAAM;KAEzD,oBAAoB;;;;;qBAMZ,kBAAkB;;;;;;wBAOf;;;;;;;;;WA2CJ,QAAA,GAAC,gBAAkB,MAAI;;;;;;WAkBlB,aAAA,UAAU,gBAAc,UACzB,mBAAmB,OAC5B,mBAAmB;;;;;WApDI,WAAA,UAAA;;;;;;WAqEF,oBAAA,IAAA;;;;;;;;;;;;;;WAgBK,yBAAA,IAAA;;;;;;;;;;;;;;;;;;;WAqBV,eAAA,IAAA;;;;;qBAWV;;;;;;;;;WArFD,QAAA,GAAC,gBAAkB,MAAI;;;;;;WAkBlB,aAAA,UAAU,gBAAc,UACzB,mBAAmB,OAC5B,mBAAmB;;;;;WApDI,WAAA,UAAA;;;;;;WAqEF,oBAAA,IAAA;;;;;;;;;;;;;;WAgBK,yBAAA,IAAA;;;;;;;;;;;;;;;;;;;WAqBV,eAAA,IAAA"}
@@ -5,6 +5,11 @@ import { systemSetTimeoutZero } from "./timeoutManager.js";
5
5
  * Schedules the callback with the system's `setTimeout(callback, 0)`.
6
6
  */
7
7
  const defaultScheduler = systemSetTimeoutZero;
8
+ /**
9
+ * Creates a notify manager, which schedules and batches notifications to subscribers. Query uses a
10
+ * single instance of it, exported as {@link notifyManager}.
11
+ * @returns A new notify manager.
12
+ */
8
13
  function createNotifyManager() {
9
14
  let queue = [];
10
15
  let transactions = 0;
@@ -38,6 +43,8 @@ function createNotifyManager() {
38
43
  * This is mainly used internally to optimize query client updating.
39
44
  * Batches can be nested; the queue is only flushed once the outermost `batch` call finishes.
40
45
  * The return value of `callback` is passed through.
46
+ * @param callback - The function to run in the batch.
47
+ * @returns The return value of `callback`.
41
48
  */
42
49
  batch: (callback) => {
43
50
  let result;
@@ -52,6 +59,8 @@ function createNotifyManager() {
52
59
  },
53
60
  /**
54
61
  * All calls to the wrapped function will be batched.
62
+ * @param callback - The function to wrap.
63
+ * @returns A function that schedules a call to `callback` with the given arguments.
55
64
  */
56
65
  batchCalls: (callback) => {
57
66
  return (...args) => {
@@ -68,6 +77,7 @@ function createNotifyManager() {
68
77
  /**
69
78
  * Use this method to set a custom notify function.
70
79
  * This can be used to for example wrap notifications with `React.act` while running tests.
80
+ * @param fn - Receives each notification callback and must call it.
71
81
  */
72
82
  setNotifyFunction: (fn) => {
73
83
  notifyFn = fn;
@@ -76,7 +86,7 @@ function createNotifyManager() {
76
86
  * Use this method to set a custom function to batch notifications together into a single tick.
77
87
  * Framework adapters use this to plug in their own batching primitive, so that a single query
78
88
  * update only triggers one re-render instead of one per subscriber.
79
- *
89
+ * @param fn - Receives a function that runs a batch of notifications and must call it.
80
90
  * @example
81
91
  * ```ts
82
92
  * import { notifyManager } from '@tanstack/query-core'
@@ -91,7 +101,7 @@ function createNotifyManager() {
91
101
  /**
92
102
  * Configures a custom callback that schedules when the next batch runs.
93
103
  * The default behavior is `setTimeout(callback, 0)`.
94
- *
104
+ * @param fn - Receives a callback that runs the next batch, and schedules it.
95
105
  * @example
96
106
  * ```ts
97
107
  * import { notifyManager } from '@tanstack/query-core'
@@ -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\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
+ {"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\n/**\n * Creates a notify manager, which schedules and batches notifications to subscribers. Query uses a\n * single instance of it, exported as {@link notifyManager}.\n * @returns A new notify manager.\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 * @param callback - The function to run in the batch.\n * @returns The return value of `callback`.\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 * @param callback - The function to wrap.\n * @returns A function that schedules a call to `callback` with the given arguments.\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 * @param fn - Receives each notification callback and must call it.\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 * @param fn - Receives a function that runs a batch of notifications and must call it.\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 * @param fn - Receives a callback that runs the next batch, and schedules it.\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;;;;;;AAOlD,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;;;;;;;;;EASL,QAAW,aAAyB;GAClC,IAAI;GACJ;GACA,IAAI;IACF,SAAS,SAAS;GACpB,UAAU;IACR;IACA,IAAI,CAAC,cACH,MAAM;GAEV;GACA,OAAO;EACT;;;;;;EAMA,aACE,aAC0B;GAC1B,QAAQ,GAAG,SAAS;IAClB,eAAe;KACb,SAAS,GAAG,IAAI;IAClB,CAAC;GACH;EACF;;;;;EAKA;;;;;;EAMA,oBAAoB,OAAuB;GACzC,WAAW;EACb;;;;;;;;;;;;;;EAcA,yBAAyB,OAA4B;GACnD,gBAAgB;EAClB;;;;;;;;;;;;;;;;;;;EAmBA,eAAe,OAAyB;GACtC,aAAa;EACf;CACF;AACF;;;;AAOA,MAAa,gBAAgB,oBAAoB"}
@@ -48,7 +48,8 @@ var OnlineManager = class extends require_subscribable.Subscribable {
48
48
  * be used to determine the online state. The provided `setup` function
49
49
  * receives a `setOnline` callback that should be called with a `boolean`
50
50
  * whenever the online state changes.
51
- *
51
+ * @param setup - Receives the `setOnline` callback, registers the event listener, and may return
52
+ * a cleanup function that is called when the listener is replaced or no longer needed.
52
53
  * @example
53
54
  * ```ts
54
55
  * import NetInfo from '@react-native-community/netinfo'
@@ -69,7 +70,7 @@ var OnlineManager = class extends require_subscribable.Subscribable {
69
70
  }
70
71
  /**
71
72
  * `setOnline` can be used to manually set the online state.
72
- *
73
+ * @param online - The online state.
73
74
  * @example
74
75
  * ```ts
75
76
  * import { onlineManager } from '@tanstack/query-core'
@@ -91,6 +92,7 @@ var OnlineManager = class extends require_subscribable.Subscribable {
91
92
  }
92
93
  /**
93
94
  * `isOnline` can be used to get the current online state.
95
+ * @returns `true` if online.
94
96
  */
95
97
  isOnline() {
96
98
  return require_classPrivateFieldSet2._classPrivateFieldGet2(_online, this);
@@ -1 +1 @@
1
- {"version":3,"file":"onlineManager.cjs","names":["Subscribable"],"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;CAMxD,cAAc;EACZ,MAAM;EANE,8BAAA,2BAAA,MAAA,SAAA,IAAA;;;EAOR,8BAAA,uBAAA,QAAA,OAAe,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,CAAA;CACF;CAEA,cAA8B;EAC5B,IAAI,CAAA,8BAAA,uBAAA,UAAC,IAAA,GACH,KAAK,iBAAA,8BAAA,uBAAA,QAAiB,IAAA,CAAW;CAErC;CAEA,gBAA0B;EACxB,IAAI,CAAC,KAAK,aAAa,GAAG;;GACxB,CAAA,2BAAA,8BAAA,uBAAA,UAAA,IAAA,OAAA,QAAA,6BAAA,KAAA,KAAA,yBAAA,KAAA,IAAgB;GAChB,8BAAA,uBAAA,UAAA,MAAgB,KAAA,CAAA;EAClB;CACF;;;;;;;;;;;;;;;;;;;CAoBA,iBAAiB,OAAsB;;EACrC,8BAAA,uBAAA,QAAA,MAAc,KAAA;EACd,CAAA,yBAAA,8BAAA,uBAAA,UAAA,IAAA,OAAA,QAAA,2BAAA,KAAA,KAAA,uBAAA,KAAA,IAAgB;EAChB,8BAAA,uBAAA,UAAA,MAAgB,MAAM,KAAK,UAAU,KAAK,IAAI,CAAC,CAAA;CACjD;;;;;;;;;;;;;;;CAgBA,UAAU,QAAuB;EAG/B,IAAA,8BAAA,uBAAA,SAFgB,IAAA,MAAiB,QAEpB;GACX,8BAAA,uBAAA,SAAA,MAAe,MAAA;GACf,KAAK,UAAU,SAAS,aAAa;IACnC,SAAS,MAAM;GACjB,CAAC;EACH;CACF;;;;CAKA,WAAoB;EAClB,OAAA,8BAAA,uBAAA,SAAO,IAAA;CACT;AACF;;;;AAKA,MAAa,gBAAgB,IAAI,cAAc"}
1
+ {"version":3,"file":"onlineManager.cjs","names":["Subscribable"],"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 // oxlint-disable-next-line typescript/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 override onSubscribe(): void {\n if (!this.#cleanup) {\n this.setEventListener(this.#setup)\n }\n }\n\n protected override 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 * @param setup - Receives the `setOnline` callback, registers the event listener, and may return\n * a cleanup function that is called when the listener is replaced or no longer needed.\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 * @param online - The online state.\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 * @returns `true` if online.\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;CAMxD,cAAc;EACZ,MAAM;EANE,8BAAA,2BAAA,MAAA,SAAA,IAAA;;;EAOR,8BAAA,uBAAA,QAAA,OAAe,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,CAAA;CACF;CAEA,cAAuC;EACrC,IAAI,CAAA,8BAAA,uBAAA,UAAC,IAAA,GACH,KAAK,iBAAA,8BAAA,uBAAA,QAAiB,IAAA,CAAW;CAErC;CAEA,gBAAmC;EACjC,IAAI,CAAC,KAAK,aAAa,GAAG;;GACxB,CAAA,2BAAA,8BAAA,uBAAA,UAAA,IAAA,OAAA,QAAA,6BAAA,KAAA,KAAA,yBAAA,KAAA,IAAgB;GAChB,8BAAA,uBAAA,UAAA,MAAgB,KAAA,CAAA;EAClB;CACF;;;;;;;;;;;;;;;;;;;;CAqBA,iBAAiB,OAAsB;;EACrC,8BAAA,uBAAA,QAAA,MAAc,KAAA;EACd,CAAA,yBAAA,8BAAA,uBAAA,UAAA,IAAA,OAAA,QAAA,2BAAA,KAAA,KAAA,uBAAA,KAAA,IAAgB;EAChB,8BAAA,uBAAA,UAAA,MAAgB,MAAM,KAAK,UAAU,KAAK,IAAI,CAAC,CAAA;CACjD;;;;;;;;;;;;;;;CAgBA,UAAU,QAAuB;EAG/B,IAAA,8BAAA,uBAAA,SAFgB,IAAA,MAAiB,QAEpB;GACX,8BAAA,uBAAA,SAAA,MAAe,MAAA;GACf,KAAK,UAAU,SAAS,aAAa;IACnC,SAAS,MAAM;GACjB,CAAC;EACH;CACF;;;;;CAMA,WAAoB;EAClB,OAAA,8BAAA,uBAAA,SAAO,IAAA;CACT;AACF;;;;AAKA,MAAa,gBAAgB,IAAI,cAAc"}
@@ -1,4 +1,4 @@
1
- import { t as Subscribable } from "./subscribable-CysQ0tne.cjs";
1
+ import { t as Subscribable } from "./subscribable-czlHOxMP.cjs";
2
2
  //#region src/onlineManager.d.ts
3
3
  type Listener = (online: boolean) => void;
4
4
  type SetupFn = (setOnline: Listener) => (() => void) | undefined;
@@ -21,7 +21,8 @@ export declare class OnlineManager extends Subscribable<Listener> {
21
21
  * be used to determine the online state. The provided `setup` function
22
22
  * receives a `setOnline` callback that should be called with a `boolean`
23
23
  * whenever the online state changes.
24
- *
24
+ * @param setup - Receives the `setOnline` callback, registers the event listener, and may return
25
+ * a cleanup function that is called when the listener is replaced or no longer needed.
25
26
  * @example
26
27
  * ```ts
27
28
  * import NetInfo from '@react-native-community/netinfo'
@@ -37,7 +38,7 @@ export declare class OnlineManager extends Subscribable<Listener> {
37
38
  setEventListener(setup: SetupFn): void;
38
39
  /**
39
40
  * `setOnline` can be used to manually set the online state.
40
- *
41
+ * @param online - The online state.
41
42
  * @example
42
43
  * ```ts
43
44
  * import { onlineManager } from '@tanstack/query-core'
@@ -52,6 +53,7 @@ export declare class OnlineManager extends Subscribable<Listener> {
52
53
  setOnline(online: boolean): void;
53
54
  /**
54
55
  * `isOnline` can be used to get the current online state.
56
+ * @returns `true` if online.
55
57
  */
56
58
  isOnline(): boolean;
57
59
  }
@@ -1 +1 @@
1
- {"version":3,"file":"onlineManager.d.cts","names":[],"sources":["../../src/onlineManager.ts"],"mappings":";;KAEK,YAAY;KACZ,WAAW,WAAW;;;;;;;;;;qBAWd,sBAAsB,aAAa;;;YA6BpC;YAMA;;;;;;;;;;;;;;;;;;;EAyBV,iBAAiB,OAAO;;;;;;;;;;;;;;;EAoBxB,UAAU;;;;EAcV;;;;;qBAQW,eAAa"}
1
+ {"version":3,"file":"onlineManager.d.cts","names":[],"sources":["../../src/onlineManager.ts"],"mappings":";;KAEK,YAAY;KACZ,WAAW,WAAW;;;;;;;;;;qBAWd,sBAAsB,aAAa;;;YA6B3B;YAMA;;;;;;;;;;;;;;;;;;;;EA0BnB,iBAAiB,OAAO;;;;;;;;;;;;;;;EAoBxB,UAAU;;;;;EAeV;;;;;qBAQW,eAAa"}
@@ -1,4 +1,4 @@
1
- import { t as Subscribable } from "./subscribable-CysQ0tne.js";
1
+ import { t as Subscribable } from "./subscribable-czlHOxMP.js";
2
2
  //#region src/onlineManager.d.ts
3
3
  type Listener = (online: boolean) => void;
4
4
  type SetupFn = (setOnline: Listener) => (() => void) | undefined;
@@ -21,7 +21,8 @@ export declare class OnlineManager extends Subscribable<Listener> {
21
21
  * be used to determine the online state. The provided `setup` function
22
22
  * receives a `setOnline` callback that should be called with a `boolean`
23
23
  * whenever the online state changes.
24
- *
24
+ * @param setup - Receives the `setOnline` callback, registers the event listener, and may return
25
+ * a cleanup function that is called when the listener is replaced or no longer needed.
25
26
  * @example
26
27
  * ```ts
27
28
  * import NetInfo from '@react-native-community/netinfo'
@@ -37,7 +38,7 @@ export declare class OnlineManager extends Subscribable<Listener> {
37
38
  setEventListener(setup: SetupFn): void;
38
39
  /**
39
40
  * `setOnline` can be used to manually set the online state.
40
- *
41
+ * @param online - The online state.
41
42
  * @example
42
43
  * ```ts
43
44
  * import { onlineManager } from '@tanstack/query-core'
@@ -52,6 +53,7 @@ export declare class OnlineManager extends Subscribable<Listener> {
52
53
  setOnline(online: boolean): void;
53
54
  /**
54
55
  * `isOnline` can be used to get the current online state.
56
+ * @returns `true` if online.
55
57
  */
56
58
  isOnline(): boolean;
57
59
  }
@@ -1 +1 @@
1
- {"version":3,"file":"onlineManager.d.ts","names":[],"sources":["../../src/onlineManager.ts"],"mappings":";;KAEK,YAAY;KACZ,WAAW,WAAW;;;;;;;;;;qBAWd,sBAAsB,aAAa;;;YA6BpC;YAMA;;;;;;;;;;;;;;;;;;;EAyBV,iBAAiB,OAAO;;;;;;;;;;;;;;;EAoBxB,UAAU;;;;EAcV;;;;;qBAQW,eAAa"}
1
+ {"version":3,"file":"onlineManager.d.ts","names":[],"sources":["../../src/onlineManager.ts"],"mappings":";;KAEK,YAAY;KACZ,WAAW,WAAW;;;;;;;;;;qBAWd,sBAAsB,aAAa;;;YA6B3B;YAMA;;;;;;;;;;;;;;;;;;;;EA0BnB,iBAAiB,OAAO;;;;;;;;;;;;;;;EAoBxB,UAAU;;;;;EAeV;;;;;qBAQW,eAAa"}
@@ -47,7 +47,8 @@ var OnlineManager = class extends Subscribable {
47
47
  * be used to determine the online state. The provided `setup` function
48
48
  * receives a `setOnline` callback that should be called with a `boolean`
49
49
  * whenever the online state changes.
50
- *
50
+ * @param setup - Receives the `setOnline` callback, registers the event listener, and may return
51
+ * a cleanup function that is called when the listener is replaced or no longer needed.
51
52
  * @example
52
53
  * ```ts
53
54
  * import NetInfo from '@react-native-community/netinfo'
@@ -68,7 +69,7 @@ var OnlineManager = class extends Subscribable {
68
69
  }
69
70
  /**
70
71
  * `setOnline` can be used to manually set the online state.
71
- *
72
+ * @param online - The online state.
72
73
  * @example
73
74
  * ```ts
74
75
  * import { onlineManager } from '@tanstack/query-core'
@@ -90,6 +91,7 @@ var OnlineManager = class extends Subscribable {
90
91
  }
91
92
  /**
92
93
  * `isOnline` can be used to get the current online state.
94
+ * @returns `true` if online.
93
95
  */
94
96
  isOnline() {
95
97
  return _classPrivateFieldGet2(_online, this);
@@ -1 +1 @@
1
- {"version":3,"file":"onlineManager.js","names":[],"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,cAAmC,aAAuB;CAMxD,cAAc;EACZ,MAAM;EANE,2BAAA,MAAA,SAAA,IAAA;;;EAOR,uBAAA,QAAA,OAAe,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,CAAA;CACF;CAEA,cAA8B;EAC5B,IAAI,CAAA,uBAAA,UAAC,IAAA,GACH,KAAK,iBAAA,uBAAA,QAAiB,IAAA,CAAW;CAErC;CAEA,gBAA0B;EACxB,IAAI,CAAC,KAAK,aAAa,GAAG;;GACxB,CAAA,2BAAA,uBAAA,UAAA,IAAA,OAAA,QAAA,6BAAA,KAAA,KAAA,yBAAA,KAAA,IAAgB;GAChB,uBAAA,UAAA,MAAgB,KAAA,CAAA;EAClB;CACF;;;;;;;;;;;;;;;;;;;CAoBA,iBAAiB,OAAsB;;EACrC,uBAAA,QAAA,MAAc,KAAA;EACd,CAAA,yBAAA,uBAAA,UAAA,IAAA,OAAA,QAAA,2BAAA,KAAA,KAAA,uBAAA,KAAA,IAAgB;EAChB,uBAAA,UAAA,MAAgB,MAAM,KAAK,UAAU,KAAK,IAAI,CAAC,CAAA;CACjD;;;;;;;;;;;;;;;CAgBA,UAAU,QAAuB;EAG/B,IAAA,uBAAA,SAFgB,IAAA,MAAiB,QAEpB;GACX,uBAAA,SAAA,MAAe,MAAA;GACf,KAAK,UAAU,SAAS,aAAa;IACnC,SAAS,MAAM;GACjB,CAAC;EACH;CACF;;;;CAKA,WAAoB;EAClB,OAAA,uBAAA,SAAO,IAAA;CACT;AACF;;;;AAKA,MAAa,gBAAgB,IAAI,cAAc"}
1
+ {"version":3,"file":"onlineManager.js","names":[],"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 // oxlint-disable-next-line typescript/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 override onSubscribe(): void {\n if (!this.#cleanup) {\n this.setEventListener(this.#setup)\n }\n }\n\n protected override 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 * @param setup - Receives the `setOnline` callback, registers the event listener, and may return\n * a cleanup function that is called when the listener is replaced or no longer needed.\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 * @param online - The online state.\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 * @returns `true` if online.\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,cAAmC,aAAuB;CAMxD,cAAc;EACZ,MAAM;EANE,2B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