1 | System.register(['jotai-tanstack-query', 'jotai'], (function (exports) {
|
2 | 'use strict';
|
3 | var atomsWithQuery, queryClientAtom, atomsWithInfiniteQuery, atom;
|
4 | return {
|
5 | setters: [function (module) {
|
6 | atomsWithQuery = module.atomsWithQuery;
|
7 | queryClientAtom = module.queryClientAtom;
|
8 | atomsWithInfiniteQuery = module.atomsWithInfiniteQuery;
|
9 | exports('queryClientAtom', module.queryClientAtom);
|
10 | }, function (module) {
|
11 | atom = module.atom;
|
12 | }],
|
13 | execute: (function () {
|
14 |
|
15 | exports({
|
16 | atomWithInfiniteQuery: atomWithInfiniteQuery,
|
17 | atomWithQuery: atomWithQuery
|
18 | });
|
19 |
|
20 | function atomWithQuery(createQuery, getQueryClient = (get) => get(queryClientAtom)) {
|
21 | const getOptions = (get) => ({
|
22 | staleTime: 200,
|
23 | ...typeof createQuery === "function" ? createQuery(get) : createQuery
|
24 | });
|
25 | const [dataAtom] = atomsWithQuery(getOptions, getQueryClient);
|
26 | return atom(
|
27 | (get) => {
|
28 | const options = getOptions(get);
|
29 | if (options.enabled === false) {
|
30 | const queryClient = getQueryClient(get);
|
31 | return queryClient.getQueryData(options.queryKey);
|
32 | }
|
33 | return get(dataAtom);
|
34 | },
|
35 | (_get, set, action) => {
|
36 | if (action.type === "refetch") {
|
37 | return set(dataAtom, { type: "refetch", force: true });
|
38 | }
|
39 | }
|
40 | );
|
41 | }
|
42 |
|
43 | function atomWithInfiniteQuery(createQuery, getQueryClient = (get) => get(queryClientAtom)) {
|
44 | const getOptions = (get) => ({
|
45 | staleTime: 200,
|
46 | ...typeof createQuery === "function" ? createQuery(get) : createQuery
|
47 | });
|
48 | const [dataAtom] = atomsWithInfiniteQuery(getOptions, getQueryClient);
|
49 | return atom(
|
50 | (get) => {
|
51 | const options = getOptions(get);
|
52 | if (options.enabled === false) {
|
53 | const queryClient = getQueryClient(get);
|
54 | return queryClient.getQueryData(options.queryKey);
|
55 | }
|
56 | return get(dataAtom);
|
57 | },
|
58 | (_get, set, action) => {
|
59 | if (action.type === "refetch") {
|
60 | return set(dataAtom, {
|
61 | type: "refetch",
|
62 | force: true,
|
63 | options: action.payload
|
64 | });
|
65 | }
|
66 | return set(dataAtom, action);
|
67 | }
|
68 | );
|
69 | }
|
70 |
|
71 | })
|
72 | };
|
73 | }));
|