jotai-tanstack-query
Version:
3 lines (2 loc) • 4.63 kB
JavaScript
!function(t,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("@tanstack/query-core"),require("jotai/vanilla"),require("jotai")):"function"==typeof define&&define.amd?define(["exports","@tanstack/query-core","jotai/vanilla","jotai"],r):r((t||self).jotaiTanstackQuery={},t.queryCore,t.vanilla,t.jotai)}(this,function(t,r,n,e){var o=n.atom(new r.QueryClient);function u(){return u=Object.assign?Object.assign.bind():function(t){for(var r=1;r<arguments.length;r++){var n=arguments[r];for(var e in n)Object.prototype.hasOwnProperty.call(n,e)&&(t[e]=n[e])}return t},u.apply(this,arguments)}function i(t,r){return"function"==typeof t?t.apply(void 0,r):!!t}"production"!==process.env.NODE_ENV&&(o.debugPrivate=!0);var a=function(t,r){return void 0===r.state.data};function c(t,n,a){void 0===a&&(a=function(t){return t(o)});var c=e.atom(0),s=e.atom(a);"production"!==process.env.NODE_ENV&&(s.debugPrivate=!0);var f=e.atom(function(){return new WeakMap});"production"!==process.env.NODE_ENV&&(f.debugPrivate=!0);var v=e.atom(function(r){var n=r(s),e=t(r),o=n.defaultQueryOptions(e),i=r(f).get(n);return o._optimisticResults="optimistic",i&&i.setOptions(o,{listeners:!1}),function(t){return t.suspense&&"number"!=typeof t.staleTime?u({},t,{staleTime:1e3}):t}(o)});"production"!==process.env.NODE_ENV&&(v.debugPrivate=!0);var p=e.atom(function(t){var r=t(s),e=t(v),o=t(f),u=o.get(r);if(u)return u;var i=new n(r,e);return o.set(r,i),i});"production"!==process.env.NODE_ENV&&(p.debugPrivate=!0);var d=e.atom(function(t){var n=t(p),o=t(v),u=n.getOptimisticResult(o),i=e.atom(u);return"production"!==process.env.NODE_ENV&&(i.debugPrivate=!0),i.onMount=function(t){var e=n.subscribe(r.notifyManager.batchCalls(t));return function(){n.getCurrentResult().isError&&n.getCurrentQuery().reset(),e()}},i});return"production"!==process.env.NODE_ENV&&(d.debugPrivate=!0),e.atom(function(t){t(c);var r=t(p),n=t(v),e=t(t(d));if(function(t,r,n){return(null==t?void 0:t.suspense)&&function(t,r){return t.isPending&&!0}(r)}(n,e))return r.fetchOptimistic(n);if(function(t){var r=t.result;return r.isError&&!r.isFetching&&i(t.throwOnError,[r.error,t.query])}({result:e,query:r.getCurrentQuery(),throwOnError:n.throwOnError}))throw e.error;return e},function(t,r){r(c,function(t){return t+1})})}function s(){}t.atomWithInfiniteQuery=function(t,n){return void 0===n&&(n=function(t){return t(o)}),c(t,r.InfiniteQueryObserver,n)},t.atomWithMutation=function(t,n){void 0===n&&(n=function(t){return t(o)});var a=Symbol(),c=e.atom(function(r){var e=n(r),o=t(r);return e.defaultMutationOptions(o)});"production"!==process.env.NODE_ENV&&(c.debugPrivate=!0);var f=e.atom(function(){return new WeakMap});"production"!==process.env.NODE_ENV&&(f.debugPrivate=!0);var v=e.atom(function(t){var e=t(c),o=n(t),u=t(f),i=u.get(o);if(i)return i[a]=!0,i.setOptions(e),delete i[a],i;var s=new r.MutationObserver(o,e);return u.set(o,s),s});"production"!==process.env.NODE_ENV&&(v.debugPrivate=!0);var p=e.atom(function(t){var n=t(v),o=n.getCurrentResult(),u=e.atom(o);return u.onMount=function(t){return n.subscribe(r.notifyManager.batchCalls(t)),function(){n.reset()}},"production"!==process.env.NODE_ENV&&(u.debugPrivate=!0),u}),d=e.atom(function(t){var r=t(v);return function(t,n){r.mutate(t,n).catch(s)}});return"production"!==process.env.NODE_ENV&&(d.debugPrivate=!0),e.atom(function(t){var r=t(v),n=t(p),e=t(n),o=t(d);if(e.isError&&i(r.options.throwOnError,[e.error]))throw e.error;return u({},e,{mutate:o,mutateAsync:e.mutate})})},t.atomWithMutationState=function(t,r){void 0===r&&(r=function(t){return t(o)});var n=e.atom([]);"production"!==process.env.NODE_ENV&&(n.debugPrivate=!0);var u=e.atom(function(e){var o=r(e).getMutationCache();n.onMount=function(n){var u=o.subscribe(function(){n(function(t,r){return t.findAll(r.filters).map(function(t){return r.select?r.select(t):t.state})}(r(e).getMutationCache(),t(e)))});return u}});return"production"!==process.env.NODE_ENV&&(u.debugPrivate=!0),e.atom(function(t){return t(u),t(n)})},t.atomWithQuery=function(t,n){return void 0===n&&(n=function(t){return t(o)}),c(t,r.QueryObserver,n)},t.atomWithSuspenseInfiniteQuery=function(t,n){void 0===n&&(n=function(t){return t(o)});var i=e.atom(function(r){return u({},t(r),{enabled:!0,suspense:!0,throwOnError:a})});return c(function(t){return t(i)},r.InfiniteQueryObserver,n)},t.atomWithSuspenseQuery=function(t,n){void 0===n&&(n=function(t){return t(o)});var i=e.atom(function(r){return u({},t(r),{suspense:!0,enabled:!0,throwOnError:a})});return c(function(t){return t(i)},r.QueryObserver,n)},t.queryClientAtom=o});
//# sourceMappingURL=index.umd.js.map