@tanstack/solid-query 4.10.3 → 4.11.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/LICENSE +1 -1
- package/build/lib/createBaseQuery.esm.js +18 -2
- package/build/lib/createBaseQuery.esm.js.map +1 -1
- package/build/lib/createBaseQuery.js +18 -2
- package/build/lib/createBaseQuery.js.map +1 -1
- package/build/lib/createBaseQuery.mjs +18 -2
- package/build/lib/createBaseQuery.mjs.map +1 -1
- package/build/solid/createBaseQuery.js +14 -2
- package/build/umd/index.development.js +18 -2
- 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 +2 -2
- package/src/__tests__/createQuery.test.tsx +15 -42
- package/src/__tests__/suspense.test.tsx +0 -46
- package/src/__tests__/transition.test.tsx +58 -0
- package/src/createBaseQuery.ts +14 -3
package/LICENSE
CHANGED
|
@@ -7,6 +7,7 @@ function createBaseQuery(options, Observer) {
|
|
|
7
7
|
const queryClient = useQueryClient({
|
|
8
8
|
context: options.context
|
|
9
9
|
});
|
|
10
|
+
const emptyData = Symbol('empty');
|
|
10
11
|
const defaultedOptions = queryClient.defaultQueryOptions(options);
|
|
11
12
|
defaultedOptions._optimisticResults = 'optimistic';
|
|
12
13
|
const observer = new Observer(queryClient, defaultedOptions);
|
|
@@ -18,6 +19,10 @@ function createBaseQuery(options, Observer) {
|
|
|
18
19
|
}] = createResource(() => {
|
|
19
20
|
return new Promise(resolve => {
|
|
20
21
|
if (!(state.isFetching && state.isLoading)) {
|
|
22
|
+
if (unwrap(state.data) === emptyData) {
|
|
23
|
+
resolve(undefined);
|
|
24
|
+
}
|
|
25
|
+
|
|
21
26
|
resolve(unwrap(state.data));
|
|
22
27
|
}
|
|
23
28
|
});
|
|
@@ -30,7 +35,18 @@ function createBaseQuery(options, Observer) {
|
|
|
30
35
|
const unsubscribe = observer.subscribe(result => {
|
|
31
36
|
taskQueue.push(() => {
|
|
32
37
|
batch(() => {
|
|
33
|
-
|
|
38
|
+
const unwrappedResult = { ...unwrap(result)
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
if (unwrappedResult.data === undefined) {
|
|
42
|
+
// This is a hack to prevent Solid
|
|
43
|
+
// from deleting the data property when it is `undefined`
|
|
44
|
+
// ref: https://www.solidjs.com/docs/latest/api#updating-stores
|
|
45
|
+
// @ts-ignore
|
|
46
|
+
unwrappedResult.data = emptyData;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
setState(unwrap(unwrappedResult));
|
|
34
50
|
mutate(() => unwrap(result.data));
|
|
35
51
|
refetch();
|
|
36
52
|
});
|
|
@@ -62,7 +78,7 @@ function createBaseQuery(options, Observer) {
|
|
|
62
78
|
}));
|
|
63
79
|
const handler = {
|
|
64
80
|
get(target, prop) {
|
|
65
|
-
if (prop === 'data'
|
|
81
|
+
if (prop === 'data') {
|
|
66
82
|
return dataResource();
|
|
67
83
|
}
|
|
68
84
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createBaseQuery.esm.js","sources":["../../src/createBaseQuery.ts"],"sourcesContent":["import type { QueryObserver } from '@tanstack/query-core'\nimport type { QueryKey, QueryObserverResult } from '@tanstack/query-core'\nimport type { CreateBaseQueryOptions } from './types'\nimport { useQueryClient } from './QueryClientProvider'\nimport {\n onMount,\n onCleanup,\n createComputed,\n createResource,\n on,\n batch,\n} from 'solid-js'\nimport { createStore, unwrap } from 'solid-js/store'\nimport { shouldThrowError } from './utils'\n\n// Base Query Function that is used to create the query.\nexport function createBaseQuery<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey extends QueryKey,\n>(\n options: CreateBaseQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >,\n Observer: typeof QueryObserver,\n): QueryObserverResult<TData, TError> {\n const queryClient = useQueryClient({ context: options.context })\n\n const defaultedOptions = queryClient.defaultQueryOptions(options)\n defaultedOptions._optimisticResults = 'optimistic'\n const observer = new Observer(queryClient, defaultedOptions)\n\n const [state, setState] = createStore<QueryObserverResult<TData, TError>>(\n // @ts-ignore\n observer.getOptimisticResult(defaultedOptions),\n )\n\n const [dataResource, { refetch, mutate }] = createResource<TData | undefined>(\n () => {\n return new Promise((resolve) => {\n if (!(state.isFetching && state.isLoading)) {\n resolve(unwrap(state.data))\n }\n })\n },\n )\n\n batch(() => {\n mutate(() => unwrap(state.data))\n refetch()\n })\n\n let taskQueue: Array<() => void> = []\n\n const unsubscribe = observer.subscribe((result) => {\n taskQueue.push(() => {\n batch(() => {\n setState(unwrap(
|
|
1
|
+
{"version":3,"file":"createBaseQuery.esm.js","sources":["../../src/createBaseQuery.ts"],"sourcesContent":["import type { QueryObserver } from '@tanstack/query-core'\nimport type { QueryKey, QueryObserverResult } from '@tanstack/query-core'\nimport type { CreateBaseQueryOptions } from './types'\nimport { useQueryClient } from './QueryClientProvider'\nimport {\n onMount,\n onCleanup,\n createComputed,\n createResource,\n on,\n batch,\n} from 'solid-js'\nimport { createStore, unwrap } from 'solid-js/store'\nimport { shouldThrowError } from './utils'\n\n// Base Query Function that is used to create the query.\nexport function createBaseQuery<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey extends QueryKey,\n>(\n options: CreateBaseQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >,\n Observer: typeof QueryObserver,\n): QueryObserverResult<TData, TError> {\n const queryClient = useQueryClient({ context: options.context })\n const emptyData = Symbol('empty')\n const defaultedOptions = queryClient.defaultQueryOptions(options)\n defaultedOptions._optimisticResults = 'optimistic'\n const observer = new Observer(queryClient, defaultedOptions)\n\n const [state, setState] = createStore<QueryObserverResult<TData, TError>>(\n // @ts-ignore\n observer.getOptimisticResult(defaultedOptions),\n )\n\n const [dataResource, { refetch, mutate }] = createResource<TData | undefined>(\n () => {\n return new Promise((resolve) => {\n if (!(state.isFetching && state.isLoading)) {\n if (unwrap(state.data) === emptyData) {\n resolve(undefined)\n }\n resolve(unwrap(state.data))\n }\n })\n },\n )\n\n batch(() => {\n mutate(() => unwrap(state.data))\n refetch()\n })\n\n let taskQueue: Array<() => void> = []\n\n const unsubscribe = observer.subscribe((result) => {\n taskQueue.push(() => {\n batch(() => {\n const unwrappedResult = { ...unwrap(result) }\n if (unwrappedResult.data === undefined) {\n // This is a hack to prevent Solid\n // from deleting the data property when it is `undefined`\n // ref: https://www.solidjs.com/docs/latest/api#updating-stores\n // @ts-ignore\n unwrappedResult.data = emptyData\n }\n setState(unwrap(unwrappedResult))\n mutate(() => unwrap(result.data))\n refetch()\n })\n })\n\n queueMicrotask(() => {\n const taskToRun = taskQueue.pop()\n if (taskToRun) {\n taskToRun()\n }\n taskQueue = []\n })\n })\n\n onCleanup(() => unsubscribe())\n\n onMount(() => {\n observer.setOptions(defaultedOptions, { listeners: false })\n })\n\n createComputed(() => {\n const newDefaultedOptions = queryClient.defaultQueryOptions(options)\n observer.setOptions(newDefaultedOptions)\n })\n\n createComputed(\n on(\n () => state.status,\n () => {\n if (\n state.isError &&\n !state.isFetching &&\n shouldThrowError(observer.options.useErrorBoundary, [\n state.error,\n observer.getCurrentQuery(),\n ])\n ) {\n throw state.error\n }\n },\n ),\n )\n\n const handler = {\n get(\n target: QueryObserverResult<TData, TError>,\n prop: keyof QueryObserverResult<TData, TError>,\n ): any {\n if (prop === 'data') {\n return dataResource()\n }\n return Reflect.get(target, prop)\n },\n }\n\n return new Proxy(state, handler) as QueryObserverResult<TData, TError>\n}\n"],"names":["createBaseQuery","options","Observer","queryClient","useQueryClient","context","emptyData","Symbol","defaultedOptions","defaultQueryOptions","_optimisticResults","observer","state","setState","createStore","getOptimisticResult","dataResource","refetch","mutate","createResource","Promise","resolve","isFetching","isLoading","unwrap","data","undefined","batch","taskQueue","unsubscribe","subscribe","result","push","unwrappedResult","queueMicrotask","taskToRun","pop","onCleanup","onMount","setOptions","listeners","createComputed","newDefaultedOptions","on","status","isError","shouldThrowError","useErrorBo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,OAAhC,CAA5B,CAAA;IACAU,QAAQ,CAAC4B,UAAT,CAAoBG,mBAApB,CAAA,CAAA;AACD,GAHa,CAAd,CAAA;EAKAD,cAAc,CACZE,EAAE,CACA,MAAM/B,KAAK,CAACgC,MADZ,EAEA,MAAM;AACJ,IAAA,IACEhC,KAAK,CAACiC,OAAN,IACA,CAACjC,KAAK,CAACU,UADP,IAEAwB,gBAAgB,CAACnC,QAAQ,CAACV,OAAT,CAAiB8C,gBAAlB,EAAoC,CAClDnC,KAAK,CAACoC,KAD4C,EAElDrC,QAAQ,CAACsC,eAAT,EAFkD,CAApC,CAHlB,EAOE;MACA,MAAMrC,KAAK,CAACoC,KAAZ,CAAA;AACD,KAAA;AACF,GAbD,CADU,CAAd,CAAA;AAkBA,EAAA,MAAME,OAAO,GAAG;AACdC,IAAAA,GAAG,CACDC,MADC,EAEDC,IAFC,EAGI;MACL,IAAIA,IAAI,KAAK,MAAb,EAAqB;AACnB,QAAA,OAAOrC,YAAY,EAAnB,CAAA;AACD,OAAA;;AACD,MAAA,OAAOsC,OAAO,CAACH,GAAR,CAAYC,MAAZ,EAAoBC,IAApB,CAAP,CAAA;AACD,KAAA;;GATH,CAAA;AAYA,EAAA,OAAO,IAAIE,KAAJ,CAAU3C,KAAV,EAAiBsC,OAAjB,CAAP,CAAA;AACD;;;;"}
|
|
@@ -11,6 +11,7 @@ function createBaseQuery(options, Observer) {
|
|
|
11
11
|
const queryClient = QueryClientProvider.useQueryClient({
|
|
12
12
|
context: options.context
|
|
13
13
|
});
|
|
14
|
+
const emptyData = Symbol('empty');
|
|
14
15
|
const defaultedOptions = queryClient.defaultQueryOptions(options);
|
|
15
16
|
defaultedOptions._optimisticResults = 'optimistic';
|
|
16
17
|
const observer = new Observer(queryClient, defaultedOptions);
|
|
@@ -22,6 +23,10 @@ function createBaseQuery(options, Observer) {
|
|
|
22
23
|
}] = solidJs.createResource(() => {
|
|
23
24
|
return new Promise(resolve => {
|
|
24
25
|
if (!(state.isFetching && state.isLoading)) {
|
|
26
|
+
if (store.unwrap(state.data) === emptyData) {
|
|
27
|
+
resolve(undefined);
|
|
28
|
+
}
|
|
29
|
+
|
|
25
30
|
resolve(store.unwrap(state.data));
|
|
26
31
|
}
|
|
27
32
|
});
|
|
@@ -34,7 +39,18 @@ function createBaseQuery(options, Observer) {
|
|
|
34
39
|
const unsubscribe = observer.subscribe(result => {
|
|
35
40
|
taskQueue.push(() => {
|
|
36
41
|
solidJs.batch(() => {
|
|
37
|
-
|
|
42
|
+
const unwrappedResult = { ...store.unwrap(result)
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
if (unwrappedResult.data === undefined) {
|
|
46
|
+
// This is a hack to prevent Solid
|
|
47
|
+
// from deleting the data property when it is `undefined`
|
|
48
|
+
// ref: https://www.solidjs.com/docs/latest/api#updating-stores
|
|
49
|
+
// @ts-ignore
|
|
50
|
+
unwrappedResult.data = emptyData;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
setState(store.unwrap(unwrappedResult));
|
|
38
54
|
mutate(() => store.unwrap(result.data));
|
|
39
55
|
refetch();
|
|
40
56
|
});
|
|
@@ -66,7 +82,7 @@ function createBaseQuery(options, Observer) {
|
|
|
66
82
|
}));
|
|
67
83
|
const handler = {
|
|
68
84
|
get(target, prop) {
|
|
69
|
-
if (prop === 'data'
|
|
85
|
+
if (prop === 'data') {
|
|
70
86
|
return dataResource();
|
|
71
87
|
}
|
|
72
88
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createBaseQuery.js","sources":["../../src/createBaseQuery.ts"],"sourcesContent":["import type { QueryObserver } from '@tanstack/query-core'\nimport type { QueryKey, QueryObserverResult } from '@tanstack/query-core'\nimport type { CreateBaseQueryOptions } from './types'\nimport { useQueryClient } from './QueryClientProvider'\nimport {\n onMount,\n onCleanup,\n createComputed,\n createResource,\n on,\n batch,\n} from 'solid-js'\nimport { createStore, unwrap } from 'solid-js/store'\nimport { shouldThrowError } from './utils'\n\n// Base Query Function that is used to create the query.\nexport function createBaseQuery<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey extends QueryKey,\n>(\n options: CreateBaseQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >,\n Observer: typeof QueryObserver,\n): QueryObserverResult<TData, TError> {\n const queryClient = useQueryClient({ context: options.context })\n\n const defaultedOptions = queryClient.defaultQueryOptions(options)\n defaultedOptions._optimisticResults = 'optimistic'\n const observer = new Observer(queryClient, defaultedOptions)\n\n const [state, setState] = createStore<QueryObserverResult<TData, TError>>(\n // @ts-ignore\n observer.getOptimisticResult(defaultedOptions),\n )\n\n const [dataResource, { refetch, mutate }] = createResource<TData | undefined>(\n () => {\n return new Promise((resolve) => {\n if (!(state.isFetching && state.isLoading)) {\n resolve(unwrap(state.data))\n }\n })\n },\n )\n\n batch(() => {\n mutate(() => unwrap(state.data))\n refetch()\n })\n\n let taskQueue: Array<() => void> = []\n\n const unsubscribe = observer.subscribe((result) => {\n taskQueue.push(() => {\n batch(() => {\n setState(unwrap(
|
|
1
|
+
{"version":3,"file":"createBaseQuery.js","sources":["../../src/createBaseQuery.ts"],"sourcesContent":["import type { QueryObserver } from '@tanstack/query-core'\nimport type { QueryKey, QueryObserverResult } from '@tanstack/query-core'\nimport type { CreateBaseQueryOptions } from './types'\nimport { useQueryClient } from './QueryClientProvider'\nimport {\n onMount,\n onCleanup,\n createComputed,\n createResource,\n on,\n batch,\n} from 'solid-js'\nimport { createStore, unwrap } from 'solid-js/store'\nimport { shouldThrowError } from './utils'\n\n// Base Query Function that is used to create the query.\nexport function createBaseQuery<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey extends QueryKey,\n>(\n options: CreateBaseQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >,\n Observer: typeof QueryObserver,\n): QueryObserverResult<TData, TError> {\n const queryClient = useQueryClient({ context: options.context })\n const emptyData = Symbol('empty')\n const defaultedOptions = queryClient.defaultQueryOptions(options)\n defaultedOptions._optimisticResults = 'optimistic'\n const observer = new Observer(queryClient, defaultedOptions)\n\n const [state, setState] = createStore<QueryObserverResult<TData, TError>>(\n // @ts-ignore\n observer.getOptimisticResult(defaultedOptions),\n )\n\n const [dataResource, { refetch, mutate }] = createResource<TData | undefined>(\n () => {\n return new Promise((resolve) => {\n if (!(state.isFetching && state.isLoading)) {\n if (unwrap(state.data) === emptyData) {\n resolve(undefined)\n }\n resolve(unwrap(state.data))\n }\n })\n },\n )\n\n batch(() => {\n mutate(() => unwrap(state.data))\n refetch()\n })\n\n let taskQueue: Array<() => void> = []\n\n const unsubscribe = observer.subscribe((result) => {\n taskQueue.push(() => {\n batch(() => {\n const unwrappedResult = { ...unwrap(result) }\n if (unwrappedResult.data === undefined) {\n // This is a hack to prevent Solid\n // from deleting the data property when it is `undefined`\n // ref: https://www.solidjs.com/docs/latest/api#updating-stores\n // @ts-ignore\n unwrappedResult.data = emptyData\n }\n setState(unwrap(unwrappedResult))\n mutate(() => unwrap(result.data))\n refetch()\n })\n })\n\n queueMicrotask(() => {\n const taskToRun = taskQueue.pop()\n if (taskToRun) {\n taskToRun()\n }\n taskQueue = []\n })\n })\n\n onCleanup(() => unsubscribe())\n\n onMount(() => {\n observer.setOptions(defaultedOptions, { listeners: false })\n })\n\n createComputed(() => {\n const newDefaultedOptions = queryClient.defaultQueryOptions(options)\n observer.setOptions(newDefaultedOptions)\n })\n\n createComputed(\n on(\n () => state.status,\n () => {\n if (\n state.isError &&\n !state.isFetching &&\n shouldThrowError(observer.options.useErrorBoundary, [\n state.error,\n observer.getCurrentQuery(),\n ])\n ) {\n throw state.error\n }\n },\n ),\n )\n\n const handler = {\n get(\n target: QueryObserverResult<TData, TError>,\n prop: keyof QueryObserverResult<TData, TError>,\n ): any {\n if (prop === 'data') {\n return dataResource()\n }\n return Reflect.get(target, prop)\n },\n }\n\n return new Proxy(state, handler) as QueryObserverResult<TData, TError>\n}\n"],"names":["createBaseQuery","options","Observer","queryClient","useQueryClient","context","emptyData","Symbol","defaultedOptions","defaultQueryOptions","_optimisticResults","observer","state","setState","createStore","getOptimisticResult","dataResource","refetch","mutate","createResource","Promise","resolve","isFetching","isLoading","unwrap","data","undefined","batch","taskQueue","unsubscribe","subscribe","result","push","unwrappedResult","queueMicrotask","taskToRun","pop","onCleanup","onMount","setOptions","listeners","createComputed","newDefaultedOptions","on","status","isError","shouldThrowError","useErrorBoundary","error","getCurrentQuery","handler","get","target","prop","Reflect","Proxy"],"mappings":";;;;;;;;;AAgBO,SAASA,eAAT,CAOLC,OAPK,EAcLC,QAdK,EAe+B;EACpC,MAAMC,WAAW,GAAGC,kCAAc,CAAC;IAAEC,OAAO,EAAEJ,OAAO,CAACI,OAAAA;AAAnB,GAAD,CAAlC,CAAA;AACA,EAAA,MAAMC,SAAS,GAAGC,MAAM,CAAC,OAAD,CAAxB,CAAA;AACA,EAAA,MAAMC,gBAAgB,GAAGL,WAAW,CAACM,mBAAZ,CAAgCR,OAAhC,CAAzB,CAAA;EACAO,gBAAgB,CAACE,kBAAjB,GAAsC,YAAtC,CAAA;EACA,MAAMC,QAAQ,GAAG,IAAIT,QAAJ,CAAaC,WAAb,EAA0BK,gBAA1B,CAAjB,CAAA;AAEA,EAAA,MAAM,CAACI,KAAD,EAAQC,QAAR,CAAA,GAAoBC,iBAAW;AAEnCH,EAAAA,QAAQ,CAACI,mBAAT,CAA6BP,gBAA7B,CAFmC,CAArC,CAAA;EAKA,MAAM,CAACQ,YAAD,EAAe;IAAEC,OAAF;AAAWC,IAAAA,MAAAA;GAA1B,CAAA,GAAsCC,sBAAc,CACxD,MAAM;AACJ,IAAA,OAAO,IAAIC,OAAJ,CAAaC,OAAD,IAAa;MAC9B,IAAI,EAAET,KAAK,CAACU,UAAN,IAAoBV,KAAK,CAACW,SAA5B,CAAJ,EAA4C;QAC1C,IAAIC,YAAM,CAACZ,KAAK,CAACa,IAAP,CAAN,KAAuBnB,SAA3B,EAAsC;UACpCe,OAAO,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B,CAAT,CAAA;AAEAS,EAAAA,eAAO,CAAC,MAAM;AACZ3B,IAAAA,QAAQ,CAAC4B,UAAT,CAAoB/B,gBAApB,EAAsC;AAAEgC,MAAAA,SAAS,EAAE,KAAA;KAAnD,CAAA,CAAA;AACD,GAFM,CAAP,CAAA;AAIAC,EAAAA,sBAAc,CAAC,MAAM;AACnB,IAAA,MAAMC,mBAAmB,GAAGvC,WAAW,CAACM,mBAAZ,CAAgCR,OAAhC,CAA5B,CAAA;IACAU,QAAQ,CAAC4B,UAAT,CAAoBG,mBAApB,CAAA,CAAA;AACD,GAHa,CAAd,CAAA;EAKAD,sBAAc,CACZE,UAAE,CACA,MAAM/B,KAAK,CAACgC,MADZ,EAEA,MAAM;AACJ,IAAA,IACEhC,KAAK,CAACiC,OAAN,IACA,CAACjC,KAAK,CAACU,UADP,IAEAwB,sBAAgB,CAACnC,QAAQ,CAACV,OAAT,CAAiB8C,gBAAlB,EAAoC,CAClDnC,KAAK,CAACoC,KAD4C,EAElDrC,QAAQ,CAACsC,eAAT,EAFkD,CAApC,CAHlB,EAOE;MACA,MAAMrC,KAAK,CAACoC,KAAZ,CAAA;AACD,KAAA;AACF,GAbD,CADU,CAAd,CAAA;AAkBA,EAAA,MAAME,OAAO,GAAG;AACdC,IAAAA,GAAG,CACDC,MADC,EAEDC,IAFC,EAGI;MACL,IAAIA,IAAI,KAAK,MAAb,EAAqB;AACnB,QAAA,OAAOrC,YAAY,EAAnB,CAAA;AACD,OAAA;;AACD,MAAA,OAAOsC,OAAO,CAACH,GAAR,CAAYC,MAAZ,EAAoBC,IAApB,CAAP,CAAA;AACD,KAAA;;GATH,CAAA;AAYA,EAAA,OAAO,IAAIE,KAAJ,CAAU3C,KAAV,EAAiBsC,OAAjB,CAAP,CAAA;AACD;;;;"}
|
|
@@ -7,6 +7,7 @@ function createBaseQuery(options, Observer) {
|
|
|
7
7
|
const queryClient = useQueryClient({
|
|
8
8
|
context: options.context
|
|
9
9
|
});
|
|
10
|
+
const emptyData = Symbol('empty');
|
|
10
11
|
const defaultedOptions = queryClient.defaultQueryOptions(options);
|
|
11
12
|
defaultedOptions._optimisticResults = 'optimistic';
|
|
12
13
|
const observer = new Observer(queryClient, defaultedOptions);
|
|
@@ -18,6 +19,10 @@ function createBaseQuery(options, Observer) {
|
|
|
18
19
|
}] = createResource(() => {
|
|
19
20
|
return new Promise(resolve => {
|
|
20
21
|
if (!(state.isFetching && state.isLoading)) {
|
|
22
|
+
if (unwrap(state.data) === emptyData) {
|
|
23
|
+
resolve(undefined);
|
|
24
|
+
}
|
|
25
|
+
|
|
21
26
|
resolve(unwrap(state.data));
|
|
22
27
|
}
|
|
23
28
|
});
|
|
@@ -30,7 +35,18 @@ function createBaseQuery(options, Observer) {
|
|
|
30
35
|
const unsubscribe = observer.subscribe(result => {
|
|
31
36
|
taskQueue.push(() => {
|
|
32
37
|
batch(() => {
|
|
33
|
-
|
|
38
|
+
const unwrappedResult = { ...unwrap(result)
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
if (unwrappedResult.data === undefined) {
|
|
42
|
+
// This is a hack to prevent Solid
|
|
43
|
+
// from deleting the data property when it is `undefined`
|
|
44
|
+
// ref: https://www.solidjs.com/docs/latest/api#updating-stores
|
|
45
|
+
// @ts-ignore
|
|
46
|
+
unwrappedResult.data = emptyData;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
setState(unwrap(unwrappedResult));
|
|
34
50
|
mutate(() => unwrap(result.data));
|
|
35
51
|
refetch();
|
|
36
52
|
});
|
|
@@ -62,7 +78,7 @@ function createBaseQuery(options, Observer) {
|
|
|
62
78
|
}));
|
|
63
79
|
const handler = {
|
|
64
80
|
get(target, prop) {
|
|
65
|
-
if (prop === 'data'
|
|
81
|
+
if (prop === 'data') {
|
|
66
82
|
return dataResource();
|
|
67
83
|
}
|
|
68
84
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createBaseQuery.mjs","sources":["../../src/createBaseQuery.ts"],"sourcesContent":["import type { QueryObserver } from '@tanstack/query-core'\nimport type { QueryKey, QueryObserverResult } from '@tanstack/query-core'\nimport type { CreateBaseQueryOptions } from './types'\nimport { useQueryClient } from './QueryClientProvider'\nimport {\n onMount,\n onCleanup,\n createComputed,\n createResource,\n on,\n batch,\n} from 'solid-js'\nimport { createStore, unwrap } from 'solid-js/store'\nimport { shouldThrowError } from './utils'\n\n// Base Query Function that is used to create the query.\nexport function createBaseQuery<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey extends QueryKey,\n>(\n options: CreateBaseQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >,\n Observer: typeof QueryObserver,\n): QueryObserverResult<TData, TError> {\n const queryClient = useQueryClient({ context: options.context })\n\n const defaultedOptions = queryClient.defaultQueryOptions(options)\n defaultedOptions._optimisticResults = 'optimistic'\n const observer = new Observer(queryClient, defaultedOptions)\n\n const [state, setState] = createStore<QueryObserverResult<TData, TError>>(\n // @ts-ignore\n observer.getOptimisticResult(defaultedOptions),\n )\n\n const [dataResource, { refetch, mutate }] = createResource<TData | undefined>(\n () => {\n return new Promise((resolve) => {\n if (!(state.isFetching && state.isLoading)) {\n resolve(unwrap(state.data))\n }\n })\n },\n )\n\n batch(() => {\n mutate(() => unwrap(state.data))\n refetch()\n })\n\n let taskQueue: Array<() => void> = []\n\n const unsubscribe = observer.subscribe((result) => {\n taskQueue.push(() => {\n batch(() => {\n setState(unwrap(
|
|
1
|
+
{"version":3,"file":"createBaseQuery.mjs","sources":["../../src/createBaseQuery.ts"],"sourcesContent":["import type { QueryObserver } from '@tanstack/query-core'\nimport type { QueryKey, QueryObserverResult } from '@tanstack/query-core'\nimport type { CreateBaseQueryOptions } from './types'\nimport { useQueryClient } from './QueryClientProvider'\nimport {\n onMount,\n onCleanup,\n createComputed,\n createResource,\n on,\n batch,\n} from 'solid-js'\nimport { createStore, unwrap } from 'solid-js/store'\nimport { shouldThrowError } from './utils'\n\n// Base Query Function that is used to create the query.\nexport function createBaseQuery<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey extends QueryKey,\n>(\n options: CreateBaseQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >,\n Observer: typeof QueryObserver,\n): QueryObserverResult<TData, TError> {\n const queryClient = useQueryClient({ context: options.context })\n const emptyData = Symbol('empty')\n const defaultedOptions = queryClient.defaultQueryOptions(options)\n defaultedOptions._optimisticResults = 'optimistic'\n const observer = new Observer(queryClient, defaultedOptions)\n\n const [state, setState] = createStore<QueryObserverResult<TData, TError>>(\n // @ts-ignore\n observer.getOptimisticResult(defaultedOptions),\n )\n\n const [dataResource, { refetch, mutate }] = createResource<TData | undefined>(\n () => {\n return new Promise((resolve) => {\n if (!(state.isFetching && state.isLoading)) {\n if (unwrap(state.data) === emptyData) {\n resolve(undefined)\n }\n resolve(unwrap(state.data))\n }\n })\n },\n )\n\n batch(() => {\n mutate(() => unwrap(state.data))\n refetch()\n })\n\n let taskQueue: Array<() => void> = []\n\n const unsubscribe = observer.subscribe((result) => {\n taskQueue.push(() => {\n batch(() => {\n const unwrappedResult = { ...unwrap(result) }\n if (unwrappedResult.data === undefined) {\n // This is a hack to prevent Solid\n // from deleting the data property when it is `undefined`\n // ref: https://www.solidjs.com/docs/latest/api#updating-stores\n // @ts-ignore\n unwrappedResult.data = emptyData\n }\n setState(unwrap(unwrappedResult))\n mutate(() => unwrap(result.data))\n refetch()\n })\n })\n\n queueMicrotask(() => {\n const taskToRun = taskQueue.pop()\n if (taskToRun) {\n taskToRun()\n }\n taskQueue = []\n })\n })\n\n onCleanup(() => unsubscribe())\n\n onMount(() => {\n observer.setOptions(defaultedOptions, { listeners: false })\n })\n\n createComputed(() => {\n const newDefaultedOptions = queryClient.defaultQueryOptions(options)\n observer.setOptions(newDefaultedOptions)\n })\n\n createComputed(\n on(\n () => state.status,\n () => {\n if (\n state.isError &&\n !state.isFetching &&\n shouldThrowError(observer.options.useErrorBoundary, [\n state.error,\n observer.getCurrentQuery(),\n ])\n ) {\n throw state.error\n }\n },\n ),\n )\n\n const handler = {\n get(\n target: QueryObserverResult<TData, TError>,\n prop: keyof QueryObserverResult<TData, TError>,\n ): any {\n if (prop === 'data') {\n return dataResource()\n }\n return Reflect.get(target, prop)\n },\n }\n\n return new Proxy(state, handler) as QueryObserverResult<TData, TError>\n}\n"],"names":["createBaseQuery","options","Observer","queryClient","useQueryClient","context","emptyData","Symbol","defaultedOptions","defaultQueryOptions","_optimisticResults","observer","state","setState","createStore","getOptimisticResult","dataResource","refetch","mutate","createResource","Promise","resolve","isFetching","isLoading","unwrap","data","undefined","batch","taskQueue","unsubscribe","subscribe","result","push","unwrappedResult","queueMicrotask","taskToRun","pop","onCleanup","onMount","setOptions","listeners","createComputed","newDefaultedOptions","on","status","isError","shouldThrowError","useErrorBoundary","error","getCurrentQuery","handler","get","target","prop","Reflect","Proxy"],"mappings":";;;;;AAgBO,SAASA,eAAT,CAOLC,OAPK,EAcLC,QAdK,EAe+B;EACpC,MAAMC,WAAW,GAAGC,cAAc,CAAC;IAAEC,OAAO,EAAEJ,OAAO,CAACI,OAAAA;AAAnB,GAAD,CAAlC,CAAA;AACA,EAAA,MAAMC,SAAS,GAAGC,MAAM,CAAC,OAAD,CAAxB,CAAA;AACA,EAAA,MAAMC,gBAAgB,GAAGL,WAAW,CAACM,mBAAZ,CAAgCR,OAAhC,CAAzB,CAAA;EACAO,gBAAgB,CAACE,kBAAjB,GAAsC,YAAtC,CAAA;EACA,MAAMC,QAAQ,GAAG,IAAIT,QAAJ,CAAaC,WAAb,EAA0BK,gBAA1B,CAAjB,CAAA;AAEA,EAAA,MAAM,CAACI,KAAD,EAAQC,QAAR,CAAA,GAAoBC,WAAW;AAEnCH,EAAAA,QAAQ,CAACI,mBAAT,CAA6BP,gBAA7B,CAFmC,CAArC,CAAA;EAKA,MAAM,CAACQ,YAAD,EAAe;IAAEC,OAAF;AAAWC,IAAAA,MAAAA;GAA1B,CAAA,GA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,CAAA;AACD,KAAA;;GATH,CAAA;AAYA,EAAA,OAAO,IAAIE,KAAJ,CAAU3C,KAAV,EAAiBsC,OAAjB,CAAP,CAAA;AACD;;;;"}
|
|
@@ -5,6 +5,7 @@ import { shouldThrowError } from './utils';
|
|
|
5
5
|
// Base Query Function that is used to create the query.
|
|
6
6
|
export function createBaseQuery(options, Observer) {
|
|
7
7
|
const queryClient = useQueryClient({ context: options.context });
|
|
8
|
+
const emptyData = Symbol('empty');
|
|
8
9
|
const defaultedOptions = queryClient.defaultQueryOptions(options);
|
|
9
10
|
defaultedOptions._optimisticResults = 'optimistic';
|
|
10
11
|
const observer = new Observer(queryClient, defaultedOptions);
|
|
@@ -14,6 +15,9 @@ export function createBaseQuery(options, Observer) {
|
|
|
14
15
|
const [dataResource, { refetch, mutate }] = createResource(() => {
|
|
15
16
|
return new Promise((resolve) => {
|
|
16
17
|
if (!(state.isFetching && state.isLoading)) {
|
|
18
|
+
if (unwrap(state.data) === emptyData) {
|
|
19
|
+
resolve(undefined);
|
|
20
|
+
}
|
|
17
21
|
resolve(unwrap(state.data));
|
|
18
22
|
}
|
|
19
23
|
});
|
|
@@ -26,7 +30,15 @@ export function createBaseQuery(options, Observer) {
|
|
|
26
30
|
const unsubscribe = observer.subscribe((result) => {
|
|
27
31
|
taskQueue.push(() => {
|
|
28
32
|
batch(() => {
|
|
29
|
-
|
|
33
|
+
const unwrappedResult = { ...unwrap(result) };
|
|
34
|
+
if (unwrappedResult.data === undefined) {
|
|
35
|
+
// This is a hack to prevent Solid
|
|
36
|
+
// from deleting the data property when it is `undefined`
|
|
37
|
+
// ref: https://www.solidjs.com/docs/latest/api#updating-stores
|
|
38
|
+
// @ts-ignore
|
|
39
|
+
unwrappedResult.data = emptyData;
|
|
40
|
+
}
|
|
41
|
+
setState(unwrap(unwrappedResult));
|
|
30
42
|
mutate(() => unwrap(result.data));
|
|
31
43
|
refetch();
|
|
32
44
|
});
|
|
@@ -59,7 +71,7 @@ export function createBaseQuery(options, Observer) {
|
|
|
59
71
|
}));
|
|
60
72
|
const handler = {
|
|
61
73
|
get(target, prop) {
|
|
62
|
-
if (prop === 'data'
|
|
74
|
+
if (prop === 'data') {
|
|
63
75
|
return dataResource();
|
|
64
76
|
}
|
|
65
77
|
return Reflect.get(target, prop);
|
|
@@ -3224,6 +3224,7 @@
|
|
|
3224
3224
|
const queryClient = useQueryClient({
|
|
3225
3225
|
context: options.context
|
|
3226
3226
|
});
|
|
3227
|
+
const emptyData = Symbol('empty');
|
|
3227
3228
|
const defaultedOptions = queryClient.defaultQueryOptions(options);
|
|
3228
3229
|
defaultedOptions._optimisticResults = 'optimistic';
|
|
3229
3230
|
const observer = new Observer(queryClient, defaultedOptions);
|
|
@@ -3235,6 +3236,10 @@
|
|
|
3235
3236
|
}] = solidJs.createResource(() => {
|
|
3236
3237
|
return new Promise(resolve => {
|
|
3237
3238
|
if (!(state.isFetching && state.isLoading)) {
|
|
3239
|
+
if (store.unwrap(state.data) === emptyData) {
|
|
3240
|
+
resolve(undefined);
|
|
3241
|
+
}
|
|
3242
|
+
|
|
3238
3243
|
resolve(store.unwrap(state.data));
|
|
3239
3244
|
}
|
|
3240
3245
|
});
|
|
@@ -3247,7 +3252,18 @@
|
|
|
3247
3252
|
const unsubscribe = observer.subscribe(result => {
|
|
3248
3253
|
taskQueue.push(() => {
|
|
3249
3254
|
solidJs.batch(() => {
|
|
3250
|
-
|
|
3255
|
+
const unwrappedResult = { ...store.unwrap(result)
|
|
3256
|
+
};
|
|
3257
|
+
|
|
3258
|
+
if (unwrappedResult.data === undefined) {
|
|
3259
|
+
// This is a hack to prevent Solid
|
|
3260
|
+
// from deleting the data property when it is `undefined`
|
|
3261
|
+
// ref: https://www.solidjs.com/docs/latest/api#updating-stores
|
|
3262
|
+
// @ts-ignore
|
|
3263
|
+
unwrappedResult.data = emptyData;
|
|
3264
|
+
}
|
|
3265
|
+
|
|
3266
|
+
setState(store.unwrap(unwrappedResult));
|
|
3251
3267
|
mutate(() => store.unwrap(result.data));
|
|
3252
3268
|
refetch();
|
|
3253
3269
|
});
|
|
@@ -3279,7 +3295,7 @@
|
|
|
3279
3295
|
}));
|
|
3280
3296
|
const handler = {
|
|
3281
3297
|
get(target, prop) {
|
|
3282
|
-
if (prop === 'data'
|
|
3298
|
+
if (prop === 'data') {
|
|
3283
3299
|
return dataResource();
|
|
3284
3300
|
}
|
|
3285
3301
|
|