@tanstack/react-query-persist-client 4.0.2 → 4.0.8
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/build/cjs/react-query-persist-client/src/PersistQueryClientProvider.js +3 -3
- package/build/cjs/react-query-persist-client/src/PersistQueryClientProvider.js.map +1 -1
- package/build/esm/index.js +9 -269
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats.json +53 -85
- package/build/umd/index.development.js +14 -274
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +2 -22
- package/build/umd/index.production.js.map +1 -1
- package/package.json +1 -1
- package/build/cjs/react-query/build/esm/index.js +0 -301
- package/build/cjs/react-query/build/esm/index.js.map +0 -1
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*
|
|
9
9
|
* @license MIT
|
|
10
10
|
*/
|
|
11
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react"),require("
|
|
11
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react"),require("@tanstack/react-query")):"function"==typeof define&&define.amd?define(["exports","react","@tanstack/react-query"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).ReactQueryPersistClient={},e.React,e.ReactQuery)}(this,(function(e,t,n){"use strict";function s(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(n){if("default"!==n){var s=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,s.get?s:{enumerable:!0,get:function(){return e[n]}})}})),t.default=e,Object.freeze(t)}var i=s(t);
|
|
12
12
|
/**
|
|
13
13
|
* query-core
|
|
14
14
|
*
|
|
@@ -18,25 +18,5 @@
|
|
|
18
18
|
* LICENSE.md file in the root directory of this source tree.
|
|
19
19
|
*
|
|
20
20
|
* @license MIT
|
|
21
|
-
*/class
|
|
22
|
-
/**
|
|
23
|
-
* react-query
|
|
24
|
-
*
|
|
25
|
-
* Copyright (c) TanStack
|
|
26
|
-
*
|
|
27
|
-
* This source code is licensed under the MIT license found in the
|
|
28
|
-
* LICENSE.md file in the root directory of this source tree.
|
|
29
|
-
*
|
|
30
|
-
* @license MIT
|
|
31
|
-
*/
|
|
32
|
-
/**
|
|
33
|
-
* query-core
|
|
34
|
-
*
|
|
35
|
-
* Copyright (c) TanStack
|
|
36
|
-
*
|
|
37
|
-
* This source code is licensed under the MIT license found in the
|
|
38
|
-
* LICENSE.md file in the root directory of this source tree.
|
|
39
|
-
*
|
|
40
|
-
* @license MIT
|
|
41
|
-
*/new class extends i{constructor(){super(),this.setup=e=>{if(!r&&window.addEventListener){const t=()=>e();return window.addEventListener("online",t,!1),window.addEventListener("offline",t,!1),()=>{window.removeEventListener("online",t),window.removeEventListener("offline",t)}}}}onSubscribe(){this.cleanup||this.setEventListener(this.setup)}onUnsubscribe(){var e;this.hasListeners()||(null==(e=this.cleanup)||e.call(this),this.cleanup=void 0)}setEventListener(e){var t;this.setup=e,null==(t=this.cleanup)||t.call(this),this.cleanup=e((e=>{"boolean"==typeof e?this.setOnline(e):this.onOnline()}))}setOnline(e){this.online=e,e&&this.onOnline()}onOnline(){this.listeners.forEach((e=>{e()}))}isOnline(){return"boolean"==typeof this.online?this.online:"undefined"==typeof navigator||void 0===navigator.onLine||navigator.onLine}};class p{constructor(){this.listeners=[],this.subscribe=this.subscribe.bind(this)}subscribe(e){return this.listeners.push(e),this.onSubscribe(),()=>{this.listeners=this.listeners.filter((t=>t!==e)),this.onUnsubscribe()}}hasListeners(){return this.listeners.length>0}onSubscribe(){}onUnsubscribe(){}}const v="undefined"==typeof window;new class extends p{constructor(){super(),this.setup=e=>{if(!v&&window.addEventListener){const t=()=>e();return window.addEventListener("visibilitychange",t,!1),window.addEventListener("focus",t,!1),()=>{window.removeEventListener("visibilitychange",t),window.removeEventListener("focus",t)}}}}onSubscribe(){this.cleanup||this.setEventListener(this.setup)}onUnsubscribe(){var e;this.hasListeners()||(null==(e=this.cleanup)||e.call(this),this.cleanup=void 0)}setEventListener(e){var t;this.setup=e,null==(t=this.cleanup)||t.call(this),this.cleanup=e((e=>{"boolean"==typeof e?this.setFocused(e):this.onFocus()}))}setFocused(e){this.focused=e,e&&this.onFocus()}onFocus(){this.listeners.forEach((e=>{e()}))}isFocused(){return"boolean"==typeof this.focused?this.focused:"undefined"==typeof document||[void 0,"visible","prerender"].includes(document.visibilityState)}};new class extends p{constructor(){super(),this.setup=e=>{if(!v&&window.addEventListener){const t=()=>e();return window.addEventListener("online",t,!1),window.addEventListener("offline",t,!1),()=>{window.removeEventListener("online",t),window.removeEventListener("offline",t)}}}}onSubscribe(){this.cleanup||this.setEventListener(this.setup)}onUnsubscribe(){var e;this.hasListeners()||(null==(e=this.cleanup)||e.call(this),this.cleanup=void 0)}setEventListener(e){var t;this.setup=e,null==(t=this.cleanup)||t.call(this),this.cleanup=e((e=>{"boolean"==typeof e?this.setOnline(e):this.onOnline()}))}setOnline(e){this.online=e,e&&this.onOnline()}onOnline(){this.listeners.forEach((e=>{e()}))}isOnline(){return"boolean"==typeof this.online?this.online:"undefined"==typeof navigator||void 0===navigator.onLine||navigator.onLine}};const b=s.createContext(void 0),y=s.createContext(!1);const w=({client:e,children:t,context:n,contextSharing:i=!1})=>{s.useEffect((()=>(e.mount(),()=>{e.unmount()})),[e]);const r=function(e,t){return e||(t&&"undefined"!=typeof window?(window.ReactQueryClientContext||(window.ReactQueryClientContext=b),window.ReactQueryClientContext):b)}(n,i);return s.createElement(y.Provider,{value:!n&&i},s.createElement(r.Provider,{value:e},t))},E=s.createContext(!1).Provider;e.PersistQueryClientProvider=({client:e,children:t,persistOptions:n,onSuccess:i,...r})=>{const[o,u]=s.useState(!0),c=s.useRef({persistOptions:n,onSuccess:i});return s.useEffect((()=>{c.current={persistOptions:n,onSuccess:i}})),s.useEffect((()=>{let t=!1;u(!0);const[n,s]=d({...c.current.persistOptions,queryClient:e});return s.then((()=>{t||(null==c.current.onSuccess||c.current.onSuccess(),u(!1))})),()=>{t=!0,n()}}),[e]),s.createElement(w,f({client:e},r),s.createElement(E,{value:o},t))},e.persistQueryClient=d,e.persistQueryClientRestore=a,e.persistQueryClientSave=l,e.persistQueryClientSubscribe=h,e.removeOldestQuery=({persistedClient:e})=>{const t=[...e.clientState.mutations],n=[...e.clientState.queries],s={...e,clientState:{mutations:t,queries:n}},i=[...n].sort(((e,t)=>e.state.dataUpdatedAt-t.state.dataUpdatedAt));if(i.length>0){const e=i.shift();return s.clientState.queries=n.filter((t=>t!==e)),s}},Object.defineProperty(e,"__esModule",{value:!0})}));
|
|
21
|
+
*/class r{constructor(){this.listeners=[],this.subscribe=this.subscribe.bind(this)}subscribe(e){return this.listeners.push(e),this.onSubscribe(),()=>{this.listeners=this.listeners.filter((t=>t!==e)),this.onUnsubscribe()}}hasListeners(){return this.listeners.length>0}onSubscribe(){}onUnsubscribe(){}}const u="undefined"==typeof window;new class extends r{constructor(){super(),this.setup=e=>{if(!u&&window.addEventListener){const t=()=>e();return window.addEventListener("visibilitychange",t,!1),window.addEventListener("focus",t,!1),()=>{window.removeEventListener("visibilitychange",t),window.removeEventListener("focus",t)}}}}onSubscribe(){this.cleanup||this.setEventListener(this.setup)}onUnsubscribe(){var e;this.hasListeners()||(null==(e=this.cleanup)||e.call(this),this.cleanup=void 0)}setEventListener(e){var t;this.setup=e,null==(t=this.cleanup)||t.call(this),this.cleanup=e((e=>{"boolean"==typeof e?this.setFocused(e):this.onFocus()}))}setFocused(e){this.focused=e,e&&this.onFocus()}onFocus(){this.listeners.forEach((e=>{e()}))}isFocused(){return"boolean"==typeof this.focused?this.focused:"undefined"==typeof document||[void 0,"visible","prerender"].includes(document.visibilityState)}};function o(e){return e.state.isPaused}function a(e){return"success"===e.state.status}function c(e,t={}){const n=[],s=[];if(!1!==t.dehydrateMutations){const s=t.shouldDehydrateMutation||o;e.getMutationCache().getAll().forEach((e=>{s(e)&&n.push(function(e){return{mutationKey:e.options.mutationKey,state:e.state}}(e))}))}if(!1!==t.dehydrateQueries){const n=t.shouldDehydrateQuery||a;e.getQueryCache().getAll().forEach((e=>{n(e)&&s.push(function(e){return{state:e.state,queryKey:e.queryKey,queryHash:e.queryHash}}(e))}))}return{mutations:n,queries:s}}async function l({queryClient:e,persister:t,maxAge:n=864e5,buster:s="",hydrateOptions:i}){try{const r=await t.restoreClient();if(r)if(r.timestamp){const u=Date.now()-r.timestamp>n,o=r.buster!==s;u||o?t.removeClient():function(e,t,n){if("object"!=typeof t||null===t)return;const s=e.getMutationCache(),i=e.getQueryCache(),r=t.mutations||[],u=t.queries||[];r.forEach((t=>{var i;s.build(e,{...null==n||null==(i=n.defaultOptions)?void 0:i.mutations,mutationKey:t.mutationKey},t.state)})),u.forEach((t=>{var s;const r=i.get(t.queryHash);r?r.state.dataUpdatedAt<t.state.dataUpdatedAt&&r.setState(t.state):i.build(e,{...null==n||null==(s=n.defaultOptions)?void 0:s.queries,queryKey:t.queryKey,queryHash:t.queryHash},t.state)}))}(e,r.clientState,i)}else t.removeClient()}catch(e){t.removeClient()}}async function d({queryClient:e,persister:t,buster:n="",dehydrateOptions:s}){const i={buster:n,timestamp:Date.now(),clientState:c(e,s)};await t.persistClient(i)}function h(e){const t=e.queryClient.getQueryCache().subscribe((()=>{d(e)})),n=e.queryClient.getMutationCache().subscribe((()=>{d(e)}));return()=>{t(),n()}}function f(e){let t,n=!1;return[()=>{n=!0,null==t||t()},l(e).then((()=>{n||(t=h(e))}))]}function p(){return p=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var s in n)Object.prototype.hasOwnProperty.call(n,s)&&(e[s]=n[s])}return e},p.apply(this,arguments)}new class extends r{constructor(){super(),this.setup=e=>{if(!u&&window.addEventListener){const t=()=>e();return window.addEventListener("online",t,!1),window.addEventListener("offline",t,!1),()=>{window.removeEventListener("online",t),window.removeEventListener("offline",t)}}}}onSubscribe(){this.cleanup||this.setEventListener(this.setup)}onUnsubscribe(){var e;this.hasListeners()||(null==(e=this.cleanup)||e.call(this),this.cleanup=void 0)}setEventListener(e){var t;this.setup=e,null==(t=this.cleanup)||t.call(this),this.cleanup=e((e=>{"boolean"==typeof e?this.setOnline(e):this.onOnline()}))}setOnline(e){this.online=e,e&&this.onOnline()}onOnline(){this.listeners.forEach((e=>{e()}))}isOnline(){return"boolean"==typeof this.online?this.online:"undefined"==typeof navigator||void 0===navigator.onLine||navigator.onLine}};e.PersistQueryClientProvider=({client:e,children:t,persistOptions:s,onSuccess:r,...u})=>{const[o,a]=i.useState(!0),c=i.useRef({persistOptions:s,onSuccess:r});return i.useEffect((()=>{c.current={persistOptions:s,onSuccess:r}})),i.useEffect((()=>{let t=!1;a(!0);const[n,s]=f({...c.current.persistOptions,queryClient:e});return s.then((()=>{t||(null==c.current.onSuccess||c.current.onSuccess(),a(!1))})),()=>{t=!0,n()}}),[e]),i.createElement(n.QueryClientProvider,p({client:e},u),i.createElement(n.IsRestoringProvider,{value:o},t))},e.persistQueryClient=f,e.persistQueryClientRestore=l,e.persistQueryClientSave=d,e.persistQueryClientSubscribe=h,e.removeOldestQuery=({persistedClient:e})=>{const t=[...e.clientState.mutations],n=[...e.clientState.queries],s={...e,clientState:{mutations:t,queries:n}},i=[...n].sort(((e,t)=>e.state.dataUpdatedAt-t.state.dataUpdatedAt));if(i.length>0){const e=i.shift();return s.clientState.queries=n.filter((t=>t!==e)),s}},Object.defineProperty(e,"__esModule",{value:!0})}));
|
|
42
22
|
//# sourceMappingURL=index.production.js.map
|