UNPKG

2.63 kBJavaScriptView Raw
1System.register(["@tanstack/query-core","jotai"],function(Q){"use strict";var g,p,C,P,f;return{setters:[function(d){g=d.QueryClient,p=d.QueryObserver,C=d.InfiniteQueryObserver,P=d.isCancelledError},function(d){f=d.atom}],execute:function(){Q({atomWithInfiniteQuery:A,atomWithQuery:E});const d=Q("queryClientAtom",f(new g));function E(v,w=b=>b(d)){const b=f(t=>{const e=w(t),n=e.defaultQueryOptions();return new p(e,n)}),l=f(t=>{const e=w(t),n=typeof v=="function"?v(t):v,a=e.defaultQueryOptions(n),s=t(b);s.destroy(),s.setOptions(a);const u=s.getCurrentResult();let o=null;const y=f(u.data===void 0&&n.enabled!==!1?new Promise(m=>{o=m}):u);let r=null,c=null;const i=()=>{r||(c==null||c(),c=null)},h=m=>{if(!(m.isFetching||!m.isError&&m.data===void 0))if(o)setTimeout(i,1e3),o(m),o=null;else if(r)r(m);else throw new Error("setting result without mount")};return n.enabled!==!1&&(c=s.subscribe(h)),y.onMount=m=>(r=m,n.enabled!==!1&&!c&&(c=s.subscribe(h),h(s.getCurrentResult())),()=>{r=null,c==null||c()}),{options:n,resultAtom:y,unsubIfNotMounted:i}},(t,e,n)=>{const a=t(b),{options:s,resultAtom:u,unsubIfNotMounted:o}=t(l);if(s.enabled!==!1)switch(n.type){case"refetch":return e(u,new Promise(()=>{})),o(),a.refetch({cancelRefetch:!0}).then(y=>{e(u,y)})}});return f(t=>{const{resultAtom:e}=t(l),n=t(e);if(n.isError)throw n.error;return n.data},(t,e,n)=>e(l,n))}function A(v,w=b=>b(d)){const b=f(l=>{const t=w(l),e=typeof v=="function"?v(l):v,n=t.defaultQueryOptions(e),a=new C(t,n),s=a.getCurrentResult();let u=null;const o=f(s.data===void 0&&e.enabled!==!1?new Promise(i=>{u=i}):s);let y=()=>{throw new Error("setting result without mount")};const r={isMounted:!1,unsubscribe:null},c=i=>{i.isFetching||!i.isError&&i.data===void 0||i.isError&&P(i.error)||(u?(setTimeout(()=>{var h;r.isMounted||((h=r.unsubscribe)==null||h.call(r),r.unsubscribe=null)},1e3),u(i),u=null):y(i))};return e.enabled!==!1&&(r.unsubscribe=a.subscribe(c)),o.onMount=i=>(y=i,r.isMounted=!0,e.enabled!==!1&&!r.unsubscribe&&(r.unsubscribe=a.subscribe(c),c(a.getCurrentResult())),()=>{var h;return(h=r.unsubscribe)==null?void 0:h.call(r)}),{options:e,resultAtom:o,observer:a,state:r}},(l,t,e)=>{var n;const{options:a,resultAtom:s,observer:u,state:o}=l(b);if(a.enabled!==!1)switch(e.type){case"refetch":{t(s,new Promise(()=>{})),o.isMounted||((n=o.unsubscribe)==null||n.call(o),o.unsubscribe=null),u.refetch(e.payload).then(y=>{t(s,y)});return}case"fetchPreviousPage":{u.fetchPreviousPage();return}case"fetchNextPage":{u.fetchNextPage();return}}});return f(l=>{const{resultAtom:t}=l(b),e=l(t);if(e.isError)throw e.error;return e.data},(l,t,e)=>t(b,e))}}}});