import r from"@babel/runtime/helpers/asyncToGenerator";import e from"@babel/runtime/helpers/slicedToArray";import t from"@babel/runtime/regenerator";import{identity as n,debounce as a,clone as o}from"lodash";import{useState as i,useRef as s,useCallback as u}from"react";function c(c){var l=c.loadFn,p=c.getDataFromResponseFn,d=void 0===p?n((function(r){return r})):p,f=c.initialLoading,m=void 0===f||f,v=c.initialData,b=void 0===v?null:v,h=c.isCacheEnabled,g=void 0!==h&&h,x=i(m),y=e(x,2),D=y[0],k=y[1],w=i(b),F=e(w,2),L=F[0],A=F[1],T=i(null),C=e(T,2),E=C[0],G=C[1],I=s({}),J=u(a(r(t.mark((function r(){var e,n,a,i,s,u,c=arguments;return t.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:for(k(!0),r.prev=1,e=c.length,n=new Array(e),a=0;a<e;a++)n[a]=c[a];if(i=JSON.stringify(n),!I.current[i]||!g){r.next=7;break}return A(o(I.current[i])),r.abrupt("return");case 7:return r.next=9,l.apply(void 0,n);case 9:s=r.sent,u=d(s),A(u),g&&(I.current[i]=u),r.next=19;break;case 15:r.prev=15,r.t0=r.catch(1),G(r.t0),console.error(r.t0);case 19:return r.prev=19,k(!1),r.finish(19);case 22:case"end":return r.stop()}}),r,null,[[1,15,19,22]])}))),500),[d,l,g]);return{isLoading:D,data:L,error:E,loadData:J,setData:A,setIsLoading:k}}export{c as default};
