@tanstack/solid-query 5.94.5 → 6.0.0-alpha.1
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/_tsup-dts-rollup.d.cts +17 -8
- package/build/_tsup-dts-rollup.d.ts +17 -8
- package/build/dev.cjs +161 -258
- package/build/dev.d.cts +1 -1
- package/build/dev.d.ts +1 -1
- package/build/dev.js +155 -252
- package/build/index.cjs +161 -258
- package/build/index.d.cts +1 -1
- package/build/index.d.ts +1 -1
- package/build/index.js +155 -252
- package/package.json +9 -5
- package/src/QueryClientProvider.tsx +7 -16
- package/src/index.ts +1 -1
- package/src/isRestoring.ts +1 -2
- package/src/useBaseQuery.ts +154 -160
- package/src/useMutation.ts +32 -22
- package/src/useMutationState.ts +7 -9
- package/src/useQueries.ts +50 -116
package/build/index.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { MutationObserver, shouldThrowError, QueriesObserver,
|
|
1
|
+
import { MutationObserver, shouldThrowError, QueriesObserver, QueryClient as QueryClient$1, replaceEqualDeep, noop, notifyManager, QueryObserver, InfiniteQueryObserver } from '@tanstack/query-core';
|
|
2
2
|
export * from '@tanstack/query-core';
|
|
3
|
-
import { createContext, useContext,
|
|
4
|
-
import { createComponent
|
|
5
|
-
import { createStore, unwrap, reconcile } from 'solid-js/store';
|
|
3
|
+
import { createContext, useContext, onCleanup, createMemo, createStore, createRenderEffect, merge, createEffect, reconcile, createSignal, isPending, refresh, snapshot } from 'solid-js';
|
|
4
|
+
import { createComponent } from '@solidjs/web';
|
|
6
5
|
|
|
7
6
|
// src/useQuery.ts
|
|
8
|
-
var QueryClientContext = createContext(
|
|
7
|
+
var QueryClientContext = createContext(null);
|
|
9
8
|
var useQueryClient = (queryClient) => {
|
|
10
9
|
if (queryClient) {
|
|
11
10
|
return queryClient;
|
|
@@ -17,13 +16,9 @@ var useQueryClient = (queryClient) => {
|
|
|
17
16
|
return client();
|
|
18
17
|
};
|
|
19
18
|
var QueryClientProvider = (props) => {
|
|
20
|
-
|
|
21
|
-
unmount?.();
|
|
22
|
-
props.client.mount();
|
|
23
|
-
return props.client.unmount.bind(props.client);
|
|
24
|
-
});
|
|
19
|
+
props.client.mount();
|
|
25
20
|
onCleanup(() => props.client.unmount());
|
|
26
|
-
return createComponent(QueryClientContext
|
|
21
|
+
return createComponent(QueryClientContext, {
|
|
27
22
|
value: () => props.client,
|
|
28
23
|
get children() {
|
|
29
24
|
return props.children;
|
|
@@ -32,15 +27,28 @@ var QueryClientProvider = (props) => {
|
|
|
32
27
|
};
|
|
33
28
|
var IsRestoringContext = createContext(() => false);
|
|
34
29
|
var useIsRestoring = () => useContext(IsRestoringContext);
|
|
35
|
-
var IsRestoringProvider = IsRestoringContext.Provider;
|
|
36
30
|
|
|
37
31
|
// src/useBaseQuery.ts
|
|
32
|
+
var isServer = typeof window === "undefined";
|
|
33
|
+
function _stripFnsForSSR(obj) {
|
|
34
|
+
if (!isServer) return obj;
|
|
35
|
+
const out = {};
|
|
36
|
+
for (const k of Object.keys(obj)) {
|
|
37
|
+
if (k === "refetch" || k === "fetchNextPage" || k === "fetchPreviousPage") {
|
|
38
|
+
out[k] = void 0;
|
|
39
|
+
} else {
|
|
40
|
+
out[k] = obj[k];
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return out;
|
|
44
|
+
}
|
|
38
45
|
function reconcileFn(store, result, reconcileOption, queryHash) {
|
|
39
|
-
if (reconcileOption === false) return result;
|
|
40
46
|
if (typeof reconcileOption === "function") {
|
|
41
|
-
const
|
|
42
|
-
return { ...result, data:
|
|
47
|
+
const newData = reconcileOption(store.data, result.data);
|
|
48
|
+
return { ...result, data: newData };
|
|
43
49
|
}
|
|
50
|
+
if (reconcileOption === false) return result;
|
|
51
|
+
const key = reconcileOption;
|
|
44
52
|
let data = result.data;
|
|
45
53
|
if (store.data === void 0) {
|
|
46
54
|
try {
|
|
@@ -48,13 +56,16 @@ function reconcileFn(store, result, reconcileOption, queryHash) {
|
|
|
48
56
|
} catch (error) {
|
|
49
57
|
}
|
|
50
58
|
}
|
|
51
|
-
|
|
52
|
-
|
|
59
|
+
if (store.data !== void 0 && data !== void 0) {
|
|
60
|
+
reconcile(data, key)(store.data);
|
|
61
|
+
return { ...result, data: store.data };
|
|
62
|
+
}
|
|
63
|
+
return { ...result, data };
|
|
53
64
|
}
|
|
54
65
|
var hydratableObserverResult = (query, result) => {
|
|
55
66
|
if (!isServer) return result;
|
|
56
67
|
const obj = {
|
|
57
|
-
...
|
|
68
|
+
...snapshot(result),
|
|
58
69
|
// During SSR, functions cannot be serialized, so we need to remove them
|
|
59
70
|
// This is safe because we will add these functions back when the query is hydrated
|
|
60
71
|
refetch: void 0
|
|
@@ -86,16 +97,22 @@ function useBaseQuery(options, Observer, queryClient) {
|
|
|
86
97
|
}
|
|
87
98
|
return defaultOptions;
|
|
88
99
|
});
|
|
89
|
-
const
|
|
90
|
-
const
|
|
91
|
-
|
|
100
|
+
const observer = new Observer(client(), defaultedOptions());
|
|
101
|
+
const trackedDefaultedOptions = createMemo(() => defaultedOptions());
|
|
102
|
+
createRenderEffect(
|
|
103
|
+
() => trackedDefaultedOptions(),
|
|
104
|
+
(opts) => {
|
|
105
|
+
observer.setOptions(opts);
|
|
106
|
+
}
|
|
107
|
+
);
|
|
108
|
+
let observerResult = observer.getOptimisticResult(defaultedOptions());
|
|
109
|
+
const [state, setState] = createStore(
|
|
110
|
+
_stripFnsForSSR(observerResult)
|
|
92
111
|
);
|
|
93
|
-
let observerResult = observer().getOptimisticResult(defaultedOptions());
|
|
94
|
-
const [state, setState] = createStore(observerResult);
|
|
95
112
|
const createServerSubscriber = (resolve, reject) => {
|
|
96
|
-
return observer
|
|
113
|
+
return observer.subscribe((result) => {
|
|
97
114
|
notifyManager.batchCalls(() => {
|
|
98
|
-
const query = observer
|
|
115
|
+
const query = observer.getCurrentQuery();
|
|
99
116
|
const unwrappedResult = hydratableObserverResult(query, result);
|
|
100
117
|
if (result.data !== void 0 && unwrappedResult.isError) {
|
|
101
118
|
reject(unwrappedResult.error);
|
|
@@ -114,133 +131,74 @@ function useBaseQuery(options, Observer, queryClient) {
|
|
|
114
131
|
}
|
|
115
132
|
};
|
|
116
133
|
const createClientSubscriber = () => {
|
|
117
|
-
|
|
118
|
-
|
|
134
|
+
return observer.subscribe((result) => {
|
|
135
|
+
const previousResult = observerResult;
|
|
119
136
|
observerResult = result;
|
|
137
|
+
setStateWithReconciliation(result);
|
|
120
138
|
queueMicrotask(() => {
|
|
121
|
-
if (unsubscribe) {
|
|
122
|
-
|
|
139
|
+
if (unsubscribe && !disposed && (previousResult.isLoading !== result.isLoading || previousResult.isError !== result.isError)) {
|
|
140
|
+
try {
|
|
141
|
+
refresh(queryResource);
|
|
142
|
+
} catch {
|
|
143
|
+
}
|
|
123
144
|
}
|
|
124
145
|
});
|
|
125
146
|
});
|
|
126
147
|
};
|
|
127
148
|
function setStateWithReconciliation(res) {
|
|
128
|
-
const opts = observer
|
|
149
|
+
const opts = observer.options;
|
|
129
150
|
const reconcileOptions = opts.reconcile;
|
|
151
|
+
const sanitized = _stripFnsForSSR(res);
|
|
130
152
|
setState((store) => {
|
|
131
153
|
return reconcileFn(
|
|
132
154
|
store,
|
|
133
|
-
|
|
155
|
+
sanitized,
|
|
134
156
|
reconcileOptions === void 0 ? false : reconcileOptions,
|
|
135
157
|
opts.queryHash
|
|
136
158
|
);
|
|
137
159
|
});
|
|
138
160
|
}
|
|
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
161
|
let unsubscribe = null;
|
|
162
|
+
let disposed = false;
|
|
156
163
|
let resolver = null;
|
|
157
|
-
const
|
|
164
|
+
const queryResource = createMemo(
|
|
158
165
|
() => {
|
|
159
|
-
const
|
|
166
|
+
const opts = trackedDefaultedOptions();
|
|
167
|
+
const restoring = isRestoring();
|
|
160
168
|
return new Promise((resolve, reject) => {
|
|
161
169
|
resolver = resolve;
|
|
162
170
|
if (isServer) {
|
|
163
|
-
unsubscribe = createServerSubscriber(
|
|
164
|
-
|
|
171
|
+
unsubscribe = createServerSubscriber((data) => {
|
|
172
|
+
resolve(data);
|
|
173
|
+
}, reject);
|
|
174
|
+
} else if (!unsubscribe && !restoring) {
|
|
165
175
|
unsubscribe = createClientSubscriber();
|
|
166
176
|
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
177
|
+
const currentResult = observer.getOptimisticResult(opts);
|
|
178
|
+
observerResult = currentResult;
|
|
179
|
+
if (currentResult.isError && !currentResult.isFetching && !restoring && shouldThrowError(opts.throwOnError, [
|
|
180
|
+
currentResult.error,
|
|
181
|
+
observer.getCurrentQuery()
|
|
171
182
|
])) {
|
|
172
|
-
setStateWithReconciliation(
|
|
173
|
-
return reject(
|
|
183
|
+
setStateWithReconciliation(currentResult);
|
|
184
|
+
return reject(currentResult.error);
|
|
174
185
|
}
|
|
175
|
-
if (!
|
|
186
|
+
if (!currentResult.isLoading) {
|
|
176
187
|
resolver = null;
|
|
188
|
+
setStateWithReconciliation(currentResult);
|
|
177
189
|
return resolve(
|
|
178
|
-
hydratableObserverResult(
|
|
190
|
+
hydratableObserverResult(observer.getCurrentQuery(), currentResult)
|
|
179
191
|
);
|
|
180
192
|
}
|
|
181
|
-
setStateWithReconciliation(
|
|
193
|
+
queueMicrotask(() => setStateWithReconciliation(currentResult));
|
|
182
194
|
});
|
|
183
195
|
},
|
|
184
|
-
|
|
185
|
-
|
|
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
|
-
)
|
|
196
|
+
observerResult,
|
|
197
|
+
{ ssrSource: "client" }
|
|
241
198
|
);
|
|
242
199
|
onCleanup(() => {
|
|
243
|
-
|
|
200
|
+
disposed = true;
|
|
201
|
+
if (isServer && isPending(queryResource)) {
|
|
244
202
|
unsubscribeQueued = true;
|
|
245
203
|
return;
|
|
246
204
|
}
|
|
@@ -253,29 +211,31 @@ function useBaseQuery(options, Observer, queryClient) {
|
|
|
253
211
|
resolver = null;
|
|
254
212
|
}
|
|
255
213
|
});
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
)
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
if (prop
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
214
|
+
const errorPassthroughProps = /* @__PURE__ */ new Set([
|
|
215
|
+
"error",
|
|
216
|
+
"isError",
|
|
217
|
+
"failureCount",
|
|
218
|
+
"failureReason",
|
|
219
|
+
"errorUpdateCount",
|
|
220
|
+
"errorUpdatedAt"
|
|
221
|
+
]);
|
|
222
|
+
return new Proxy(state, {
|
|
223
|
+
get(target, prop, receiver) {
|
|
224
|
+
if (typeof prop === "symbol") {
|
|
225
|
+
return Reflect.get(target, prop, receiver);
|
|
226
|
+
}
|
|
227
|
+
if (errorPassthroughProps.has(prop)) {
|
|
228
|
+
return Reflect.get(target, prop, receiver);
|
|
229
|
+
}
|
|
230
|
+
if (state.isError && !state.isFetching && shouldThrowError(observer.options.throwOnError, [
|
|
231
|
+
state.error,
|
|
232
|
+
observer.getCurrentQuery()
|
|
233
|
+
])) {
|
|
234
|
+
throw state.error;
|
|
274
235
|
}
|
|
275
|
-
return Reflect.get(target, prop);
|
|
236
|
+
return Reflect.get(target, prop, receiver);
|
|
276
237
|
}
|
|
277
|
-
};
|
|
278
|
-
return new Proxy(state, handler);
|
|
238
|
+
});
|
|
279
239
|
}
|
|
280
240
|
|
|
281
241
|
// src/useQuery.ts
|
|
@@ -296,6 +256,9 @@ function useInfiniteQuery(options, queryClient) {
|
|
|
296
256
|
function useMutation(options, queryClient) {
|
|
297
257
|
const client = createMemo(() => useQueryClient(queryClient?.()));
|
|
298
258
|
const observer = new MutationObserver(client(), options());
|
|
259
|
+
createMemo(() => {
|
|
260
|
+
observer.setOptions(options());
|
|
261
|
+
});
|
|
299
262
|
const mutate = (variables, mutateOptions) => {
|
|
300
263
|
observer.mutate(variables, mutateOptions).catch(noop);
|
|
301
264
|
};
|
|
@@ -304,27 +267,25 @@ function useMutation(options, queryClient) {
|
|
|
304
267
|
mutate,
|
|
305
268
|
mutateAsync: observer.getCurrentResult().mutate
|
|
306
269
|
});
|
|
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
270
|
const unsubscribe = observer.subscribe((result) => {
|
|
321
|
-
setState({
|
|
271
|
+
setState(() => ({
|
|
322
272
|
...result,
|
|
323
273
|
mutate,
|
|
324
274
|
mutateAsync: result.mutate
|
|
325
|
-
});
|
|
275
|
+
}));
|
|
326
276
|
});
|
|
327
277
|
onCleanup(unsubscribe);
|
|
278
|
+
createRenderEffect(
|
|
279
|
+
() => {
|
|
280
|
+
const isError = state.isError;
|
|
281
|
+
const error = state.error;
|
|
282
|
+
if (isError && shouldThrowError(observer.options.throwOnError, [error])) {
|
|
283
|
+
throw error;
|
|
284
|
+
}
|
|
285
|
+
},
|
|
286
|
+
() => {
|
|
287
|
+
}
|
|
288
|
+
);
|
|
328
289
|
return state;
|
|
329
290
|
}
|
|
330
291
|
function useQueries(queriesOptions, queryClient) {
|
|
@@ -332,14 +293,11 @@ function useQueries(queriesOptions, queryClient) {
|
|
|
332
293
|
const isRestoring = useIsRestoring();
|
|
333
294
|
const defaultedQueries = createMemo(
|
|
334
295
|
() => queriesOptions().queries.map(
|
|
335
|
-
(options) =>
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
get _optimisticResults() {
|
|
339
|
-
return isRestoring() ? "isRestoring" : "optimistic";
|
|
340
|
-
}
|
|
296
|
+
(options) => merge(client().defaultQueryOptions(options), {
|
|
297
|
+
get _optimisticResults() {
|
|
298
|
+
return isRestoring() ? "isRestoring" : "optimistic";
|
|
341
299
|
}
|
|
342
|
-
)
|
|
300
|
+
})
|
|
343
301
|
)
|
|
344
302
|
);
|
|
345
303
|
const observer = new QueriesObserver(
|
|
@@ -349,100 +307,47 @@ function useQueries(queriesOptions, queryClient) {
|
|
|
349
307
|
combine: queriesOptions().combine
|
|
350
308
|
} : void 0
|
|
351
309
|
);
|
|
352
|
-
const [
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
queriesOptions().combine
|
|
356
|
-
)[1]()
|
|
310
|
+
const [, getCombinedResult] = observer.getOptimisticResult(
|
|
311
|
+
defaultedQueries(),
|
|
312
|
+
queriesOptions().combine
|
|
357
313
|
);
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
() => setState(
|
|
362
|
-
observer.getOptimisticResult(
|
|
363
|
-
defaultedQueries(),
|
|
364
|
-
queriesOptions().combine
|
|
365
|
-
)[1]()
|
|
366
|
-
)
|
|
367
|
-
)
|
|
314
|
+
const initialResult = getCombinedResult();
|
|
315
|
+
const [state, setState] = createStore(
|
|
316
|
+
Array.isArray(initialResult) ? initialResult : [initialResult]
|
|
368
317
|
);
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
318
|
+
let unsubscribe = noop;
|
|
319
|
+
createEffect(
|
|
320
|
+
() => {
|
|
321
|
+
if (!isRestoring()) {
|
|
322
|
+
unsubscribe = observer.subscribe((result) => {
|
|
323
|
+
setState(
|
|
324
|
+
reconcile(
|
|
325
|
+
[...result],
|
|
326
|
+
// Use a key function that returns undefined so reconcile
|
|
327
|
+
// uses positional matching and recursively updates nested properties
|
|
328
|
+
() => void 0
|
|
329
|
+
)
|
|
330
|
+
);
|
|
376
331
|
});
|
|
377
|
-
|
|
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();
|
|
332
|
+
}
|
|
333
|
+
},
|
|
334
|
+
() => {
|
|
387
335
|
}
|
|
336
|
+
);
|
|
337
|
+
onCleanup(() => {
|
|
338
|
+
unsubscribe();
|
|
388
339
|
});
|
|
389
|
-
|
|
390
|
-
|
|
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(() => {
|
|
340
|
+
createMemo(() => {
|
|
341
|
+
const queries = defaultedQueries();
|
|
425
342
|
observer.setQueries(
|
|
426
|
-
|
|
343
|
+
queries,
|
|
427
344
|
queriesOptions().combine ? {
|
|
428
345
|
combine: queriesOptions().combine
|
|
429
346
|
} : void 0
|
|
430
347
|
);
|
|
348
|
+
return queries;
|
|
431
349
|
});
|
|
432
|
-
|
|
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;
|
|
350
|
+
return state;
|
|
446
351
|
}
|
|
447
352
|
var QueryClient = class extends QueryClient$1 {
|
|
448
353
|
constructor(config = {}) {
|
|
@@ -497,18 +402,16 @@ function useMutationState(options = () => ({}), queryClient) {
|
|
|
497
402
|
const [result, setResult] = createSignal(
|
|
498
403
|
getResult(mutationCache(), options())
|
|
499
404
|
);
|
|
500
|
-
|
|
501
|
-
|
|
405
|
+
const unsubscribe = mutationCache().subscribe(() => {
|
|
406
|
+
setResult((prev) => {
|
|
502
407
|
const nextResult = replaceEqualDeep(
|
|
503
|
-
|
|
408
|
+
prev,
|
|
504
409
|
getResult(mutationCache(), options())
|
|
505
410
|
);
|
|
506
|
-
|
|
507
|
-
setResult(nextResult);
|
|
508
|
-
}
|
|
411
|
+
return prev === nextResult ? prev : nextResult;
|
|
509
412
|
});
|
|
510
|
-
onCleanup(unsubscribe);
|
|
511
413
|
});
|
|
414
|
+
onCleanup(unsubscribe);
|
|
512
415
|
return result;
|
|
513
416
|
}
|
|
514
417
|
|
|
@@ -518,4 +421,4 @@ var createInfiniteQuery = useInfiniteQuery;
|
|
|
518
421
|
var createMutation = useMutation;
|
|
519
422
|
var createQueries = useQueries;
|
|
520
423
|
|
|
521
|
-
export {
|
|
424
|
+
export { IsRestoringContext, 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 };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/solid-query",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.0-alpha.1",
|
|
4
4
|
"description": "Primitives for managing, caching and syncing asynchronous and remote data in Solid",
|
|
5
5
|
"author": "tannerlinsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -46,18 +46,22 @@
|
|
|
46
46
|
"!src/__tests__"
|
|
47
47
|
],
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@tanstack/query-core": "5.
|
|
49
|
+
"@tanstack/query-core": "5.91.2"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
|
+
"@babel/core": "^7.28.0",
|
|
53
|
+
"@babel/preset-typescript": "^7.18.6",
|
|
52
54
|
"@solidjs/testing-library": "^0.8.10",
|
|
55
|
+
"@solidjs/web": "2.0.0-beta.4",
|
|
56
|
+
"babel-preset-solid": "2.0.0-beta.4",
|
|
53
57
|
"npm-run-all2": "^5.0.0",
|
|
54
|
-
"solid-js": "
|
|
58
|
+
"solid-js": "2.0.0-beta.4",
|
|
55
59
|
"tsup-preset-solid": "^2.2.0",
|
|
56
|
-
"vite-plugin-solid": "
|
|
60
|
+
"vite-plugin-solid": "3.0.0-next.2",
|
|
57
61
|
"@tanstack/query-test-utils": "0.0.0"
|
|
58
62
|
},
|
|
59
63
|
"peerDependencies": {
|
|
60
|
-
"solid-js": "
|
|
64
|
+
"solid-js": ">=2.0.0-beta.0 <3.0.0"
|
|
61
65
|
},
|
|
62
66
|
"scripts": {
|
|
63
67
|
"clean": "premove ./build ./coverage ./dist-ts",
|
|
@@ -1,15 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createContext,
|
|
3
|
-
createRenderEffect,
|
|
4
|
-
onCleanup,
|
|
5
|
-
useContext,
|
|
6
|
-
} from 'solid-js'
|
|
1
|
+
import { createContext, onCleanup, useContext } from 'solid-js'
|
|
7
2
|
import type { QueryClient } from './QueryClient'
|
|
8
3
|
import type { JSX } from 'solid-js'
|
|
9
4
|
|
|
10
|
-
export const QueryClientContext = createContext<
|
|
11
|
-
|
|
12
|
-
|
|
5
|
+
export const QueryClientContext = createContext<(() => QueryClient) | null>(
|
|
6
|
+
null,
|
|
7
|
+
)
|
|
13
8
|
|
|
14
9
|
export const useQueryClient = (queryClient?: QueryClient) => {
|
|
15
10
|
if (queryClient) {
|
|
@@ -32,16 +27,12 @@ export type QueryClientProviderProps = {
|
|
|
32
27
|
export const QueryClientProvider = (
|
|
33
28
|
props: QueryClientProviderProps,
|
|
34
29
|
): JSX.Element => {
|
|
35
|
-
|
|
36
|
-
unmount?.()
|
|
37
|
-
props.client.mount()
|
|
38
|
-
return props.client.unmount.bind(props.client)
|
|
39
|
-
})
|
|
30
|
+
props.client.mount()
|
|
40
31
|
onCleanup(() => props.client.unmount())
|
|
41
32
|
|
|
42
33
|
return (
|
|
43
|
-
<QueryClientContext
|
|
34
|
+
<QueryClientContext value={() => props.client}>
|
|
44
35
|
{props.children}
|
|
45
|
-
</QueryClientContext
|
|
36
|
+
</QueryClientContext>
|
|
46
37
|
)
|
|
47
38
|
}
|
package/src/index.ts
CHANGED
|
@@ -84,4 +84,4 @@ export { useMutationState } from './useMutationState'
|
|
|
84
84
|
export { useMutationState as createMutationState } from './useMutationState'
|
|
85
85
|
export { useQueries } from './useQueries'
|
|
86
86
|
export const createQueries = useQueries
|
|
87
|
-
export { useIsRestoring,
|
|
87
|
+
export { useIsRestoring, IsRestoringContext } from './isRestoring'
|
package/src/isRestoring.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { createContext, useContext } from 'solid-js'
|
|
2
2
|
import type { Accessor } from 'solid-js'
|
|
3
3
|
|
|
4
|
-
const IsRestoringContext = createContext<Accessor<boolean>>(() => false)
|
|
4
|
+
export const IsRestoringContext = createContext<Accessor<boolean>>(() => false)
|
|
5
5
|
|
|
6
6
|
export const useIsRestoring = () => useContext(IsRestoringContext)
|
|
7
|
-
export const IsRestoringProvider = IsRestoringContext.Provider
|