@tanstack/svelte-query 5.0.0-alpha.76 → 5.0.0-alpha.78

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.
@@ -1 +1 @@
1
- {"version":3,"file":"createBaseQuery.d.ts","sourceRoot":"","sources":["../../src/createBaseQuery.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AAChF,OAAO,KAAK,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAA;AAI5E,wBAAgB,eAAe,CAC7B,YAAY,EACZ,MAAM,EACN,KAAK,EACL,UAAU,EACV,SAAS,SAAS,QAAQ,EAE1B,OAAO,EAAE,sBAAsB,CAC7B,YAAY,EACZ,MAAM,EACN,KAAK,EACL,UAAU,EACV,SAAS,CACV,EACD,QAAQ,EAAE,OAAO,aAAa,EAC9B,WAAW,CAAC,EAAE,WAAW,GACxB,qBAAqB,CAAC,KAAK,EAAE,MAAM,CAAC,CAsCtC"}
1
+ {"version":3,"file":"createBaseQuery.d.ts","sourceRoot":"","sources":["../../src/createBaseQuery.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AAChF,OAAO,KAAK,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAA;AAI5E,wBAAgB,eAAe,CAC7B,YAAY,EACZ,MAAM,EACN,KAAK,EACL,UAAU,EACV,SAAS,SAAS,QAAQ,EAE1B,OAAO,EAAE,sBAAsB,CAC7B,YAAY,EACZ,MAAM,EACN,KAAK,EACL,UAAU,EACV,SAAS,CACV,EACD,QAAQ,EAAE,OAAO,aAAa,EAC9B,WAAW,CAAC,EAAE,WAAW,GACxB,qBAAqB,CAAC,KAAK,EAAE,MAAM,CAAC,CA6CtC"}
@@ -3,13 +3,17 @@ import { notifyManager } from '@tanstack/query-core';
3
3
  import { useQueryClient } from './useQueryClient';
4
4
  import { isSvelteStore } from './utils';
5
5
  export function createBaseQuery(options, Observer, queryClient) {
6
+ /** Load query client */
6
7
  const client = useQueryClient(queryClient);
8
+ /** Converts options to a svelte store if not already a store object */
7
9
  const optionsStore = isSvelteStore(options) ? options : readable(options);
8
- const defaultedOptionsStore = derived(optionsStore, ($options) => {
9
- const defaultedOptions = client.defaultQueryOptions($options);
10
+ /** Creates a store that has the default options applied */
11
+ const defaultedOptionsStore = derived(optionsStore, ($optionsStore) => {
12
+ const defaultedOptions = client.defaultQueryOptions($optionsStore);
10
13
  defaultedOptions._optimisticResults = 'optimistic';
11
14
  return defaultedOptions;
12
15
  });
16
+ /** Creates the observer */
13
17
  const observer = new Observer(client, get(defaultedOptionsStore));
14
18
  defaultedOptionsStore.subscribe(($defaultedOptions) => {
15
19
  // Do not notify on updates because of changes in the options because
@@ -19,9 +23,10 @@ export function createBaseQuery(options, Observer, queryClient) {
19
23
  const result = readable(observer.getCurrentResult(), (set) => {
20
24
  return observer.subscribe(notifyManager.batchCalls(set));
21
25
  });
22
- const { subscribe } = derived(result, ($result) => {
23
- $result = observer.getOptimisticResult(get(defaultedOptionsStore));
24
- return !get(defaultedOptionsStore).notifyOnChangeProps
26
+ /** Subscribe to changes in result and defaultedOptionsStore */
27
+ const { subscribe } = derived([result, defaultedOptionsStore], ([$result, $defaultedOptionsStore]) => {
28
+ $result = observer.getOptimisticResult($defaultedOptionsStore);
29
+ return !$defaultedOptionsStore.notifyOnChangeProps
25
30
  ? observer.trackResult($result)
26
31
  : $result;
27
32
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/svelte-query",
3
- "version": "5.0.0-alpha.76",
3
+ "version": "5.0.0-alpha.78",
4
4
  "description": "Primitives for managing, caching and syncing asynchronous and remote data in Svelte",
5
5
  "author": "Lachlan Collins",
6
6
  "license": "MIT",
@@ -22,17 +22,20 @@ export function createBaseQuery<
22
22
  Observer: typeof QueryObserver,
23
23
  queryClient?: QueryClient,
24
24
  ): CreateBaseQueryResult<TData, TError> {
25
+ /** Load query client */
25
26
  const client = useQueryClient(queryClient)
26
27
 
28
+ /** Converts options to a svelte store if not already a store object */
27
29
  const optionsStore = isSvelteStore(options) ? options : readable(options)
28
30
 
29
- const defaultedOptionsStore = derived(optionsStore, ($options) => {
30
- const defaultedOptions = client.defaultQueryOptions($options)
31
+ /** Creates a store that has the default options applied */
32
+ const defaultedOptionsStore = derived(optionsStore, ($optionsStore) => {
33
+ const defaultedOptions = client.defaultQueryOptions($optionsStore)
31
34
  defaultedOptions._optimisticResults = 'optimistic'
32
-
33
35
  return defaultedOptions
34
36
  })
35
37
 
38
+ /** Creates the observer */
36
39
  const observer = new Observer<
37
40
  TQueryFnData,
38
41
  TError,
@@ -51,12 +54,16 @@ export function createBaseQuery<
51
54
  return observer.subscribe(notifyManager.batchCalls(set))
52
55
  })
53
56
 
54
- const { subscribe } = derived(result, ($result) => {
55
- $result = observer.getOptimisticResult(get(defaultedOptionsStore))
56
- return !get(defaultedOptionsStore).notifyOnChangeProps
57
- ? observer.trackResult($result)
58
- : $result
59
- })
57
+ /** Subscribe to changes in result and defaultedOptionsStore */
58
+ const { subscribe } = derived(
59
+ [result, defaultedOptionsStore],
60
+ ([$result, $defaultedOptionsStore]) => {
61
+ $result = observer.getOptimisticResult($defaultedOptionsStore)
62
+ return !$defaultedOptionsStore.notifyOnChangeProps
63
+ ? observer.trackResult($result)
64
+ : $result
65
+ },
66
+ )
60
67
 
61
68
  return { subscribe }
62
69
  }