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