@tanstack/query-core 5.0.0-alpha.31 → 5.0.0-alpha.33
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.
- package/build/lib/index.d.ts +1 -0
- package/build/lib/mutationObserver.esm.js +1 -1
- package/build/lib/mutationObserver.esm.js.map +1 -1
- package/build/lib/mutationObserver.js +1 -1
- package/build/lib/mutationObserver.js.map +1 -1
- package/build/lib/mutationObserver.mjs +1 -1
- package/build/lib/mutationObserver.mjs.map +1 -1
- package/build/lib/queriesObserver.d.ts +12 -5
- package/build/lib/queriesObserver.esm.js +52 -13
- package/build/lib/queriesObserver.esm.js.map +1 -1
- package/build/lib/queriesObserver.js +52 -13
- package/build/lib/queriesObserver.js.map +1 -1
- package/build/lib/queriesObserver.mjs +35 -13
- package/build/lib/queriesObserver.mjs.map +1 -1
- package/build/lib/queryObserver.esm.js +3 -3
- package/build/lib/queryObserver.esm.js.map +1 -1
- package/build/lib/queryObserver.js +3 -3
- package/build/lib/queryObserver.js.map +1 -1
- package/build/lib/queryObserver.mjs +3 -3
- package/build/lib/queryObserver.mjs.map +1 -1
- package/build/lib/subscribable.d.ts +1 -1
- package/build/lib/subscribable.esm.js +4 -4
- package/build/lib/subscribable.esm.js.map +1 -1
- package/build/lib/subscribable.js +4 -4
- package/build/lib/subscribable.js.map +1 -1
- package/build/lib/subscribable.mjs +4 -4
- package/build/lib/subscribable.mjs.map +1 -1
- package/build/umd/index.development.js +42 -21
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +1 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +1 -0
- package/src/mutationObserver.ts +1 -1
- package/src/queriesObserver.ts +66 -16
- package/src/queryObserver.ts +3 -3
- package/src/subscribable.ts +5 -5
- package/build/lib/focusManager.d.ts.map +0 -1
- package/build/lib/hydration.d.ts.map +0 -1
- package/build/lib/index.d.ts.map +0 -1
- package/build/lib/infiniteQueryBehavior.d.ts.map +0 -1
- package/build/lib/infiniteQueryObserver.d.ts.map +0 -1
- package/build/lib/mutation.d.ts.map +0 -1
- package/build/lib/mutationCache.d.ts.map +0 -1
- package/build/lib/mutationObserver.d.ts.map +0 -1
- package/build/lib/notifyManager.d.ts.map +0 -1
- package/build/lib/onlineManager.d.ts.map +0 -1
- package/build/lib/queriesObserver.d.ts.map +0 -1
- package/build/lib/query.d.ts.map +0 -1
- package/build/lib/queryCache.d.ts.map +0 -1
- package/build/lib/queryClient.d.ts.map +0 -1
- package/build/lib/queryObserver.d.ts.map +0 -1
- package/build/lib/removable.d.ts.map +0 -1
- package/build/lib/retryer.d.ts.map +0 -1
- package/build/lib/subscribable.d.ts.map +0 -1
- package/build/lib/tests/focusManager.test.d.ts.map +0 -1
- package/build/lib/tests/hydration.test.d.ts.map +0 -1
- package/build/lib/tests/infiniteQueryBehavior.test.d.ts.map +0 -1
- package/build/lib/tests/infiniteQueryObserver.test.d.ts.map +0 -1
- package/build/lib/tests/mutationCache.test.d.ts.map +0 -1
- package/build/lib/tests/mutationObserver.test.d.ts.map +0 -1
- package/build/lib/tests/mutations.test.d.ts.map +0 -1
- package/build/lib/tests/notifyManager.test.d.ts.map +0 -1
- package/build/lib/tests/onlineManager.test.d.ts.map +0 -1
- package/build/lib/tests/queriesObserver.test.d.ts.map +0 -1
- package/build/lib/tests/query.test.d.ts.map +0 -1
- package/build/lib/tests/queryCache.test.d.ts.map +0 -1
- package/build/lib/tests/queryClient.test.d.ts.map +0 -1
- package/build/lib/tests/queryObserver.test.d.ts.map +0 -1
- package/build/lib/tests/utils.d.ts.map +0 -1
- package/build/lib/tests/utils.test.d.ts.map +0 -1
- package/build/lib/types.d.ts.map +0 -1
- package/build/lib/utils.d.ts.map +0 -1
|
@@ -6,19 +6,19 @@
|
|
|
6
6
|
|
|
7
7
|
class Subscribable {
|
|
8
8
|
constructor() {
|
|
9
|
-
this.listeners =
|
|
9
|
+
this.listeners = new Set();
|
|
10
10
|
this.subscribe = this.subscribe.bind(this);
|
|
11
11
|
}
|
|
12
12
|
subscribe(listener) {
|
|
13
|
-
this.listeners.
|
|
13
|
+
this.listeners.add(listener);
|
|
14
14
|
this.onSubscribe();
|
|
15
15
|
return () => {
|
|
16
|
-
this.listeners
|
|
16
|
+
this.listeners.delete(listener);
|
|
17
17
|
this.onUnsubscribe();
|
|
18
18
|
};
|
|
19
19
|
}
|
|
20
20
|
hasListeners() {
|
|
21
|
-
return this.listeners.
|
|
21
|
+
return this.listeners.size > 0;
|
|
22
22
|
}
|
|
23
23
|
onSubscribe() {
|
|
24
24
|
// Do nothing
|
|
@@ -1875,7 +1875,7 @@
|
|
|
1875
1875
|
this.refetch = this.refetch.bind(this);
|
|
1876
1876
|
}
|
|
1877
1877
|
onSubscribe() {
|
|
1878
|
-
if (this.listeners.
|
|
1878
|
+
if (this.listeners.size === 1) {
|
|
1879
1879
|
this.#currentQuery.addObserver(this);
|
|
1880
1880
|
if (shouldFetchOnMount(this.#currentQuery, this.options)) {
|
|
1881
1881
|
this.#executeFetch();
|
|
@@ -1884,7 +1884,7 @@
|
|
|
1884
1884
|
}
|
|
1885
1885
|
}
|
|
1886
1886
|
onUnsubscribe() {
|
|
1887
|
-
if (!this.
|
|
1887
|
+
if (!this.hasListeners()) {
|
|
1888
1888
|
this.destroy();
|
|
1889
1889
|
}
|
|
1890
1890
|
}
|
|
@@ -1895,7 +1895,7 @@
|
|
|
1895
1895
|
return shouldFetchOn(this.#currentQuery, this.options, this.options.refetchOnWindowFocus);
|
|
1896
1896
|
}
|
|
1897
1897
|
destroy() {
|
|
1898
|
-
this.listeners =
|
|
1898
|
+
this.listeners = new Set();
|
|
1899
1899
|
this.#clearStaleTimeout();
|
|
1900
1900
|
this.#clearRefetchInterval();
|
|
1901
1901
|
this.#currentQuery.removeObserver(this);
|
|
@@ -2279,18 +2279,22 @@
|
|
|
2279
2279
|
#result;
|
|
2280
2280
|
#queries;
|
|
2281
2281
|
#observers;
|
|
2282
|
-
|
|
2282
|
+
#options;
|
|
2283
|
+
#combinedResult;
|
|
2284
|
+
constructor(client, queries, options) {
|
|
2283
2285
|
super();
|
|
2284
2286
|
this.#client = client;
|
|
2285
2287
|
this.#queries = [];
|
|
2286
|
-
this.#result = [];
|
|
2287
2288
|
this.#observers = [];
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
|
|
2289
|
+
this.#setResult([]);
|
|
2290
|
+
this.setQueries(queries, options);
|
|
2291
|
+
}
|
|
2292
|
+
#setResult(value) {
|
|
2293
|
+
this.#result = value;
|
|
2294
|
+
this.#combinedResult = this.#combineResult(value);
|
|
2291
2295
|
}
|
|
2292
2296
|
onSubscribe() {
|
|
2293
|
-
if (this.listeners.
|
|
2297
|
+
if (this.listeners.size === 1) {
|
|
2294
2298
|
this.#observers.forEach(observer => {
|
|
2295
2299
|
observer.subscribe(result => {
|
|
2296
2300
|
this.#onUpdate(observer, result);
|
|
@@ -2299,18 +2303,19 @@
|
|
|
2299
2303
|
}
|
|
2300
2304
|
}
|
|
2301
2305
|
onUnsubscribe() {
|
|
2302
|
-
if (!this.listeners.
|
|
2306
|
+
if (!this.listeners.size) {
|
|
2303
2307
|
this.destroy();
|
|
2304
2308
|
}
|
|
2305
2309
|
}
|
|
2306
2310
|
destroy() {
|
|
2307
|
-
this.listeners =
|
|
2311
|
+
this.listeners = new Set();
|
|
2308
2312
|
this.#observers.forEach(observer => {
|
|
2309
2313
|
observer.destroy();
|
|
2310
2314
|
});
|
|
2311
2315
|
}
|
|
2312
|
-
setQueries(queries, notifyOptions) {
|
|
2316
|
+
setQueries(queries, options, notifyOptions) {
|
|
2313
2317
|
this.#queries = queries;
|
|
2318
|
+
this.#options = options;
|
|
2314
2319
|
notifyManager.batch(() => {
|
|
2315
2320
|
const prevObservers = this.#observers;
|
|
2316
2321
|
const newObserverMatches = this.#findMatchingObservers(this.#queries);
|
|
@@ -2324,7 +2329,7 @@
|
|
|
2324
2329
|
return;
|
|
2325
2330
|
}
|
|
2326
2331
|
this.#observers = newObservers;
|
|
2327
|
-
this.#
|
|
2332
|
+
this.#setResult(newResult);
|
|
2328
2333
|
if (!this.hasListeners()) {
|
|
2329
2334
|
return;
|
|
2330
2335
|
}
|
|
@@ -2340,7 +2345,7 @@
|
|
|
2340
2345
|
});
|
|
2341
2346
|
}
|
|
2342
2347
|
getCurrentResult() {
|
|
2343
|
-
return this.#
|
|
2348
|
+
return this.#combinedResult;
|
|
2344
2349
|
}
|
|
2345
2350
|
getQueries() {
|
|
2346
2351
|
return this.#observers.map(observer => observer.getCurrentQuery());
|
|
@@ -2349,7 +2354,23 @@
|
|
|
2349
2354
|
return this.#observers;
|
|
2350
2355
|
}
|
|
2351
2356
|
getOptimisticResult(queries) {
|
|
2352
|
-
|
|
2357
|
+
const matches = this.#findMatchingObservers(queries);
|
|
2358
|
+
const result = matches.map(match => match.observer.getOptimisticResult(match.defaultedQueryOptions));
|
|
2359
|
+
return [result, r => {
|
|
2360
|
+
return this.#combineResult(r ?? result);
|
|
2361
|
+
}, () => {
|
|
2362
|
+
return matches.map((match, index) => {
|
|
2363
|
+
const observerResult = result[index];
|
|
2364
|
+
return !match.defaultedQueryOptions.notifyOnChangeProps ? match.observer.trackResult(observerResult) : observerResult;
|
|
2365
|
+
});
|
|
2366
|
+
}];
|
|
2367
|
+
}
|
|
2368
|
+
#combineResult(input) {
|
|
2369
|
+
const combine = this.#options?.combine;
|
|
2370
|
+
if (combine) {
|
|
2371
|
+
return replaceEqualDeep(this.#combinedResult, combine(input));
|
|
2372
|
+
}
|
|
2373
|
+
return input;
|
|
2353
2374
|
}
|
|
2354
2375
|
#findMatchingObservers(queries) {
|
|
2355
2376
|
const prevObservers = this.#observers;
|
|
@@ -2384,7 +2405,7 @@
|
|
|
2384
2405
|
#onUpdate(observer, result) {
|
|
2385
2406
|
const index = this.#observers.indexOf(observer);
|
|
2386
2407
|
if (index !== -1) {
|
|
2387
|
-
this.#
|
|
2408
|
+
this.#setResult(replaceAt(this.#result, index, result));
|
|
2388
2409
|
this.#notify();
|
|
2389
2410
|
}
|
|
2390
2411
|
}
|
|
@@ -2500,7 +2521,7 @@
|
|
|
2500
2521
|
this.#currentMutation?.setOptions(this.options);
|
|
2501
2522
|
}
|
|
2502
2523
|
onUnsubscribe() {
|
|
2503
|
-
if (!this.
|
|
2524
|
+
if (!this.hasListeners()) {
|
|
2504
2525
|
this.#currentMutation?.removeObserver(this);
|
|
2505
2526
|
}
|
|
2506
2527
|
}
|