@tanstack/solid-query 5.91.4 → 5.94.4
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/package.json +2 -2
- package/build/_tsup-dts-rollup.d.cts +0 -798
- package/build/_tsup-dts-rollup.d.ts +0 -798
- package/build/dev.cjs +0 -549
- package/build/dev.d.cts +0 -200
- package/build/dev.d.ts +0 -200
- package/build/dev.js +0 -530
- package/build/index.cjs +0 -540
- package/build/index.d.cts +0 -200
- package/build/index.d.ts +0 -200
- package/build/index.js +0 -521
package/build/index.js
DELETED
|
@@ -1,521 +0,0 @@
|
|
|
1
|
-
import { MutationObserver, shouldThrowError, QueriesObserver, noop, QueryClient as QueryClient$1, replaceEqualDeep, hydrate, notifyManager, QueryObserver, InfiniteQueryObserver } from '@tanstack/query-core';
|
|
2
|
-
export * from '@tanstack/query-core';
|
|
3
|
-
import { createContext, useContext, createRenderEffect, onCleanup, createMemo, createComputed, on, mergeProps, createResource, batch, onMount, createSignal, createEffect } from 'solid-js';
|
|
4
|
-
import { createComponent, isServer } from 'solid-js/web';
|
|
5
|
-
import { createStore, unwrap, reconcile } from 'solid-js/store';
|
|
6
|
-
|
|
7
|
-
// src/useQuery.ts
|
|
8
|
-
var QueryClientContext = createContext(void 0);
|
|
9
|
-
var useQueryClient = (queryClient) => {
|
|
10
|
-
if (queryClient) {
|
|
11
|
-
return queryClient;
|
|
12
|
-
}
|
|
13
|
-
const client = useContext(QueryClientContext);
|
|
14
|
-
if (!client) {
|
|
15
|
-
throw new Error("No QueryClient set, use QueryClientProvider to set one");
|
|
16
|
-
}
|
|
17
|
-
return client();
|
|
18
|
-
};
|
|
19
|
-
var QueryClientProvider = (props) => {
|
|
20
|
-
createRenderEffect((unmount) => {
|
|
21
|
-
unmount?.();
|
|
22
|
-
props.client.mount();
|
|
23
|
-
return props.client.unmount.bind(props.client);
|
|
24
|
-
});
|
|
25
|
-
onCleanup(() => props.client.unmount());
|
|
26
|
-
return createComponent(QueryClientContext.Provider, {
|
|
27
|
-
value: () => props.client,
|
|
28
|
-
get children() {
|
|
29
|
-
return props.children;
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
};
|
|
33
|
-
var IsRestoringContext = createContext(() => false);
|
|
34
|
-
var useIsRestoring = () => useContext(IsRestoringContext);
|
|
35
|
-
var IsRestoringProvider = IsRestoringContext.Provider;
|
|
36
|
-
|
|
37
|
-
// src/useBaseQuery.ts
|
|
38
|
-
function reconcileFn(store, result, reconcileOption, queryHash) {
|
|
39
|
-
if (reconcileOption === false) return result;
|
|
40
|
-
if (typeof reconcileOption === "function") {
|
|
41
|
-
const newData2 = reconcileOption(store.data, result.data);
|
|
42
|
-
return { ...result, data: newData2 };
|
|
43
|
-
}
|
|
44
|
-
let data = result.data;
|
|
45
|
-
if (store.data === void 0) {
|
|
46
|
-
try {
|
|
47
|
-
data = structuredClone(data);
|
|
48
|
-
} catch (error) {
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
const newData = reconcile(data, { key: reconcileOption })(store.data);
|
|
52
|
-
return { ...result, data: newData };
|
|
53
|
-
}
|
|
54
|
-
var hydratableObserverResult = (query, result) => {
|
|
55
|
-
if (!isServer) return result;
|
|
56
|
-
const obj = {
|
|
57
|
-
...unwrap(result),
|
|
58
|
-
// During SSR, functions cannot be serialized, so we need to remove them
|
|
59
|
-
// This is safe because we will add these functions back when the query is hydrated
|
|
60
|
-
refetch: void 0
|
|
61
|
-
};
|
|
62
|
-
if ("fetchNextPage" in result) {
|
|
63
|
-
obj.fetchNextPage = void 0;
|
|
64
|
-
obj.fetchPreviousPage = void 0;
|
|
65
|
-
}
|
|
66
|
-
obj.hydrationData = {
|
|
67
|
-
state: query.state,
|
|
68
|
-
queryKey: query.queryKey,
|
|
69
|
-
queryHash: query.queryHash,
|
|
70
|
-
...query.meta && { meta: query.meta }
|
|
71
|
-
};
|
|
72
|
-
return obj;
|
|
73
|
-
};
|
|
74
|
-
function useBaseQuery(options, Observer, queryClient) {
|
|
75
|
-
const client = createMemo(() => useQueryClient(queryClient?.()));
|
|
76
|
-
const isRestoring = useIsRestoring();
|
|
77
|
-
let unsubscribeQueued = false;
|
|
78
|
-
const defaultedOptions = createMemo(() => {
|
|
79
|
-
const defaultOptions = client().defaultQueryOptions(options());
|
|
80
|
-
defaultOptions._optimisticResults = isRestoring() ? "isRestoring" : "optimistic";
|
|
81
|
-
defaultOptions.structuralSharing = false;
|
|
82
|
-
if (isServer) {
|
|
83
|
-
defaultOptions.retry = false;
|
|
84
|
-
defaultOptions.throwOnError = true;
|
|
85
|
-
defaultOptions.experimental_prefetchInRender = true;
|
|
86
|
-
}
|
|
87
|
-
return defaultOptions;
|
|
88
|
-
});
|
|
89
|
-
const initialOptions = defaultedOptions();
|
|
90
|
-
const [observer, setObserver] = createSignal(
|
|
91
|
-
new Observer(client(), defaultedOptions())
|
|
92
|
-
);
|
|
93
|
-
let observerResult = observer().getOptimisticResult(defaultedOptions());
|
|
94
|
-
const [state, setState] = createStore(observerResult);
|
|
95
|
-
const createServerSubscriber = (resolve, reject) => {
|
|
96
|
-
return observer().subscribe((result) => {
|
|
97
|
-
notifyManager.batchCalls(() => {
|
|
98
|
-
const query = observer().getCurrentQuery();
|
|
99
|
-
const unwrappedResult = hydratableObserverResult(query, result);
|
|
100
|
-
if (result.data !== void 0 && unwrappedResult.isError) {
|
|
101
|
-
reject(unwrappedResult.error);
|
|
102
|
-
unsubscribeIfQueued();
|
|
103
|
-
} else {
|
|
104
|
-
resolve(unwrappedResult);
|
|
105
|
-
unsubscribeIfQueued();
|
|
106
|
-
}
|
|
107
|
-
})();
|
|
108
|
-
});
|
|
109
|
-
};
|
|
110
|
-
const unsubscribeIfQueued = () => {
|
|
111
|
-
if (unsubscribeQueued) {
|
|
112
|
-
unsubscribe?.();
|
|
113
|
-
unsubscribeQueued = false;
|
|
114
|
-
}
|
|
115
|
-
};
|
|
116
|
-
const createClientSubscriber = () => {
|
|
117
|
-
const obs = observer();
|
|
118
|
-
return obs.subscribe((result) => {
|
|
119
|
-
observerResult = result;
|
|
120
|
-
queueMicrotask(() => {
|
|
121
|
-
if (unsubscribe) {
|
|
122
|
-
refetch();
|
|
123
|
-
}
|
|
124
|
-
});
|
|
125
|
-
});
|
|
126
|
-
};
|
|
127
|
-
function setStateWithReconciliation(res) {
|
|
128
|
-
const opts = observer().options;
|
|
129
|
-
const reconcileOptions = opts.reconcile;
|
|
130
|
-
setState((store) => {
|
|
131
|
-
return reconcileFn(
|
|
132
|
-
store,
|
|
133
|
-
res,
|
|
134
|
-
reconcileOptions === void 0 ? false : reconcileOptions,
|
|
135
|
-
opts.queryHash
|
|
136
|
-
);
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
function createDeepSignal() {
|
|
140
|
-
return [
|
|
141
|
-
() => state,
|
|
142
|
-
(v) => {
|
|
143
|
-
const unwrapped = unwrap(state);
|
|
144
|
-
if (typeof v === "function") {
|
|
145
|
-
v = v(unwrapped);
|
|
146
|
-
}
|
|
147
|
-
if (v?.hydrationData) {
|
|
148
|
-
const { hydrationData, ...rest } = v;
|
|
149
|
-
v = rest;
|
|
150
|
-
}
|
|
151
|
-
setStateWithReconciliation(v);
|
|
152
|
-
}
|
|
153
|
-
];
|
|
154
|
-
}
|
|
155
|
-
let unsubscribe = null;
|
|
156
|
-
let resolver = null;
|
|
157
|
-
const [queryResource, { refetch }] = createResource(
|
|
158
|
-
() => {
|
|
159
|
-
const obs = observer();
|
|
160
|
-
return new Promise((resolve, reject) => {
|
|
161
|
-
resolver = resolve;
|
|
162
|
-
if (isServer) {
|
|
163
|
-
unsubscribe = createServerSubscriber(resolve, reject);
|
|
164
|
-
} else if (!unsubscribe && !isRestoring()) {
|
|
165
|
-
unsubscribe = createClientSubscriber();
|
|
166
|
-
}
|
|
167
|
-
obs.updateResult();
|
|
168
|
-
if (observerResult.isError && !observerResult.isFetching && !isRestoring() && shouldThrowError(obs.options.throwOnError, [
|
|
169
|
-
observerResult.error,
|
|
170
|
-
obs.getCurrentQuery()
|
|
171
|
-
])) {
|
|
172
|
-
setStateWithReconciliation(observerResult);
|
|
173
|
-
return reject(observerResult.error);
|
|
174
|
-
}
|
|
175
|
-
if (!observerResult.isLoading) {
|
|
176
|
-
resolver = null;
|
|
177
|
-
return resolve(
|
|
178
|
-
hydratableObserverResult(obs.getCurrentQuery(), observerResult)
|
|
179
|
-
);
|
|
180
|
-
}
|
|
181
|
-
setStateWithReconciliation(observerResult);
|
|
182
|
-
});
|
|
183
|
-
},
|
|
184
|
-
{
|
|
185
|
-
storage: createDeepSignal,
|
|
186
|
-
get deferStream() {
|
|
187
|
-
return options().deferStream;
|
|
188
|
-
},
|
|
189
|
-
/**
|
|
190
|
-
* If this resource was populated on the server (either sync render, or streamed in over time), onHydrated
|
|
191
|
-
* will be called. This is the point at which we can hydrate the query cache state, and setup the query subscriber.
|
|
192
|
-
*
|
|
193
|
-
* Leveraging onHydrated allows us to plug into the async and streaming support that solidjs resources already support.
|
|
194
|
-
*
|
|
195
|
-
* Note that this is only invoked on the client, for queries that were originally run on the server.
|
|
196
|
-
*/
|
|
197
|
-
onHydrated(_k, info) {
|
|
198
|
-
if (info.value && "hydrationData" in info.value) {
|
|
199
|
-
hydrate(client(), {
|
|
200
|
-
// @ts-expect-error - hydrationData is not correctly typed internally
|
|
201
|
-
queries: [{ ...info.value.hydrationData }]
|
|
202
|
-
});
|
|
203
|
-
}
|
|
204
|
-
if (unsubscribe) return;
|
|
205
|
-
const newOptions = { ...initialOptions };
|
|
206
|
-
if ((initialOptions.staleTime || !initialOptions.initialData) && info.value) {
|
|
207
|
-
newOptions.refetchOnMount = false;
|
|
208
|
-
}
|
|
209
|
-
observer().setOptions(newOptions);
|
|
210
|
-
setStateWithReconciliation(observer().getOptimisticResult(newOptions));
|
|
211
|
-
unsubscribe = createClientSubscriber();
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
);
|
|
215
|
-
createComputed(
|
|
216
|
-
on(
|
|
217
|
-
client,
|
|
218
|
-
(c) => {
|
|
219
|
-
if (unsubscribe) {
|
|
220
|
-
unsubscribe();
|
|
221
|
-
}
|
|
222
|
-
const newObserver = new Observer(c, defaultedOptions());
|
|
223
|
-
unsubscribe = createClientSubscriber();
|
|
224
|
-
setObserver(newObserver);
|
|
225
|
-
},
|
|
226
|
-
{
|
|
227
|
-
defer: true
|
|
228
|
-
}
|
|
229
|
-
)
|
|
230
|
-
);
|
|
231
|
-
createComputed(
|
|
232
|
-
on(
|
|
233
|
-
isRestoring,
|
|
234
|
-
(restoring) => {
|
|
235
|
-
if (!restoring && !isServer) {
|
|
236
|
-
refetch();
|
|
237
|
-
}
|
|
238
|
-
},
|
|
239
|
-
{ defer: true }
|
|
240
|
-
)
|
|
241
|
-
);
|
|
242
|
-
onCleanup(() => {
|
|
243
|
-
if (isServer && queryResource.loading) {
|
|
244
|
-
unsubscribeQueued = true;
|
|
245
|
-
return;
|
|
246
|
-
}
|
|
247
|
-
if (unsubscribe) {
|
|
248
|
-
unsubscribe();
|
|
249
|
-
unsubscribe = null;
|
|
250
|
-
}
|
|
251
|
-
if (resolver && !isServer) {
|
|
252
|
-
resolver(observerResult);
|
|
253
|
-
resolver = null;
|
|
254
|
-
}
|
|
255
|
-
});
|
|
256
|
-
createComputed(
|
|
257
|
-
on(
|
|
258
|
-
[observer, defaultedOptions],
|
|
259
|
-
([obs, opts]) => {
|
|
260
|
-
obs.setOptions(opts);
|
|
261
|
-
setStateWithReconciliation(obs.getOptimisticResult(opts));
|
|
262
|
-
refetch();
|
|
263
|
-
},
|
|
264
|
-
{ defer: true }
|
|
265
|
-
)
|
|
266
|
-
);
|
|
267
|
-
const handler = {
|
|
268
|
-
get(target, prop) {
|
|
269
|
-
if (prop === "data") {
|
|
270
|
-
if (state.data !== void 0) {
|
|
271
|
-
return queryResource.latest?.data;
|
|
272
|
-
}
|
|
273
|
-
return queryResource()?.data;
|
|
274
|
-
}
|
|
275
|
-
return Reflect.get(target, prop);
|
|
276
|
-
}
|
|
277
|
-
};
|
|
278
|
-
return new Proxy(state, handler);
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
// src/useQuery.ts
|
|
282
|
-
function useQuery(options, queryClient) {
|
|
283
|
-
return useBaseQuery(
|
|
284
|
-
createMemo(() => options()),
|
|
285
|
-
QueryObserver,
|
|
286
|
-
queryClient
|
|
287
|
-
);
|
|
288
|
-
}
|
|
289
|
-
function useInfiniteQuery(options, queryClient) {
|
|
290
|
-
return useBaseQuery(
|
|
291
|
-
createMemo(() => options()),
|
|
292
|
-
InfiniteQueryObserver,
|
|
293
|
-
queryClient
|
|
294
|
-
);
|
|
295
|
-
}
|
|
296
|
-
function useMutation(options, queryClient) {
|
|
297
|
-
const client = createMemo(() => useQueryClient(queryClient?.()));
|
|
298
|
-
const observer = new MutationObserver(client(), options());
|
|
299
|
-
const mutate = (variables, mutateOptions) => {
|
|
300
|
-
observer.mutate(variables, mutateOptions).catch(noop);
|
|
301
|
-
};
|
|
302
|
-
const [state, setState] = createStore({
|
|
303
|
-
...observer.getCurrentResult(),
|
|
304
|
-
mutate,
|
|
305
|
-
mutateAsync: observer.getCurrentResult().mutate
|
|
306
|
-
});
|
|
307
|
-
createComputed(() => {
|
|
308
|
-
observer.setOptions(options());
|
|
309
|
-
});
|
|
310
|
-
createComputed(
|
|
311
|
-
on(
|
|
312
|
-
() => state.status,
|
|
313
|
-
() => {
|
|
314
|
-
if (state.isError && shouldThrowError(observer.options.throwOnError, [state.error])) {
|
|
315
|
-
throw state.error;
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
)
|
|
319
|
-
);
|
|
320
|
-
const unsubscribe = observer.subscribe((result) => {
|
|
321
|
-
setState({
|
|
322
|
-
...result,
|
|
323
|
-
mutate,
|
|
324
|
-
mutateAsync: result.mutate
|
|
325
|
-
});
|
|
326
|
-
});
|
|
327
|
-
onCleanup(unsubscribe);
|
|
328
|
-
return state;
|
|
329
|
-
}
|
|
330
|
-
function useQueries(queriesOptions, queryClient) {
|
|
331
|
-
const client = createMemo(() => useQueryClient(queryClient?.()));
|
|
332
|
-
const isRestoring = useIsRestoring();
|
|
333
|
-
const defaultedQueries = createMemo(
|
|
334
|
-
() => queriesOptions().queries.map(
|
|
335
|
-
(options) => mergeProps(
|
|
336
|
-
client().defaultQueryOptions(options),
|
|
337
|
-
{
|
|
338
|
-
get _optimisticResults() {
|
|
339
|
-
return isRestoring() ? "isRestoring" : "optimistic";
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
)
|
|
343
|
-
)
|
|
344
|
-
);
|
|
345
|
-
const observer = new QueriesObserver(
|
|
346
|
-
client(),
|
|
347
|
-
defaultedQueries(),
|
|
348
|
-
queriesOptions().combine ? {
|
|
349
|
-
combine: queriesOptions().combine
|
|
350
|
-
} : void 0
|
|
351
|
-
);
|
|
352
|
-
const [state, setState] = createStore(
|
|
353
|
-
observer.getOptimisticResult(
|
|
354
|
-
defaultedQueries(),
|
|
355
|
-
queriesOptions().combine
|
|
356
|
-
)[1]()
|
|
357
|
-
);
|
|
358
|
-
createRenderEffect(
|
|
359
|
-
on(
|
|
360
|
-
() => queriesOptions().queries.length,
|
|
361
|
-
() => setState(
|
|
362
|
-
observer.getOptimisticResult(
|
|
363
|
-
defaultedQueries(),
|
|
364
|
-
queriesOptions().combine
|
|
365
|
-
)[1]()
|
|
366
|
-
)
|
|
367
|
-
)
|
|
368
|
-
);
|
|
369
|
-
const dataResources = createMemo(
|
|
370
|
-
on(
|
|
371
|
-
() => state.length,
|
|
372
|
-
() => state.map((queryRes) => {
|
|
373
|
-
const dataPromise = () => new Promise((resolve) => {
|
|
374
|
-
if (queryRes.isFetching && queryRes.isLoading) return;
|
|
375
|
-
resolve(unwrap(queryRes.data));
|
|
376
|
-
});
|
|
377
|
-
return createResource(dataPromise);
|
|
378
|
-
})
|
|
379
|
-
)
|
|
380
|
-
);
|
|
381
|
-
batch(() => {
|
|
382
|
-
const dataResources_ = dataResources();
|
|
383
|
-
for (let index = 0; index < dataResources_.length; index++) {
|
|
384
|
-
const dataResource = dataResources_[index];
|
|
385
|
-
dataResource[1].mutate(() => unwrap(state[index].data));
|
|
386
|
-
dataResource[1].refetch();
|
|
387
|
-
}
|
|
388
|
-
});
|
|
389
|
-
let taskQueue = [];
|
|
390
|
-
const subscribeToObserver = () => observer.subscribe((result) => {
|
|
391
|
-
taskQueue.push(() => {
|
|
392
|
-
batch(() => {
|
|
393
|
-
const dataResources_ = dataResources();
|
|
394
|
-
for (let index = 0; index < dataResources_.length; index++) {
|
|
395
|
-
const dataResource = dataResources_[index];
|
|
396
|
-
const unwrappedResult = { ...unwrap(result[index]) };
|
|
397
|
-
setState(index, unwrap(unwrappedResult));
|
|
398
|
-
dataResource[1].mutate(() => unwrap(state[index].data));
|
|
399
|
-
dataResource[1].refetch();
|
|
400
|
-
}
|
|
401
|
-
});
|
|
402
|
-
});
|
|
403
|
-
queueMicrotask(() => {
|
|
404
|
-
const taskToRun = taskQueue.pop();
|
|
405
|
-
if (taskToRun) taskToRun();
|
|
406
|
-
taskQueue = [];
|
|
407
|
-
});
|
|
408
|
-
});
|
|
409
|
-
let unsubscribe = noop;
|
|
410
|
-
createComputed((cleanup) => {
|
|
411
|
-
cleanup?.();
|
|
412
|
-
unsubscribe = isRestoring() ? noop : subscribeToObserver();
|
|
413
|
-
return () => queueMicrotask(unsubscribe);
|
|
414
|
-
});
|
|
415
|
-
onCleanup(unsubscribe);
|
|
416
|
-
onMount(() => {
|
|
417
|
-
observer.setQueries(
|
|
418
|
-
defaultedQueries(),
|
|
419
|
-
queriesOptions().combine ? {
|
|
420
|
-
combine: queriesOptions().combine
|
|
421
|
-
} : void 0
|
|
422
|
-
);
|
|
423
|
-
});
|
|
424
|
-
createComputed(() => {
|
|
425
|
-
observer.setQueries(
|
|
426
|
-
defaultedQueries(),
|
|
427
|
-
queriesOptions().combine ? {
|
|
428
|
-
combine: queriesOptions().combine
|
|
429
|
-
} : void 0
|
|
430
|
-
);
|
|
431
|
-
});
|
|
432
|
-
const handler = (index) => ({
|
|
433
|
-
get(target, prop) {
|
|
434
|
-
if (prop === "data") {
|
|
435
|
-
return dataResources()[index][0]();
|
|
436
|
-
}
|
|
437
|
-
return Reflect.get(target, prop);
|
|
438
|
-
}
|
|
439
|
-
});
|
|
440
|
-
const getProxies = () => state.map((s, index) => {
|
|
441
|
-
return new Proxy(s, handler(index));
|
|
442
|
-
});
|
|
443
|
-
const [proxyState, setProxyState] = createStore(getProxies());
|
|
444
|
-
createRenderEffect(() => setProxyState(getProxies()));
|
|
445
|
-
return proxyState;
|
|
446
|
-
}
|
|
447
|
-
var QueryClient = class extends QueryClient$1 {
|
|
448
|
-
constructor(config = {}) {
|
|
449
|
-
super(config);
|
|
450
|
-
}
|
|
451
|
-
};
|
|
452
|
-
|
|
453
|
-
// src/queryOptions.ts
|
|
454
|
-
function queryOptions(options) {
|
|
455
|
-
return options;
|
|
456
|
-
}
|
|
457
|
-
function useIsFetching(filters, queryClient) {
|
|
458
|
-
const client = createMemo(() => useQueryClient(queryClient?.()));
|
|
459
|
-
const queryCache = createMemo(() => client().getQueryCache());
|
|
460
|
-
const [fetches, setFetches] = createSignal(client().isFetching(filters?.()));
|
|
461
|
-
const unsubscribe = queryCache().subscribe(() => {
|
|
462
|
-
setFetches(client().isFetching(filters?.()));
|
|
463
|
-
});
|
|
464
|
-
onCleanup(unsubscribe);
|
|
465
|
-
return fetches;
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
// src/infiniteQueryOptions.ts
|
|
469
|
-
function infiniteQueryOptions(options) {
|
|
470
|
-
return options;
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
// src/mutationOptions.ts
|
|
474
|
-
function mutationOptions(options) {
|
|
475
|
-
return options;
|
|
476
|
-
}
|
|
477
|
-
function useIsMutating(filters, queryClient) {
|
|
478
|
-
const client = createMemo(() => useQueryClient(queryClient?.()));
|
|
479
|
-
const mutationCache = createMemo(() => client().getMutationCache());
|
|
480
|
-
const [mutations, setMutations] = createSignal(
|
|
481
|
-
client().isMutating(filters?.())
|
|
482
|
-
);
|
|
483
|
-
const unsubscribe = mutationCache().subscribe((_result) => {
|
|
484
|
-
setMutations(client().isMutating(filters?.()));
|
|
485
|
-
});
|
|
486
|
-
onCleanup(unsubscribe);
|
|
487
|
-
return mutations;
|
|
488
|
-
}
|
|
489
|
-
function getResult(mutationCache, options) {
|
|
490
|
-
return mutationCache.findAll(options.filters).map(
|
|
491
|
-
(mutation) => options.select ? options.select(mutation) : mutation.state
|
|
492
|
-
);
|
|
493
|
-
}
|
|
494
|
-
function useMutationState(options = () => ({}), queryClient) {
|
|
495
|
-
const client = createMemo(() => useQueryClient(queryClient?.()));
|
|
496
|
-
const mutationCache = createMemo(() => client().getMutationCache());
|
|
497
|
-
const [result, setResult] = createSignal(
|
|
498
|
-
getResult(mutationCache(), options())
|
|
499
|
-
);
|
|
500
|
-
createEffect(() => {
|
|
501
|
-
const unsubscribe = mutationCache().subscribe(() => {
|
|
502
|
-
const nextResult = replaceEqualDeep(
|
|
503
|
-
result(),
|
|
504
|
-
getResult(mutationCache(), options())
|
|
505
|
-
);
|
|
506
|
-
if (result() !== nextResult) {
|
|
507
|
-
setResult(nextResult);
|
|
508
|
-
}
|
|
509
|
-
});
|
|
510
|
-
onCleanup(unsubscribe);
|
|
511
|
-
});
|
|
512
|
-
return result;
|
|
513
|
-
}
|
|
514
|
-
|
|
515
|
-
// src/index.ts
|
|
516
|
-
var createQuery = useQuery;
|
|
517
|
-
var createInfiniteQuery = useInfiniteQuery;
|
|
518
|
-
var createMutation = useMutation;
|
|
519
|
-
var createQueries = useQueries;
|
|
520
|
-
|
|
521
|
-
export { IsRestoringProvider, QueryClient, QueryClientContext, QueryClientProvider, createInfiniteQuery, useIsFetching as createIsFetching, useIsMutating as createIsMutating, createMutation, useMutationState as createMutationState, createQueries, createQuery, infiniteQueryOptions, mutationOptions, queryOptions, useInfiniteQuery, useIsFetching, useIsMutating, useIsRestoring, useMutation, useMutationState, useQueries, useQuery, useQueryClient };
|