UNPKG

5.65 kBJavaScriptView Raw
1var e=Object.defineProperty,t=Object.defineProperties,r=Object.getOwnPropertyDescriptors,n=Object.getOwnPropertySymbols,u=Object.prototype.hasOwnProperty,o=Object.prototype.propertyIsEnumerable,i=(t,r,n)=>r in t?e(t,r,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[r]=n,s=(e,t)=>{for(var r in t||(t={}))u.call(t,r)&&i(e,r,t[r]);if(n)for(var r of n(t))o.call(t,r)&&i(e,r,t[r]);return e},c=(e,n)=>t(e,r(n));import{coreModule as a,buildCreateApi as l}from"@reduxjs/toolkit/query";import{createSelector as p}from"@reduxjs/toolkit";import{useCallback as d,useEffect as f,useLayoutEffect as b,useMemo as y,useRef as m,useState as v}from"react";import{QueryStatus as h,skipToken as O}from"@reduxjs/toolkit/query";import{shallowEqual as S}from"react-redux";import{useEffect as g,useRef as Q}from"react";import{shallowEqual as j}from"react-redux";function k(e){const t=Q(e);return g((()=>{j(t.current,e)||(t.current=e)}),[e]),j(t.current,e)?t.current:e}var x,w,L=Symbol(),R="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement?b:f,q=e=>e,z=e=>e,F=(e,t)=>{let r=e.isSuccess?e.data:null==t?void 0:t.data;void 0===r&&(r=e.data);const n=void 0!==r,u=e.isLoading,o=!n&&u,i=e.isSuccess||u&&n;return c(s({},e),{data:r,isFetching:u,isLoading:o,isSuccess:i})},P=e=>e.isUninitialized?c(s({},e),{isUninitialized:!1,isFetching:!0,isLoading:void 0===e.data,status:h.pending}):e;function E(e){return e.replace(e[0],e[0].toUpperCase())}function I(e,...t){Object.assign(e,...t)}(w=x||(x={})).query="query",w.mutation="mutation";import{useDispatch as D,useSelector as M,useStore as A,batch as H}from"react-redux";var U=Symbol(),$=({batch:e=H,useDispatch:t=D,useSelector:r=M,useStore:n=A}={})=>({name:U,init(u,o,i){const a=u,{buildQueryHooks:l,buildMutationHook:b,usePrefetch:h}=function({api:e,moduleOptions:{batch:t,useDispatch:r,useSelector:n,useStore:u}}){return{buildQueryHooks:function(o){const i=(t,{refetchOnReconnect:n,refetchOnFocus:u,refetchOnMountOrArgChange:i,skip:s=!1,pollingInterval:c=0}={})=>{const{initiate:a}=e.endpoints[o],l=r(),p=k(s?O:t),d=k({refetchOnReconnect:n,refetchOnFocus:u,pollingInterval:c}),b=m();return f((()=>{var e;const t=b.current;if(p===O)return null==t||t.unsubscribe(),void(b.current=void 0);const r=null==(e=b.current)?void 0:e.subscriptionOptions;if(t&&t.arg===p)d!==r&&t.updateSubscriptionOptions(d);else{null==t||t.unsubscribe();const e=l(a(p,{subscriptionOptions:d,forceRefetch:i}));b.current=e}}),[l,a,i,p,d]),f((()=>()=>{var e;null==(e=b.current)||e.unsubscribe(),b.current=void 0}),[]),y((()=>({refetch:()=>{var e;null==(e=b.current)||e.refetch()}})),[])},a=({refetchOnReconnect:n,refetchOnFocus:u,pollingInterval:i=0}={})=>{const{initiate:s}=e.endpoints[o],c=r(),[a,l]=v(L),p=m(),b=k({refetchOnReconnect:n,refetchOnFocus:u,pollingInterval:i});f((()=>{var e,t;const r=null==(e=p.current)?void 0:e.subscriptionOptions;b!==r&&(null==(t=p.current)||t.updateSubscriptionOptions(b))}),[b]);const h=m(b);f((()=>{h.current=b}),[b]);const O=d((function(e,r=!1){t((()=>{var t;null==(t=p.current)||t.unsubscribe(),p.current=c(s(e,{subscriptionOptions:h.current,forceRefetch:!r})),l(e)}))}),[c,s]);return f((()=>()=>{var e;null==(e=null==p?void 0:p.current)||e.unsubscribe()}),[]),f((()=>{a===L||p.current||O(a,!0)}),[a,O]),y((()=>[O,a]),[O,a])},l=(t,{skip:r=!1,selectFromResult:i=q}={})=>{const{select:s}=e.endpoints[o],c=k(r?O:t),a=m(),l=y((()=>p([s(c),(e,t)=>t],F)),[s,c]),d=y((()=>p([l],i)),[l,i]),f=n((e=>d(e,a.current)),S),b=u(),v=l(b.getState(),a.current);return R((()=>{a.current=v}),[v]),f};return{useQueryState:l,useQuerySubscription:i,useLazyQuerySubscription:a,useLazyQuery(e){const[t,r]=a(e),n=l(r,c(s({},e),{skip:r===L})),u=y((()=>({lastArg:r})),[r]);return y((()=>[t,n,u]),[t,n,u])},useQuery(e,t){const r=i(e,t),n=l(e,s({selectFromResult:e===O||(null==t?void 0:t.skip)?void 0:P},t));return y((()=>s(s({},n),r)),[n,r])}}},buildMutationHook:function(u){return({selectFromResult:o=z}={})=>{var i;const{select:a,initiate:l}=e.endpoints[u],b=r(),[h,g]=v(),Q=m();f((()=>()=>{var e;null==(e=Q.current)||e.unsubscribe(),Q.current=void 0}),[]);const j=d((function(e){let r;return t((()=>{var t;null==(t=null==Q?void 0:Q.current)||t.unsubscribe(),r=b(l(e)),Q.current=r,g(r.requestId)})),r}),[b,l]),k=y((()=>p([a(h||O)],(e=>o(e)))),[a,h,o]),x=n(k,S),w=null==(i=Q.current)?void 0:i.arg.originalArgs,L=y((()=>c(s({},x),{originalArgs:w})),[x,w]);return y((()=>[j,L]),[j,L])}},usePrefetch:function(t,n){const u=r(),o=k(n);return d(((r,n)=>u(e.util.prefetch(t,r,s(s({},o),n)))),[t,u,o])}}}({api:u,moduleOptions:{batch:e,useDispatch:t,useSelector:r,useStore:n}});return I(a,{usePrefetch:h}),I(i,{batch:e}),{injectEndpoint(e,t){if(t.type===x.query){const{useQuery:t,useLazyQuery:r,useLazyQuerySubscription:n,useQueryState:o,useQuerySubscription:i}=l(e);I(a.endpoints[e],{useQuery:t,useLazyQuery:r,useLazyQuerySubscription:n,useQueryState:o,useQuerySubscription:i}),u[`use${E(e)}Query`]=t,u[`useLazy${E(e)}Query`]=r}else if(t.type===x.mutation){const t=b(e);I(a.endpoints[e],{useMutation:t}),u[`use${E(e)}Mutation`]=t}}}}});export*from"@reduxjs/toolkit/query";import{configureStore as C}from"@reduxjs/toolkit";import B from"react";import{Provider as G}from"react-redux";import{setupListeners as J}from"@reduxjs/toolkit/query";function K(e){const[t]=B.useState((()=>C({reducer:{[e.api.reducerPath]:e.api.reducer},middleware:t=>t().concat(e.api.middleware)})));return J(t.dispatch,e.setupListeners),B.createElement(G,{store:t,context:e.context},e.children)}var N=l(a(),$());export{K as ApiProvider,N as createApi,$ as reactHooksModule};
2//# sourceMappingURL=rtk-query-react.modern.production.min.js.map
\No newline at end of file