Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@ahooksjs/use-request

Package Overview
Dependencies
Maintainers
4
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ahooksjs/use-request - npm Package Compare versions

Comparing version 2.0.2 to 2.1.0-beta

2

dist/ahooks-use-request.js

@@ -1,1 +0,1 @@

!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("React")):"function"==typeof define&&define.amd?define(["React"],e):"object"==typeof exports?exports.ahooksUseRequest=e(require("React")):t.ahooksUseRequest=e(t.React)}(this,(function(t){return function(t){var e={};function n(r){if(e[r])return e[r].exports;var i=e[r]={i:r,l:!1,exports:{}};return t[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var i in t)n.d(r,i,function(e){return t[e]}.bind(null,i));return r},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=4)}([function(e,n){e.exports=t},function(t,e){var n;n=function(){return this}();try{n=n||new Function("return this")()}catch(t){"object"==typeof window&&(n=window)}t.exports=n},function(t,e,n){(function(e){var n=/^\s+|\s+$/g,r=/^[-+]0x[0-9a-f]+$/i,i=/^0b[01]+$/i,o=/^0o[0-7]+$/i,u=parseInt,a="object"==typeof e&&e&&e.Object===Object&&e,c="object"==typeof self&&self&&self.Object===Object&&self,s=a||c||Function("return this")(),f=Object.prototype.toString,l=Math.max,d=Math.min,h=function(){return s.Date.now()};function v(t){var e=typeof t;return!!t&&("object"==e||"function"==e)}function p(t){if("number"==typeof t)return t;if(function(t){return"symbol"==typeof t||function(t){return!!t&&"object"==typeof t}(t)&&"[object Symbol]"==f.call(t)}(t))return NaN;if(v(t)){var e="function"==typeof t.valueOf?t.valueOf():t;t=v(e)?e+"":e}if("string"!=typeof t)return 0===t?t:+t;t=t.replace(n,"");var a=i.test(t);return a||o.test(t)?u(t.slice(2),a?2:8):r.test(t)?NaN:+t}t.exports=function(t,e,n){var r,i,o,u,a,c,s=0,f=!1,g=!1,b=!0;if("function"!=typeof t)throw new TypeError("Expected a function");function y(e){var n=r,o=i;return r=i=void 0,s=e,u=t.apply(o,n)}function m(t){return s=t,a=setTimeout(j,e),f?y(t):u}function O(t){var n=t-c;return void 0===c||n>=e||n<0||g&&t-s>=o}function j(){var t=h();if(O(t))return w(t);a=setTimeout(j,function(t){var n=e-(t-c);return g?d(n,o-(t-s)):n}(t))}function w(t){return a=void 0,b&&r?y(t):(r=i=void 0,u)}function T(){var t=h(),n=O(t);if(r=arguments,i=this,c=t,n){if(void 0===a)return m(c);if(g)return a=setTimeout(j,e),y(c)}return void 0===a&&(a=setTimeout(j,e)),u}return e=p(e)||0,v(n)&&(f=!!n.leading,o=(g="maxWait"in n)?l(p(n.maxWait)||0,e):o,b="trailing"in n?!!n.trailing:b),T.cancel=function(){void 0!==a&&clearTimeout(a),s=0,r=c=i=a=void 0},T.flush=function(){return void 0===a?u:w(h())},T}}).call(this,n(1))},function(t,e,n){(function(e){var n=/^\s+|\s+$/g,r=/^[-+]0x[0-9a-f]+$/i,i=/^0b[01]+$/i,o=/^0o[0-7]+$/i,u=parseInt,a="object"==typeof e&&e&&e.Object===Object&&e,c="object"==typeof self&&self&&self.Object===Object&&self,s=a||c||Function("return this")(),f=Object.prototype.toString,l=Math.max,d=Math.min,h=function(){return s.Date.now()};function v(t,e,n){var r,i,o,u,a,c,s=0,f=!1,v=!1,b=!0;if("function"!=typeof t)throw new TypeError("Expected a function");function y(e){var n=r,o=i;return r=i=void 0,s=e,u=t.apply(o,n)}function m(t){return s=t,a=setTimeout(j,e),f?y(t):u}function O(t){var n=t-c;return void 0===c||n>=e||n<0||v&&t-s>=o}function j(){var t=h();if(O(t))return w(t);a=setTimeout(j,function(t){var n=e-(t-c);return v?d(n,o-(t-s)):n}(t))}function w(t){return a=void 0,b&&r?y(t):(r=i=void 0,u)}function T(){var t=h(),n=O(t);if(r=arguments,i=this,c=t,n){if(void 0===a)return m(c);if(v)return a=setTimeout(j,e),y(c)}return void 0===a&&(a=setTimeout(j,e)),u}return e=g(e)||0,p(n)&&(f=!!n.leading,o=(v="maxWait"in n)?l(g(n.maxWait)||0,e):o,b="trailing"in n?!!n.trailing:b),T.cancel=function(){void 0!==a&&clearTimeout(a),s=0,r=c=i=a=void 0},T.flush=function(){return void 0===a?u:w(h())},T}function p(t){var e=typeof t;return!!t&&("object"==e||"function"==e)}function g(t){if("number"==typeof t)return t;if(function(t){return"symbol"==typeof t||function(t){return!!t&&"object"==typeof t}(t)&&"[object Symbol]"==f.call(t)}(t))return NaN;if(p(t)){var e="function"==typeof t.valueOf?t.valueOf():t;t=p(e)?e+"":e}if("string"!=typeof t)return 0===t?t:+t;t=t.replace(n,"");var a=i.test(t);return a||o.test(t)?u(t.slice(2),a?2:8):r.test(t)?NaN:+t}t.exports=function(t,e,n){var r=!0,i=!0;if("function"!=typeof t)throw new TypeError("Expected a function");return p(n)&&(r="leading"in n?!!n.leading:r,i="trailing"in n?!!n.trailing:i),v(t,e,{leading:r,maxWait:e,trailing:i})}}).call(this,n(1))},function(t,e,n){"use strict";n.r(e),n.d(e,"useAsync",(function(){return E})),n.d(e,"usePaginated",(function(){return R})),n.d(e,"useLoadMore",(function(){return S})),n.d(e,"UseRequestProvider",(function(){return P})),n.d(e,"UseAPIProvider",(function(){return M}));function r(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(r=Object.getOwnPropertySymbols(t);i<r.length;i++)e.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(t,r[i])&&(n[r[i]]=t[r[i]])}return n}var i=n(0),o=n.n(i),u=n(2),a=n.n(u),c=n(3),s=n.n(c);function f(){return"undefined"==typeof document||void 0===document.visibilityState||"hidden"!==document.visibilityState}var l=new Map,d=function(t){var e=l.get(t);return{data:null==e?void 0:e.data,startTime:null==e?void 0:e.startTime}};var h=function(t){var e=Object(i.useRef)((function(){throw new Error("Cannot call an event handler while rendering.")}));e.current=t;var n=Object(i.useCallback)((function(){var t=e.current;if(t)return t.apply(void 0,arguments)}),[e]);if("function"==typeof t)return n},v=function(t,e){var n=Object(i.useRef)(!1);Object(i.useEffect)((function(){if(n.current)return t();n.current=!0}),e)},p=[];var g=!1;if("undefined"!=typeof window&&window.addEventListener&&!g){var b=function(){if(f()&&(void 0===navigator.onLine||navigator.onLine))for(var t=0;t<p.length;t++){(0,p[t])()}};window.addEventListener("visibilitychange",b,!1),window.addEventListener("focus",b,!1),g=!0}var y=function(t){return p.push(t),function(){var e=p.indexOf(t);p.splice(e,1)}},m=[];var O=!1;if("undefined"!=typeof window&&window.addEventListener&&!O){window.addEventListener("visibilitychange",(function(){if(f())for(var t=0;t<m.length;t++){(0,m[t])()}}),!1),O=!0}var j=function(t){return m.push(t),function(){var e=m.indexOf(t);m.splice(e,1)}},w="AHOOKS_USE_REQUEST_DEFAULT_KEY",T=function(){function t(t,e,n,r){var i,o,u;this.count=0,this.unmountedFlag=!1,this.pollingWhenVisibleFlag=!1,this.pollingTimer=void 0,this.loadingDelayTimer=void 0,this.unsubscribe=[],this.that=this,this.state={loading:!1,params:[],data:void 0,error:void 0,run:this.run.bind(this.that),mutate:this.mutate.bind(this.that),refresh:this.refresh.bind(this.that),cancel:this.cancel.bind(this.that),unmount:this.unmount.bind(this.that)},this.service=t,this.config=e,this.subscribe=n,r&&(this.state=Object.assign(Object.assign({},this.state),r)),this.debounceRun=this.config.debounceInterval?a()(this._run,this.config.debounceInterval):void 0,this.throttleRun=this.config.throttleInterval?s()(this._run,this.config.throttleInterval):void 0,this.limitRefresh=(i=this.refresh.bind(this),o=this.config.focusTimespan,u=!1,function(){u||(u=!0,i.apply(void 0,arguments),setTimeout((function(){u=!1}),o))}),this.config.pollingInterval&&this.unsubscribe.push(j(this.rePolling.bind(this))),this.config.refreshOnWindowFocus&&this.unsubscribe.push(y(this.limitRefresh.bind(this)))}var e=t.prototype;return e.setState=function(t){void 0===t&&(t={}),this.state=Object.assign(Object.assign({},this.state),t),this.subscribe(this.state)},e._run=function(){for(var t=this,e=arguments.length,n=new Array(e),r=0;r<e;r++)n[r]=arguments[r];this.pollingTimer&&clearTimeout(this.pollingTimer),this.loadingDelayTimer&&clearTimeout(this.loadingDelayTimer),this.count+=1;var i=this.count;return this.setState({loading:!this.config.loadingDelay,params:n}),this.config.loadingDelay&&(this.loadingDelayTimer=setTimeout((function(){t.setState({loading:!0})}),this.config.loadingDelay)),this.service.apply(this,n).then((function(e){if(!t.unmountedFlag&&i===t.count){t.loadingDelayTimer&&clearTimeout(t.loadingDelayTimer);var r=t.config.formatResult?t.config.formatResult(e):e;return t.setState({data:r,error:void 0,loading:!1}),t.config.onSuccess&&t.config.onSuccess(r,n),r}})).catch((function(e){if(!t.unmountedFlag&&i===t.count){if(t.loadingDelayTimer&&clearTimeout(t.loadingDelayTimer),t.setState({data:void 0,error:e,loading:!1}),t.config.onError&&t.config.onError(e,n),t.config.throwOnError)throw e;return console.error(e),Promise.reject("useRequest has caught the exception, if you need to handle the exception yourself, you can set options.throwOnError to true.")}})).finally((function(){if(!t.unmountedFlag&&i===t.count&&t.config.pollingInterval){if(!f()&&!t.config.pollingWhenHidden)return void(t.pollingWhenVisibleFlag=!0);t.pollingTimer=setTimeout((function(){t._run.apply(t,n)}),t.config.pollingInterval)}}))},e.run=function(){return this.debounceRun?(this.debounceRun.apply(this,arguments),Promise.resolve(null)):this.throttleRun?(this.throttleRun.apply(this,arguments),Promise.resolve(null)):this._run.apply(this,arguments)},e.cancel=function(){this.debounceRun&&this.debounceRun.cancel(),this.throttleRun&&this.throttleRun.cancel(),this.loadingDelayTimer&&clearTimeout(this.loadingDelayTimer),this.pollingTimer&&clearTimeout(this.pollingTimer),this.pollingWhenVisibleFlag=!1,this.count+=1,this.setState({loading:!1})},e.refresh=function(){return this.run.apply(this,this.state.params)},e.rePolling=function(){this.pollingWhenVisibleFlag&&(this.pollingWhenVisibleFlag=!1,this.refresh())},e.mutate=function(t){"function"==typeof t?this.setState({data:t(this.state.data)||{}}):this.setState({data:t})},e.unmount=function(){this.unmountedFlag=!0,this.cancel(),this.unsubscribe.forEach((function(t){t()}))},t}();var E=function(t,e){var n,r=e||{},o=r.refreshDeps,u=void 0===o?[]:o,a=r.manual,c=void 0!==a&&a,s=r.onSuccess,f=void 0===s?function(){}:s,p=r.onError,g=void 0===p?function(){}:p,b=r.defaultLoading,y=void 0!==b&&b,m=r.loadingDelay,O=r.pollingInterval,j=void 0===O?0:O,E=r.pollingWhenHidden,S=void 0===E||E,R=r.defaultParams,x=void 0===R?[]:R,D=r.refreshOnWindowFocus,P=void 0!==D&&D,M=r.focusTimespan,C=void 0===M?5e3:M,F=r.fetchKey,k=r.cacheKey,I=r.cacheTime,W=void 0===I?3e5:I,_=r.staleTime,K=void 0===_?0:_,L=r.debounceInterval,N=r.throttleInterval,q=r.initialData,z=r.ready,U=void 0===z||z,$=r.throwOnError,A=void 0!==$&&$,H=Object(i.useRef)(w),V=h(t),Y=h(f),Q=h(g),B=h(F);"formatResult"in r&&(n=r.formatResult);var G={formatResult:h(n),onSuccess:Y,onError:Q,loadingDelay:m,pollingInterval:j,pollingWhenHidden:S,refreshOnWindowFocus:P,focusTimespan:C,debounceInterval:L,throttleInterval:N,throwOnError:A},J=h((function(t,e){tt((function(n){return n[t]=e,Object.assign({},n)}))})),X=Object(i.useState)((function(){var t;if(k){var e=null===(t=d(k))||void 0===t?void 0:t.data;if(e){H.current=e.newstFetchKey;var n={};return Object.keys(e.fetches).forEach((function(t){var r=e.fetches[t],i=new T(V,G,J.bind(null,t),{loading:r.loading,params:r.params,data:r.data,error:r.error});n[t]=i.state})),n}}return[]})),Z=X[0],tt=X[1],et=Object(i.useRef)(Z);et.current=Z;var nt=Object(i.useRef)(),rt=Object(i.useCallback)((function(){for(var t,e=arguments.length,n=new Array(e),r=0;r<e;r++)n[r]=arguments[r];if(U){if(B){var i=B.apply(void 0,n);H.current=void 0===i?w:i}var o=H.current,u=et.current[o];if(!u){var a=new T(V,G,J.bind(null,o),{data:q});u=a.state,tt((function(t){return t[o]=u,Object.assign({},t)}))}return(t=u).run.apply(t,n)}nt.current=n}),[F,J,U]),it=Object(i.useRef)(rt);it.current=rt,v((function(){k&&function(t,e,n){var r,i=l.get(t);(null==i?void 0:i.timer)&&clearTimeout(i.timer),e>-1&&(r=setTimeout((function(){l.delete(t)}),e)),l.set(t,{data:n,timer:r,startTime:(new Date).getTime()})}(k,W,{fetches:Z,newstFetchKey:H.current})}),[k,Z]);var ot=Object(i.useRef)(!1);v((function(){U&&(!ot.current&&nt.current&&it.current.apply(it,nt.current),ot.current=!0)}),[U]),Object(i.useEffect)((function(){var t;if(!c)if(Object.keys(Z).length>0){var e=(null===(t=d(k))||void 0===t?void 0:t.startTime)||0;-1===K||(new Date).getTime()-e<=K||Object.values(Z).forEach((function(t){t.refresh()}))}else it.current.apply(it,x)}),[]);var ut=Object(i.useCallback)((function(){Object.values(et.current).forEach((function(t){t.unmount()})),H.current=w,tt({}),et.current={}}),[tt]);v((function(){c||Object.values(et.current).forEach((function(t){t.refresh()}))}),[].concat(u)),Object(i.useEffect)((function(){return function(){Object.values(et.current).forEach((function(t){t.unmount()}))}}),[]);var at=Object(i.useCallback)((function(t){return function(){throw new Error("Cannot call "+t+" when service not executed once.")}}),[]);return Object.assign(Object.assign({loading:U&&!c||y,data:q,error:void 0,params:[],cancel:at("cancel"),refresh:at("refresh"),mutate:at("mutate")},Z[H.current]||{}),{run:rt,fetches:Z,reset:ut})};var S=function(t,e){var n=e.refreshDeps,o=void 0===n?[]:n,u=e.ref,a=e.isNoMore,c=e.threshold,s=void 0===c?100:c,f=(e.fetchKey,r(e,["refreshDeps","ref","isNoMore","threshold","fetchKey"])),l=Object(i.useState)(!1),d=l[0],h=l[1];Object(i.useEffect)((function(){e.fetchKey&&console.warn("useRequest loadMore mode don't need fetchKey!")}),[]);var p=E(t,Object.assign(Object.assign({},f),{fetchKey:function(t){var e;return(null===(e=null==t?void 0:t.list)||void 0===e?void 0:e.length)||0},onSuccess:function(){h(!1),e.onSuccess&&e.onSuccess.apply(e,arguments)}})),g=p.data,b=p.run,y=p.params,m=p.reset,O=p.loading,j=p.fetches,w=Object(i.useCallback)((function(){m();var t=y.slice(1);b.apply(void 0,[void 0].concat(t))}),[b,m,y]),T=Object(i.useRef)(w);T.current=w,v((function(){e.manual||T.current()}),[].concat(o));var S=Object(i.useMemo)((function(){var t=[],e=g;return Object.values(j).forEach((function(n){var r,i;(null===(r=n.data)||void 0===r?void 0:r.list)&&(t=t.concat(null===(i=n.data)||void 0===i?void 0:i.list)),n.loading||(e=n.data)})),Object.assign(Object.assign({},e),{list:t})}),[j,g]),R=!!a&&(!O&&!d&&a(S)),x=Object(i.useCallback)((function(){if(!R){h(!0);var t=y.slice(1);b.apply(void 0,[S].concat(t))}}),[R,b,S,y]),D=Object(i.useCallback)((function(){!O&&!d&&u&&u.current&&u.current.scrollHeight-u.current.scrollTop<=u.current.clientHeight+s&&x()}),[O,u,x]);return Object(i.useEffect)((function(){return u&&u.current?(u.current.addEventListener("scroll",D),function(){u&&u.current&&u.current.removeEventListener("scroll",D)}):function(){}}),[D]),Object.assign(Object.assign({},p),{data:S,reload:w,loading:O&&0===S.list.length,loadMore:x,loadingMore:d,noMore:R})};var R=function(t,e){e.paginated;var n=e.defaultPageSize,o=void 0===n?10:n,u=e.refreshDeps,a=void 0===u?[]:u,c=e.fetchKey,s=r(e,["paginated","defaultPageSize","refreshDeps","fetchKey"]);Object(i.useEffect)((function(){c&&console.error("useRequest pagination's fetchKey will not work!")}),[]);var f=E(t,Object.assign({defaultParams:[{current:1,pageSize:o}]},s)),l=f.data,d=f.params,h=f.run,p=f.loading,g=r(f,["data","params","run","loading"]),b=d&&d[0]?d[0]:{},y=b.current,m=void 0===y?1:y,O=b.pageSize,j=void 0===O?o:O,w=b.sorter,T=void 0===w?{}:w,S=b.filters,R=void 0===S?{}:S,x=Object(i.useCallback)((function(t){var e=d[0],n=d.slice(1);h.apply(void 0,[Object.assign(Object.assign({},e),t)].concat(n))}),[h,d]),D=(null==l?void 0:l.total)||0,P=Object(i.useMemo)((function(){return Math.ceil(D/j)}),[j,D]),M=Object(i.useCallback)((function(t,e){var n=t<=0?1:t,r=e<=0?1:e,i=Math.ceil(D/r);n>i&&(n=i),x({current:t,pageSize:e})}),[D,x]),C=Object(i.useCallback)((function(t){M(t,j)}),[M,j]),F=Object(i.useCallback)((function(t){M(m,t)}),[M,m]),k=Object(i.useRef)(C);k.current=C,v((function(){e.manual||k.current(1)}),[].concat(a));var I=Object(i.useCallback)((function(t,e,n){x({current:t.current,pageSize:t.pageSize||o,filters:e,sorter:n})}),[R,T,x]);return Object.assign({loading:p,data:l,params:d,run:h,pagination:{current:m,pageSize:j,total:D,totalPage:P,onChange:M,changeCurrent:C,changePageSize:F},tableProps:{dataSource:(null==l?void 0:l.list)||[],loading:p,onChange:I,pagination:{current:m,pageSize:j,total:D}},sorter:T,filters:R},g)},x=o.a.createContext({});x.displayName="UseRequestConfigContext";var D=x;var P=D.Provider,M=P;e.default=function(t,e){void 0===e&&(e={});var n=Object(i.useContext)(D),o=Object.assign(Object.assign({},n),e),u=o.paginated,a=o.loadMore,c=o.requestMethod,s=Object(i.useRef)(u),f=Object(i.useRef)(a);if(s.current!==u)throw Error("You should not modify the paginated of options");if(f.current!==a)throw Error("You should not modify the loadMore of options");s.current=u,f.current=a;var l,d=function(){return fetch.apply(void 0,arguments).then((function(t){if(t.ok)return t.json();throw new Error(t.statusText)}))},h=c||d;if("string"==typeof t)l=function(){return h(t)};else if("object"==typeof t){var v=t.url,p=r(t,["url"]);l=function(){return c?c(t):d(v,p)}}else l=function(){for(var e=arguments.length,n=new Array(e),i=0;i<e;i++)n[i]=arguments[i];return new Promise((function(e,i){var o=t.apply(void 0,n);if(o.then)o.then((function(t){return e(t)})).catch((function(t){return i(t)}));else if("string"==typeof o)h(o).then((function(t){e(t)})).catch((function(t){return i(t)}));else if("object"==typeof o)if(c)c(o).then((function(t){e(t)})).catch((function(t){return i(t)}));else{var u=o.url,a=r(o,["url"]);d(u,a).then((function(t){e(t)})).catch((function(t){return i(t)}))}}))};return a?S(l,o):u?R(l,o):E(l,o)}}])}));
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("React")):"function"==typeof define&&define.amd?define(["React"],e):"object"==typeof exports?exports.ahooksUseRequest=e(require("React")):t.ahooksUseRequest=e(t.React)}(this,(function(t){return function(t){var e={};function n(r){if(e[r])return e[r].exports;var o=e[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)n.d(r,o,function(e){return t[e]}.bind(null,o));return r},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=4)}([function(e,n){e.exports=t},function(t,e){var n;n=function(){return this}();try{n=n||new Function("return this")()}catch(t){"object"==typeof window&&(n=window)}t.exports=n},function(t,e,n){(function(e){var n=/^\s+|\s+$/g,r=/^[-+]0x[0-9a-f]+$/i,o=/^0b[01]+$/i,i=/^0o[0-7]+$/i,a=parseInt,u="object"==typeof e&&e&&e.Object===Object&&e,c="object"==typeof self&&self&&self.Object===Object&&self,l=u||c||Function("return this")(),f=Object.prototype.toString,s=Math.max,d=Math.min,h=function(){return l.Date.now()};function v(t){var e=typeof t;return!!t&&("object"==e||"function"==e)}function p(t){if("number"==typeof t)return t;if(function(t){return"symbol"==typeof t||function(t){return!!t&&"object"==typeof t}(t)&&"[object Symbol]"==f.call(t)}(t))return NaN;if(v(t)){var e="function"==typeof t.valueOf?t.valueOf():t;t=v(e)?e+"":e}if("string"!=typeof t)return 0===t?t:+t;t=t.replace(n,"");var u=o.test(t);return u||i.test(t)?a(t.slice(2),u?2:8):r.test(t)?NaN:+t}t.exports=function(t,e,n){var r,o,i,a,u,c,l=0,f=!1,y=!1,b=!0;if("function"!=typeof t)throw new TypeError("Expected a function");function g(e){var n=r,i=o;return r=o=void 0,l=e,a=t.apply(i,n)}function m(t){return l=t,u=setTimeout(j,e),f?g(t):a}function O(t){var n=t-c;return void 0===c||n>=e||n<0||y&&t-l>=i}function j(){var t=h();if(O(t))return w(t);u=setTimeout(j,function(t){var n=e-(t-c);return y?d(n,i-(t-l)):n}(t))}function w(t){return u=void 0,b&&r?g(t):(r=o=void 0,a)}function S(){var t=h(),n=O(t);if(r=arguments,o=this,c=t,n){if(void 0===u)return m(c);if(y)return u=setTimeout(j,e),g(c)}return void 0===u&&(u=setTimeout(j,e)),a}return e=p(e)||0,v(n)&&(f=!!n.leading,i=(y="maxWait"in n)?s(p(n.maxWait)||0,e):i,b="trailing"in n?!!n.trailing:b),S.cancel=function(){void 0!==u&&clearTimeout(u),l=0,r=c=o=u=void 0},S.flush=function(){return void 0===u?a:w(h())},S}}).call(this,n(1))},function(t,e,n){(function(e){var n=/^\s+|\s+$/g,r=/^[-+]0x[0-9a-f]+$/i,o=/^0b[01]+$/i,i=/^0o[0-7]+$/i,a=parseInt,u="object"==typeof e&&e&&e.Object===Object&&e,c="object"==typeof self&&self&&self.Object===Object&&self,l=u||c||Function("return this")(),f=Object.prototype.toString,s=Math.max,d=Math.min,h=function(){return l.Date.now()};function v(t,e,n){var r,o,i,a,u,c,l=0,f=!1,v=!1,b=!0;if("function"!=typeof t)throw new TypeError("Expected a function");function g(e){var n=r,i=o;return r=o=void 0,l=e,a=t.apply(i,n)}function m(t){return l=t,u=setTimeout(j,e),f?g(t):a}function O(t){var n=t-c;return void 0===c||n>=e||n<0||v&&t-l>=i}function j(){var t=h();if(O(t))return w(t);u=setTimeout(j,function(t){var n=e-(t-c);return v?d(n,i-(t-l)):n}(t))}function w(t){return u=void 0,b&&r?g(t):(r=o=void 0,a)}function S(){var t=h(),n=O(t);if(r=arguments,o=this,c=t,n){if(void 0===u)return m(c);if(v)return u=setTimeout(j,e),g(c)}return void 0===u&&(u=setTimeout(j,e)),a}return e=y(e)||0,p(n)&&(f=!!n.leading,i=(v="maxWait"in n)?s(y(n.maxWait)||0,e):i,b="trailing"in n?!!n.trailing:b),S.cancel=function(){void 0!==u&&clearTimeout(u),l=0,r=c=o=u=void 0},S.flush=function(){return void 0===u?a:w(h())},S}function p(t){var e=typeof t;return!!t&&("object"==e||"function"==e)}function y(t){if("number"==typeof t)return t;if(function(t){return"symbol"==typeof t||function(t){return!!t&&"object"==typeof t}(t)&&"[object Symbol]"==f.call(t)}(t))return NaN;if(p(t)){var e="function"==typeof t.valueOf?t.valueOf():t;t=p(e)?e+"":e}if("string"!=typeof t)return 0===t?t:+t;t=t.replace(n,"");var u=o.test(t);return u||i.test(t)?a(t.slice(2),u?2:8):r.test(t)?NaN:+t}t.exports=function(t,e,n){var r=!0,o=!0;if("function"!=typeof t)throw new TypeError("Expected a function");return p(n)&&(r="leading"in n?!!n.leading:r,o="trailing"in n?!!n.trailing:o),v(t,e,{leading:r,maxWait:e,trailing:o})}}).call(this,n(1))},function(t,e,n){"use strict";n.r(e),n.d(e,"useAsync",(function(){return M})),n.d(e,"usePaginated",(function(){return q})),n.d(e,"useLoadMore",(function(){return W})),n.d(e,"UseRequestProvider",(function(){return Y})),n.d(e,"UseAPIProvider",(function(){return Q}));var r=n(0),o=n.n(r),i=n(2),a=n.n(i),u=n(3),c=n.n(u);function l(){return"undefined"==typeof document||void 0===document.visibilityState||"hidden"!==document.visibilityState}var f=new Map,s=function(t){var e=f.get(t);return{data:null==e?void 0:e.data,startTime:null==e?void 0:e.startTime}},d=function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,o,i=n.call(t),a=[];try{for(;(void 0===e||e-- >0)&&!(r=i.next()).done;)a.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return a},h=function(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(d(arguments[e]));return t};var v=function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,o,i=n.call(t),a=[];try{for(;(void 0===e||e-- >0)&&!(r=i.next()).done;)a.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return a},p=function(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(v(arguments[e]));return t};var y=function(t){var e=Object(r.useRef)((function(){throw new Error("Cannot call an event handler while rendering.")}));e.current=t;var n=Object(r.useCallback)((function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];var r=e.current;if(r)return r.apply(void 0,p(t))}),[e]);if("function"==typeof t)return n},b=function(t,e){var n=Object(r.useRef)(!1);Object(r.useEffect)((function(){if(n.current)return t();n.current=!0}),e)},g=[];var m=!1;if("undefined"!=typeof window&&window.addEventListener&&!m){var O=function(){if(l()&&(void 0===navigator.onLine||navigator.onLine))for(var t=0;t<g.length;t++){(0,g[t])()}};window.addEventListener("visibilitychange",O,!1),window.addEventListener("focus",O,!1),m=!0}var j=function(t){return g.push(t),function(){var e=g.indexOf(t);g.splice(e,1)}},w=[];var S=!1;if("undefined"!=typeof window&&window.addEventListener&&!S){window.addEventListener("visibilitychange",(function(){if(l())for(var t=0;t<w.length;t++){(0,w[t])()}}),!1),S=!0}var T=function(t){return w.push(t),function(){var e=w.indexOf(t);w.splice(e,1)}},x=function(){return(x=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t}).apply(this,arguments)},E=function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,o,i=n.call(t),a=[];try{for(;(void 0===e||e-- >0)&&!(r=i.next()).done;)a.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return a},R=function(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(E(arguments[e]));return t},P="AHOOKS_USE_REQUEST_DEFAULT_KEY",D=function(){function t(t,e,n,r){var o,i,u;this.count=0,this.unmountedFlag=!1,this.pollingWhenVisibleFlag=!1,this.pollingTimer=void 0,this.loadingDelayTimer=void 0,this.unsubscribe=[],this.that=this,this.state={loading:!1,params:[],data:void 0,error:void 0,run:this.run.bind(this.that),mutate:this.mutate.bind(this.that),refresh:this.refresh.bind(this.that),cancel:this.cancel.bind(this.that),unmount:this.unmount.bind(this.that)},this.service=t,this.config=e,this.subscribe=n,r&&(this.state=x(x({},this.state),r)),this.debounceRun=this.config.debounceInterval?a()(this._run,this.config.debounceInterval):void 0,this.throttleRun=this.config.throttleInterval?c()(this._run,this.config.throttleInterval):void 0,this.limitRefresh=(o=this.refresh.bind(this),i=this.config.focusTimespan,u=!1,function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];u||(u=!0,o.apply(void 0,h(t)),setTimeout((function(){u=!1}),i))}),this.config.pollingInterval&&this.unsubscribe.push(T(this.rePolling.bind(this))),this.config.refreshOnWindowFocus&&this.unsubscribe.push(j(this.limitRefresh.bind(this)))}return t.prototype.setState=function(t){void 0===t&&(t={}),this.state=x(x({},this.state),t),this.subscribe(this.state)},t.prototype._run=function(){for(var t=this,e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];this.pollingTimer&&clearTimeout(this.pollingTimer),this.loadingDelayTimer&&clearTimeout(this.loadingDelayTimer),this.count+=1;var r=this.count;return this.setState({loading:!this.config.loadingDelay,params:e}),this.config.loadingDelay&&(this.loadingDelayTimer=setTimeout((function(){t.setState({loading:!0})}),this.config.loadingDelay)),this.service.apply(this,R(e)).then((function(n){if(!t.unmountedFlag&&r===t.count){t.loadingDelayTimer&&clearTimeout(t.loadingDelayTimer);var o=t.config.formatResult?t.config.formatResult(n):n;return t.setState({data:o,error:void 0,loading:!1}),t.config.onSuccess&&t.config.onSuccess(o,e),o}})).catch((function(n){if(!t.unmountedFlag&&r===t.count){if(t.loadingDelayTimer&&clearTimeout(t.loadingDelayTimer),t.setState({data:void 0,error:n,loading:!1}),t.config.onError&&t.config.onError(n,e),t.config.throwOnError)throw n;return console.error(n),Promise.reject("useRequest has caught the exception, if you need to handle the exception yourself, you can set options.throwOnError to true.")}})).finally((function(){if(!t.unmountedFlag&&r===t.count&&t.config.pollingInterval){if(!l()&&!t.config.pollingWhenHidden)return void(t.pollingWhenVisibleFlag=!0);t.pollingTimer=setTimeout((function(){t._run.apply(t,R(e))}),t.config.pollingInterval)}}))},t.prototype.run=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return this.debounceRun?(this.debounceRun.apply(this,R(t)),Promise.resolve(null)):this.throttleRun?(this.throttleRun.apply(this,R(t)),Promise.resolve(null)):this._run.apply(this,R(t))},t.prototype.cancel=function(){this.debounceRun&&this.debounceRun.cancel(),this.throttleRun&&this.throttleRun.cancel(),this.loadingDelayTimer&&clearTimeout(this.loadingDelayTimer),this.pollingTimer&&clearTimeout(this.pollingTimer),this.pollingWhenVisibleFlag=!1,this.count+=1,this.setState({loading:!1})},t.prototype.refresh=function(){return this.run.apply(this,R(this.state.params))},t.prototype.rePolling=function(){this.pollingWhenVisibleFlag&&(this.pollingWhenVisibleFlag=!1,this.refresh())},t.prototype.mutate=function(t){"function"==typeof t?this.setState({data:t(this.state.data)||{}}):this.setState({data:t})},t.prototype.unmount=function(){this.unmountedFlag=!0,this.cancel(),this.unsubscribe.forEach((function(t){t()}))},t}();var M=function(t,e){var n,o=e||{},i=o.refreshDeps,a=void 0===i?[]:i,u=o.manual,c=void 0!==u&&u,l=o.onSuccess,d=void 0===l?function(){}:l,h=o.onError,v=void 0===h?function(){}:h,p=o.defaultLoading,g=void 0!==p&&p,m=o.loadingDelay,O=o.pollingInterval,j=void 0===O?0:O,w=o.pollingWhenHidden,S=void 0===w||w,T=o.defaultParams,M=void 0===T?[]:T,k=o.refreshOnWindowFocus,C=void 0!==k&&k,F=o.focusTimespan,I=void 0===F?5e3:F,W=o.fetchKey,_=o.cacheKey,K=o.cacheTime,L=void 0===K?3e5:K,N=o.staleTime,q=void 0===N?0:N,z=o.debounceInterval,U=o.throttleInterval,$=o.initialData,H=o.ready,V=void 0===H||H,A=o.throwOnError,Y=void 0!==A&&A,Q=Object(r.useRef)(P),B=y(t),G=y(d),J=y(v),X=y(W);"formatResult"in o&&(n=o.formatResult);var Z={formatResult:y(n),onSuccess:G,onError:J,loadingDelay:m,pollingInterval:j,pollingWhenHidden:S,refreshOnWindowFocus:C,focusTimespan:I,debounceInterval:z,throttleInterval:U,throwOnError:Y},tt=y((function(t,e){rt((function(n){return n[t]=e,x({},n)}))})),et=E(Object(r.useState)((function(){var t;if(_){var e=null===(t=s(_))||void 0===t?void 0:t.data;if(e){Q.current=e.newstFetchKey;var n={};return Object.keys(e.fetches).forEach((function(t){var r=e.fetches[t],o=new D(B,Z,tt.bind(null,t),{loading:r.loading,params:r.params,data:r.data,error:r.error});n[t]=o.state})),n}}return[]})),2),nt=et[0],rt=et[1],ot=Object(r.useRef)(nt);ot.current=nt;var it=Object(r.useRef)(),at=Object(r.useCallback)((function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];if(V){if(X){var n=X.apply(void 0,R(t));Q.current=void 0===n?P:n}var r=Q.current,o=ot.current[r];if(!o){var i=new D(B,Z,tt.bind(null,r),{data:$});o=i.state,rt((function(t){return t[r]=o,x({},t)}))}return o.run.apply(o,R(t))}it.current=t}),[W,tt,V]),ut=Object(r.useRef)(at);ut.current=at,b((function(){_&&function(t,e,n){var r,o=f.get(t);(null==o?void 0:o.timer)&&clearTimeout(o.timer),e>-1&&(r=setTimeout((function(){f.delete(t)}),e)),f.set(t,{data:n,timer:r,startTime:(new Date).getTime()})}(_,L,{fetches:nt,newstFetchKey:Q.current})}),[_,nt]);var ct=Object(r.useRef)(!1);b((function(){V&&(!ct.current&&it.current&&ut.current.apply(ut,R(it.current)),ct.current=!0)}),[V]),Object(r.useEffect)((function(){var t;if(!c)if(Object.keys(nt).length>0){var e=(null===(t=s(_))||void 0===t?void 0:t.startTime)||0;-1===q||(new Date).getTime()-e<=q||Object.values(nt).forEach((function(t){t.refresh()}))}else ut.current.apply(ut,R(M))}),[]);var lt=Object(r.useCallback)((function(){Object.values(ot.current).forEach((function(t){t.unmount()})),Q.current=P,rt({}),ot.current={}}),[rt]);b((function(){c||Object.values(ot.current).forEach((function(t){t.refresh()}))}),R(a)),Object(r.useEffect)((function(){return function(){Object.values(ot.current).forEach((function(t){t.unmount()}))}}),[]);var ft=Object(r.useCallback)((function(t){return function(){console.warn("You should't call "+t+" when service not executed once.")}}),[]);return x(x({loading:V&&!c||g,data:$,error:void 0,params:[],cancel:ft("cancel"),refresh:ft("refresh"),mutate:ft("mutate")},nt[Q.current]||{}),{run:at,fetches:nt,reset:lt})},k=function(){return(k=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t}).apply(this,arguments)},C=function(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(t);o<r.length;o++)e.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(t,r[o])&&(n[r[o]]=t[r[o]])}return n},F=function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,o,i=n.call(t),a=[];try{for(;(void 0===e||e-- >0)&&!(r=i.next()).done;)a.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return a},I=function(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(F(arguments[e]));return t};var W=function(t,e){var n=e.refreshDeps,o=void 0===n?[]:n,i=e.ref,a=e.isNoMore,u=e.threshold,c=void 0===u?100:u,l=(e.fetchKey,C(e,["refreshDeps","ref","isNoMore","threshold","fetchKey"])),f=F(Object(r.useState)(!1),2),s=f[0],d=f[1];Object(r.useEffect)((function(){e.fetchKey&&console.warn("useRequest loadMore mode don't need fetchKey!")}),[]);var h=M(t,k(k({},l),{fetchKey:function(t){var e;return(null===(e=null==t?void 0:t.list)||void 0===e?void 0:e.length)||0},onSuccess:function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];d(!1),e.onSuccess&&e.onSuccess.apply(e,I(t))}})),v=h.data,p=h.run,y=h.params,g=h.reset,m=h.loading,O=h.fetches,j=Object(r.useCallback)((function(){g();var t=F(y).slice(1);p.apply(void 0,I([void 0],t))}),[p,g,y]),w=Object(r.useRef)(j);w.current=j,b((function(){e.manual||w.current()}),I(o));var S=Object(r.useMemo)((function(){var t=[],e=v;return Object.values(O).forEach((function(n){var r,o;(null===(r=n.data)||void 0===r?void 0:r.list)&&(t=t.concat(null===(o=n.data)||void 0===o?void 0:o.list)),n.loading||(e=n.data)})),k(k({},e),{list:t})}),[O,v]),T=!!a&&(!m&&!s&&a(S)),x=Object(r.useCallback)((function(){if(!T){d(!0);var t=F(y).slice(1);p.apply(void 0,I([S],t))}}),[T,p,S,y]),E=Object(r.useCallback)((function(){!m&&!s&&i&&i.current&&i.current.scrollHeight-i.current.scrollTop<=i.current.clientHeight+c&&x()}),[m,i,x]);return Object(r.useEffect)((function(){return i&&i.current?(i.current.addEventListener("scroll",E),function(){i&&i.current&&i.current.removeEventListener("scroll",E)}):function(){}}),[E]),k(k({},h),{data:S,reload:j,loading:m&&0===S.list.length,loadMore:x,loadingMore:s,noMore:T})},_=function(){return(_=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t}).apply(this,arguments)},K=function(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(t);o<r.length;o++)e.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(t,r[o])&&(n[r[o]]=t[r[o]])}return n},L=function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,o,i=n.call(t),a=[];try{for(;(void 0===e||e-- >0)&&!(r=i.next()).done;)a.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return a},N=function(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(L(arguments[e]));return t};var q=function(t,e){e.paginated;var n=e.defaultPageSize,o=void 0===n?10:n,i=e.refreshDeps,a=void 0===i?[]:i,u=e.fetchKey,c=K(e,["paginated","defaultPageSize","refreshDeps","fetchKey"]);Object(r.useEffect)((function(){u&&console.error("useRequest pagination's fetchKey will not work!")}),[]);var l=M(t,_({defaultParams:[{current:1,pageSize:o}]},c)),f=l.data,s=l.params,d=l.run,h=l.loading,v=K(l,["data","params","run","loading"]),p=s&&s[0]?s[0]:{},y=p.current,g=void 0===y?1:y,m=p.pageSize,O=void 0===m?o:m,j=p.sorter,w=void 0===j?{}:j,S=p.filters,T=void 0===S?{}:S,x=Object(r.useCallback)((function(t){var e=L(s),n=e[0],r=e.slice(1);d.apply(void 0,N([_(_({},n),t)],r))}),[d,s]),E=(null==f?void 0:f.total)||0,R=Object(r.useMemo)((function(){return Math.ceil(E/O)}),[O,E]),P=Object(r.useCallback)((function(t,e){var n=t<=0?1:t,r=e<=0?1:e,o=Math.ceil(E/r);n>o&&(n=o),x({current:t,pageSize:e})}),[E,x]),D=Object(r.useCallback)((function(t){P(t,O)}),[P,O]),k=Object(r.useCallback)((function(t){P(g,t)}),[P,g]),C=Object(r.useRef)(D);C.current=D,b((function(){e.manual||C.current(1)}),N(a));var F=Object(r.useCallback)((function(t,e,n){x({current:t.current,pageSize:t.pageSize||o,filters:e,sorter:n})}),[T,w,x]);return _({loading:h,data:f,params:s,run:d,pagination:{current:g,pageSize:O,total:E,totalPage:R,onChange:P,changeCurrent:D,changePageSize:k},tableProps:{dataSource:(null==f?void 0:f.list)||[],loading:h,onChange:F,pagination:{current:g,pageSize:O,total:E}},sorter:w,filters:T},v)},z=o.a.createContext({});z.displayName="UseRequestConfigContext";var U=z,$=function(){return($=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t}).apply(this,arguments)},H=function(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(t);o<r.length;o++)e.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(t,r[o])&&(n[r[o]]=t[r[o]])}return n},V=function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,o,i=n.call(t),a=[];try{for(;(void 0===e||e-- >0)&&!(r=i.next()).done;)a.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return a},A=function(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(V(arguments[e]));return t};var Y=U.Provider,Q=Y;e.default=function(t,e){void 0===e&&(e={});var n=Object(r.useContext)(U),o=$($({},n),e),i=o.paginated,a=o.loadMore,u=o.requestMethod,c=Object(r.useRef)(i),l=Object(r.useRef)(a);if(c.current!==i)throw Error("You should not modify the paginated of options");if(l.current!==a)throw Error("You should not modify the loadMore of options");c.current=i,l.current=a;var f,s=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return fetch.apply(void 0,A(t)).then((function(t){if(t.ok)return t.json();throw new Error(t.statusText)}))},d=u||s;switch(typeof t){case"string":f=function(){return d(t)};break;case"object":var h=t.url,v=H(t,["url"]);f=function(){return u?u(t):s(h,v)};break;default:f=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return new Promise((function(n,r){var o=t.apply(void 0,A(e)),i=o;if(!o.then)switch(typeof o){case"string":i=d(o);break;case"object":var a=o.url,c=H(o,["url"]);i=u?u(o):s(a,c)}i.then(n).catch(r)}))}}return a?W(f,o):i?q(f,o):M(f,o)}}])}));

@@ -1,4 +0,67 @@

import { __rest } from "tslib";
var __assign = this && this.__assign || function () {
__assign = Object.assign || function (t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) {
if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
}
}
return t;
};
return __assign.apply(this, arguments);
};
var __rest = this && this.__rest || function (s, e) {
var t = {};
for (var p in s) {
if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
}
if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
}
return t;
};
var __read = this && this.__read || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o),
r,
ar = [],
e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) {
ar.push(r.value);
}
} catch (error) {
e = {
error: error
};
} finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
} finally {
if (e) throw e.error;
}
}
return ar;
};
var __spread = this && this.__spread || function () {
for (var ar = [], i = 0; i < arguments.length; i++) {
ar = ar.concat(__read(arguments[i]));
}
return ar;
};
/* eslint-disable react-hooks/rules-of-hooks */
import { useRef, useContext } from 'react';

@@ -16,3 +79,5 @@ import useAsync from './useAsync';

var contextConfig = useContext(ConfigContext);
var finalOptions = Object.assign(Object.assign({}, contextConfig), options);
var finalOptions = __assign(__assign({}, contextConfig), options);
var paginated = finalOptions.paginated,

@@ -36,11 +101,16 @@ loadMore = finalOptions.loadMore,

var fetchProxy = function fetchProxy() {
return (// @ts-ignore
fetch.apply(void 0, arguments).then(function (res) {
if (res.ok) {
return res.json();
}
var args = [];
throw new Error(res.statusText);
})
);
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
} // @ts-ignore
return fetch.apply(void 0, __spread(args)).then(function (res) {
if (res.ok) {
return res.json();
}
throw new Error(res.statusText);
});
};

@@ -51,55 +121,51 @@

if (typeof service === 'string') {
promiseService = function promiseService() {
return finalRequestMethod(service);
};
} else if (typeof service === 'object') {
var url = service.url,
rest = __rest(service, ["url"]);
switch (typeof service) {
case 'string':
promiseService = function promiseService() {
return finalRequestMethod(service);
};
promiseService = function promiseService() {
return requestMethod ? requestMethod(service) : fetchProxy(url, rest);
};
} else {
promiseService = function promiseService() {
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
break;
return new Promise(function (resolve, reject) {
var result = service.apply(void 0, args);
case 'object':
var url_1 = service.url,
rest_1 = __rest(service, ["url"]);
if (result.then) {
result.then(function (data) {
return resolve(data);
})["catch"](function (e) {
return reject(e);
});
} else if (typeof result === 'string') {
finalRequestMethod(result).then(function (data) {
resolve(data);
})["catch"](function (e) {
return reject(e);
});
} else if (typeof result === 'object') {
// fetch 需要拆分下字段
if (requestMethod) {
requestMethod(result).then(function (data) {
resolve(data);
})["catch"](function (e) {
return reject(e);
});
} else {
var _url = result.url,
_rest = __rest(result, ["url"]);
promiseService = function promiseService() {
return requestMethod ? requestMethod(service) : fetchProxy(url_1, rest_1);
};
fetchProxy(_url, _rest).then(function (data) {
resolve(data);
})["catch"](function (e) {
return reject(e);
});
break;
default:
promiseService = function promiseService() {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return new Promise(function (resolve, reject) {
var s = service.apply(void 0, __spread(args));
var fn = s;
if (!s.then) {
switch (typeof s) {
case 'string':
fn = finalRequestMethod(s);
break;
case 'object':
var url_2 = s.url,
rest_2 = __rest(s, ["url"]);
fn = requestMethod ? requestMethod(s) : fetchProxy(url_2, rest_2);
break;
}
}
}
});
};
fn.then(resolve)["catch"](reject);
});
};
}

@@ -106,0 +172,0 @@

@@ -0,1 +1,52 @@

var __assign = this && this.__assign || function () {
__assign = Object.assign || function (t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) {
if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
}
}
return t;
};
return __assign.apply(this, arguments);
};
var __read = this && this.__read || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o),
r,
ar = [],
e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) {
ar.push(r.value);
}
} catch (error) {
e = {
error: error
};
} finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
} finally {
if (e) throw e.error;
}
}
return ar;
};
var __spread = this && this.__spread || function () {
for (var ar = [], i = 0; i < arguments.length; i++) {
ar = ar.concat(__read(arguments[i]));
}
return ar;
};
import debounce from 'lodash.debounce';

@@ -13,3 +64,5 @@ import throttle from 'lodash.throttle';

var Fetch = /*#__PURE__*/function () {
var Fetch =
/** @class */
function () {
function Fetch(service, config, subscribe, initState) {

@@ -42,3 +95,3 @@ // 请求时序

if (initState) {
this.state = Object.assign(Object.assign({}, this.state), initState);
this.state = __assign(__assign({}, this.state), initState);
}

@@ -59,5 +112,3 @@

var _proto = Fetch.prototype;
_proto.setState = function setState(s) {
Fetch.prototype.setState = function (s) {
if (s === void 0) {

@@ -67,14 +118,16 @@ s = {};

this.state = Object.assign(Object.assign({}, this.state), s);
this.state = __assign(__assign({}, this.state), s);
this.subscribe(this.state);
};
_proto._run = function _run() {
Fetch.prototype._run = function () {
var _this = this;
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
var args = [];
// 取消已有定时器
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
} // 取消已有定时器
if (this.pollingTimer) {

@@ -105,3 +158,3 @@ clearTimeout(this.pollingTimer);

return this.service.apply(this, args).then(function (res) {
return this.service.apply(this, __spread(args)).then(function (res) {
if (!_this.unmountedFlag && currentCount === _this.count) {

@@ -162,3 +215,3 @@ if (_this.loadingDelayTimer) {

_this.pollingTimer = setTimeout(function () {
_this._run.apply(_this, args);
_this._run.apply(_this, __spread(args));
}, _this.config.pollingInterval);

@@ -170,5 +223,11 @@ }

_proto.run = function run() {
Fetch.prototype.run = function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
if (this.debounceRun) {
this.debounceRun.apply(this, arguments); // TODO 如果 options 存在 debounceInterval,或 throttleInterval,则 run 和 refresh 不会返回 Promise。 带类型需要修复后,此处变成 return;。
this.debounceRun.apply(this, __spread(args)); // TODO 如果 options 存在 debounceInterval,或 throttleInterval,则 run 和 refresh 不会返回 Promise。 带类型需要修复后,此处变成 return;。

@@ -179,10 +238,10 @@ return Promise.resolve(null);

if (this.throttleRun) {
this.throttleRun.apply(this, arguments);
this.throttleRun.apply(this, __spread(args));
return Promise.resolve(null);
}
return this._run.apply(this, arguments);
return this._run.apply(this, __spread(args));
};
_proto.cancel = function cancel() {
Fetch.prototype.cancel = function () {
if (this.debounceRun) {

@@ -211,7 +270,7 @@ this.debounceRun.cancel();

_proto.refresh = function refresh() {
return this.run.apply(this, this.state.params);
Fetch.prototype.refresh = function () {
return this.run.apply(this, __spread(this.state.params));
};
_proto.rePolling = function rePolling() {
Fetch.prototype.rePolling = function () {
if (this.pollingWhenVisibleFlag) {

@@ -223,3 +282,3 @@ this.pollingWhenVisibleFlag = false;

_proto.mutate = function mutate(data) {
Fetch.prototype.mutate = function (data) {
if (typeof data === 'function') {

@@ -237,3 +296,3 @@ this.setState({

_proto.unmount = function unmount() {
Fetch.prototype.unmount = function () {
this.unmountedFlag = true;

@@ -252,36 +311,36 @@ this.cancel();

var _options$refreshDeps = _options.refreshDeps,
refreshDeps = _options$refreshDeps === void 0 ? [] : _options$refreshDeps,
_options$manual = _options.manual,
manual = _options$manual === void 0 ? false : _options$manual,
_options$onSuccess = _options.onSuccess,
onSuccess = _options$onSuccess === void 0 ? function () {} : _options$onSuccess,
_options$onError = _options.onError,
onError = _options$onError === void 0 ? function () {} : _options$onError,
_options$defaultLoadi = _options.defaultLoading,
defaultLoading = _options$defaultLoadi === void 0 ? false : _options$defaultLoadi,
var _a = _options.refreshDeps,
refreshDeps = _a === void 0 ? [] : _a,
_b = _options.manual,
manual = _b === void 0 ? false : _b,
_c = _options.onSuccess,
onSuccess = _c === void 0 ? function () {} : _c,
_d = _options.onError,
onError = _d === void 0 ? function () {} : _d,
_e = _options.defaultLoading,
defaultLoading = _e === void 0 ? false : _e,
loadingDelay = _options.loadingDelay,
_options$pollingInter = _options.pollingInterval,
pollingInterval = _options$pollingInter === void 0 ? 0 : _options$pollingInter,
_options$pollingWhenH = _options.pollingWhenHidden,
pollingWhenHidden = _options$pollingWhenH === void 0 ? true : _options$pollingWhenH,
_options$defaultParam = _options.defaultParams,
defaultParams = _options$defaultParam === void 0 ? [] : _options$defaultParam,
_options$refreshOnWin = _options.refreshOnWindowFocus,
refreshOnWindowFocus = _options$refreshOnWin === void 0 ? false : _options$refreshOnWin,
_options$focusTimespa = _options.focusTimespan,
focusTimespan = _options$focusTimespa === void 0 ? 5000 : _options$focusTimespa,
_f = _options.pollingInterval,
pollingInterval = _f === void 0 ? 0 : _f,
_g = _options.pollingWhenHidden,
pollingWhenHidden = _g === void 0 ? true : _g,
_h = _options.defaultParams,
defaultParams = _h === void 0 ? [] : _h,
_j = _options.refreshOnWindowFocus,
refreshOnWindowFocus = _j === void 0 ? false : _j,
_k = _options.focusTimespan,
focusTimespan = _k === void 0 ? 5000 : _k,
fetchKey = _options.fetchKey,
cacheKey = _options.cacheKey,
_options$cacheTime = _options.cacheTime,
cacheTime = _options$cacheTime === void 0 ? 5 * 60 * 1000 : _options$cacheTime,
_options$staleTime = _options.staleTime,
staleTime = _options$staleTime === void 0 ? 0 : _options$staleTime,
_l = _options.cacheTime,
cacheTime = _l === void 0 ? 5 * 60 * 1000 : _l,
_m = _options.staleTime,
staleTime = _m === void 0 ? 0 : _m,
debounceInterval = _options.debounceInterval,
throttleInterval = _options.throttleInterval,
initialData = _options.initialData,
_options$ready = _options.ready,
ready = _options$ready === void 0 ? true : _options$ready,
_options$throwOnError = _options.throwOnError,
throwOnError = _options$throwOnError === void 0 ? false : _options$throwOnError;
_o = _options.ready,
ready = _o === void 0 ? true : _o,
_p = _options.throwOnError,
throwOnError = _p === void 0 ? false : _p;
var newstFetchKey = useRef(DEFAULT_KEY); // 持久化一些函数

@@ -318,7 +377,7 @@

s[key] = data;
return Object.assign({}, s);
return __assign({}, s);
});
});
var _useState = useState(function () {
var _q = __read(useState(function () {
var _a; // 如果有 缓存,则从缓存中读数据

@@ -328,11 +387,11 @@

if (cacheKey) {
var cacheData = (_a = getCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
var cacheData_1 = (_a = getCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
if (cacheData) {
newstFetchKey.current = cacheData.newstFetchKey;
if (cacheData_1) {
newstFetchKey.current = cacheData_1.newstFetchKey;
/* 使用 initState, 重新 new Fetch */
var newFetches = {};
Object.keys(cacheData.fetches).forEach(function (key) {
var cacheFetch = cacheData.fetches[key];
var newFetches_1 = {};
Object.keys(cacheData_1.fetches).forEach(function (key) {
var cacheFetch = cacheData_1.fetches[key];
var newFetch = new Fetch(servicePersist, config, subscribe.bind(null, key), {

@@ -344,5 +403,5 @@ loading: cacheFetch.loading,

});
newFetches[key] = newFetch.state;
newFetches_1[key] = newFetch.state;
});
return newFetches;
return newFetches_1;
}

@@ -352,5 +411,5 @@ }

return [];
}),
fetches = _useState[0],
setFeches = _useState[1];
}), 2),
fetches = _q[0],
setFeches = _q[1];

@@ -361,6 +420,6 @@ var fetchesRef = useRef(fetches);

var run = useCallback(function () {
var _currentFetch;
var args = [];
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
args[_key2] = arguments[_key2];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}

@@ -375,3 +434,3 @@

if (fetchKeyPersist) {
var key = fetchKeyPersist.apply(void 0, args);
var key = fetchKeyPersist.apply(void 0, __spread(args));
newstFetchKey.current = key === undefined ? DEFAULT_KEY : key;

@@ -393,7 +452,7 @@ }

s[currentFetchKey] = currentFetch;
return Object.assign({}, s);
return __assign({}, s);
});
}
return (_currentFetch = currentFetch).run.apply(_currentFetch, args);
return currentFetch.run.apply(currentFetch, __spread(args));
}, [fetchKey, subscribe, ready]);

@@ -416,3 +475,3 @@ var runRef = useRef(run);

if (!hasTriggeredByReady.current && readyMemoryParams.current) {
runRef.current.apply(runRef, readyMemoryParams.current);
runRef.current.apply(runRef, __spread(readyMemoryParams.current));
}

@@ -442,3 +501,3 @@

// 第一次默认执行,可以通过 defaultParams 设置参数
runRef.current.apply(runRef, defaultParams);
runRef.current.apply(runRef, __spread(defaultParams));
}

@@ -465,3 +524,3 @@ }

}
}, [].concat(refreshDeps)); // 卸载组件触发
}, __spread(refreshDeps)); // 卸载组件触发

@@ -477,6 +536,6 @@ useEffect(function () {

return function () {
throw new Error("Cannot call " + name + " when service not executed once.");
console.warn("You should't call " + name + " when service not executed once.");
};
}, []);
return Object.assign(Object.assign({
return __assign(__assign({
loading: ready && !manual || defaultLoading,

@@ -483,0 +542,0 @@ data: initialData,

@@ -1,2 +0,65 @@

import { __rest } from "tslib";
var __assign = this && this.__assign || function () {
__assign = Object.assign || function (t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) {
if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
}
}
return t;
};
return __assign.apply(this, arguments);
};
var __rest = this && this.__rest || function (s, e) {
var t = {};
for (var p in s) {
if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
}
if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
}
return t;
};
var __read = this && this.__read || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o),
r,
ar = [],
e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) {
ar.push(r.value);
}
} catch (error) {
e = {
error: error
};
} finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
} finally {
if (e) throw e.error;
}
}
return ar;
};
var __spread = this && this.__spread || function () {
for (var ar = [], i = 0; i < arguments.length; i++) {
ar = ar.concat(__read(arguments[i]));
}
return ar;
};
import { useRef, useCallback, useMemo, useEffect, useState } from 'react';

@@ -7,14 +70,14 @@ import useAsync from './useAsync';

function useLoadMore(service, options) {
var _options$refreshDeps = options.refreshDeps,
refreshDeps = _options$refreshDeps === void 0 ? [] : _options$refreshDeps,
var _a = options.refreshDeps,
refreshDeps = _a === void 0 ? [] : _a,
ref = options.ref,
isNoMore = options.isNoMore,
_options$threshold = options.threshold,
threshold = _options$threshold === void 0 ? 100 : _options$threshold,
_b = options.threshold,
threshold = _b === void 0 ? 100 : _b,
fetchKey = options.fetchKey,
restOptions = __rest(options, ["refreshDeps", "ref", "isNoMore", "threshold", "fetchKey"]);
var _useState = useState(false),
loadingMore = _useState[0],
setLoadingMore = _useState[1];
var _c = __read(useState(false), 2),
loadingMore = _c[0],
setLoadingMore = _c[1];

@@ -26,3 +89,3 @@ useEffect(function () {

}, []);
var result = useAsync(service, Object.assign(Object.assign({}, restOptions), {
var result = useAsync(service, __assign(__assign({}, restOptions), {
fetchKey: function fetchKey(d) {

@@ -34,6 +97,12 @@ var _a;

onSuccess: function onSuccess() {
var params = [];
for (var _i = 0; _i < arguments.length; _i++) {
params[_i] = arguments[_i];
}
setLoadingMore(false);
if (options.onSuccess) {
options.onSuccess.apply(options, arguments);
options.onSuccess.apply(options, __spread(params));
}

@@ -50,4 +119,7 @@ }

reset();
var restParams = params.slice(1);
run.apply(void 0, [undefined].concat(restParams));
var _a = __read(params),
restParams = _a.slice(1);
run.apply(void 0, __spread([undefined], restParams));
}, [run, reset, params]);

@@ -63,3 +135,3 @@ var reloadRef = useRef(reload);

}
}, [].concat(refreshDeps));
}, __spread(refreshDeps));
var dataGroup = useMemo(function () {

@@ -80,3 +152,3 @@ var listGroup = []; // 在 loadMore 时,不希望清空上一次的 data。需要把最后一个 非 loading 的请求 data,放回去。

});
return Object.assign(Object.assign({}, lastNoLoadingData), {
return __assign(__assign({}, lastNoLoadingData), {
list: listGroup

@@ -92,4 +164,7 @@ });

setLoadingMore(true);
var restParams = params.slice(1);
run.apply(void 0, [dataGroup].concat(restParams));
var _a = __read(params),
restParams = _a.slice(1);
run.apply(void 0, __spread([dataGroup], restParams));
}, [noMore, run, dataGroup, params]);

@@ -121,3 +196,3 @@ /* 上拉加载的方法 */

}, [scrollMethod]);
return Object.assign(Object.assign({}, result), {
return __assign(__assign({}, result), {
data: dataGroup,

@@ -124,0 +199,0 @@ reload: reload,

@@ -1,2 +0,65 @@

import { __rest } from "tslib";
var __assign = this && this.__assign || function () {
__assign = Object.assign || function (t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) {
if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
}
}
return t;
};
return __assign.apply(this, arguments);
};
var __rest = this && this.__rest || function (s, e) {
var t = {};
for (var p in s) {
if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
}
if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
}
return t;
};
var __read = this && this.__read || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o),
r,
ar = [],
e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) {
ar.push(r.value);
}
} catch (error) {
e = {
error: error
};
} finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
} finally {
if (e) throw e.error;
}
}
return ar;
};
var __spread = this && this.__spread || function () {
for (var ar = [], i = 0; i < arguments.length; i++) {
ar = ar.concat(__read(arguments[i]));
}
return ar;
};
import { useCallback, useEffect, useMemo, useRef } from 'react';

@@ -8,6 +71,6 @@ import useAsync from './useAsync';

var paginated = options.paginated,
_options$defaultPageS = options.defaultPageSize,
defaultPageSize = _options$defaultPageS === void 0 ? 10 : _options$defaultPageS,
_options$refreshDeps = options.refreshDeps,
refreshDeps = _options$refreshDeps === void 0 ? [] : _options$refreshDeps,
_a = options.defaultPageSize,
defaultPageSize = _a === void 0 ? 10 : _a,
_b = options.refreshDeps,
refreshDeps = _b === void 0 ? [] : _b,
fetchKey = options.fetchKey,

@@ -22,3 +85,3 @@ restOptions = __rest(options, ["paginated", "defaultPageSize", "refreshDeps", "fetchKey"]);

var _a = useAsync(service, Object.assign({
var _c = useAsync(service, __assign({
defaultParams: [{

@@ -29,23 +92,25 @@ current: 1,

}, restOptions)),
data = _a.data,
params = _a.params,
run = _a.run,
loading = _a.loading,
rest = __rest(_a, ["data", "params", "run", "loading"]);
data = _c.data,
params = _c.params,
run = _c.run,
loading = _c.loading,
rest = __rest(_c, ["data", "params", "run", "loading"]);
var _ref = params && params[0] ? params[0] : {},
_ref$current = _ref.current,
current = _ref$current === void 0 ? 1 : _ref$current,
_ref$pageSize = _ref.pageSize,
pageSize = _ref$pageSize === void 0 ? defaultPageSize : _ref$pageSize,
_ref$sorter = _ref.sorter,
sorter = _ref$sorter === void 0 ? {} : _ref$sorter,
_ref$filters = _ref.filters,
filters = _ref$filters === void 0 ? {} : _ref$filters; // 只改变 pagination,其他参数原样传递
var _d = params && params[0] ? params[0] : {},
_e = _d.current,
current = _e === void 0 ? 1 : _e,
_f = _d.pageSize,
pageSize = _f === void 0 ? defaultPageSize : _f,
_g = _d.sorter,
sorter = _g === void 0 ? {} : _g,
_h = _d.filters,
filters = _h === void 0 ? {} : _h; // 只改变 pagination,其他参数原样传递
var runChangePaination = useCallback(function (paginationParams) {
var oldPaginationParams = params[0],
restParams = params.slice(1);
run.apply(void 0, [Object.assign(Object.assign({}, oldPaginationParams), paginationParams)].concat(restParams));
var _a = __read(params),
oldPaginationParams = _a[0],
restParams = _a.slice(1);
run.apply(void 0, __spread([__assign(__assign({}, oldPaginationParams), paginationParams)], restParams));
}, [run, params]);

@@ -85,3 +150,3 @@ var total = (data === null || data === void 0 ? void 0 : data.total) || 0;

}
}, [].concat(refreshDeps)); // 表格翻页 排序 筛选等
}, __spread(refreshDeps)); // 表格翻页 排序 筛选等

@@ -96,3 +161,3 @@ var changeTable = useCallback(function (p, f, s) {

}, [filters, sorter, runChangePaination]);
return Object.assign({
return __assign({
loading: loading,

@@ -99,0 +164,0 @@ data: data,

@@ -1,2 +0,49 @@

import { __rest } from "tslib";
var __rest = this && this.__rest || function (s, e) {
var t = {};
for (var p in s) {
if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
}
if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
}
return t;
};
var __read = this && this.__read || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o),
r,
ar = [],
e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) {
ar.push(r.value);
}
} catch (error) {
e = {
error: error
};
} finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
} finally {
if (e) throw e.error;
}
}
return ar;
};
var __spread = this && this.__spread || function () {
for (var ar = [], i = 0; i < arguments.length; i++) {
ar = ar.concat(__read(arguments[i]));
}
return ar;
};
import request from 'umi-request';

@@ -13,16 +60,18 @@ import useAsync from './useAsync';

} else if (typeof service === 'object') {
var url = service.url,
rest = __rest(service, ["url"]);
var url_1 = service.url,
rest_1 = __rest(service, ["url"]);
promiseService = function promiseService() {
return request(url, rest);
return request(url_1, rest_1);
};
} else {
promiseService = function promiseService() {
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return new Promise(function (resolve) {
var result = service.apply(void 0, args);
var result = service.apply(void 0, __spread(args));

@@ -34,6 +83,6 @@ if (typeof result === 'string') {

} else if (typeof result === 'object') {
var _url = result.url,
_rest = __rest(result, ["url"]);
var url = result.url,
rest = __rest(result, ["url"]);
request(_url, _rest).then(function (data) {
request(url, rest).then(function (data) {
resolve(data);

@@ -40,0 +89,0 @@ });

@@ -0,5 +1,6 @@

declare type Timer = ReturnType<typeof setTimeout>;
export declare type CachedKeyType = string | number;
export declare type cachedData = {
data: any;
timer: ReturnType<typeof setTimeout>;
timer: Timer;
startTime: number;

@@ -6,0 +7,0 @@ };

@@ -0,7 +1,48 @@

var __read = this && this.__read || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o),
r,
ar = [],
e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) {
ar.push(r.value);
}
} catch (error) {
e = {
error: error
};
} finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
} finally {
if (e) throw e.error;
}
}
return ar;
};
var __spread = this && this.__spread || function () {
for (var ar = [], i = 0; i < arguments.length; i++) {
ar = ar.concat(__read(arguments[i]));
}
return ar;
};
export default function limit(fn, timespan) {
var pending = false;
return function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
if (pending) return;
pending = true;
fn.apply(void 0, arguments);
fn.apply(void 0, __spread(args));
setTimeout(function () {

@@ -8,0 +49,0 @@ pending = false;

@@ -0,1 +1,36 @@

var __read = this && this.__read || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o),
r,
ar = [],
e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) {
ar.push(r.value);
}
} catch (error) {
e = {
error: error
};
} finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
} finally {
if (e) throw e.error;
}
}
return ar;
};
var __spread = this && this.__spread || function () {
for (var ar = [], i = 0; i < arguments.length; i++) {
ar = ar.concat(__read(arguments[i]));
}
return ar;
};
import { useCallback, useRef } from 'react';

@@ -9,6 +44,12 @@

var persist = useCallback(function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
var refFn = ref.current;
if (refFn) {
return refFn.apply(void 0, arguments);
return refFn.apply(void 0, __spread(args));
}

@@ -15,0 +56,0 @@ }, [ref]);

"use strict";
var __importDefault = this && this.__importDefault || function (mod) {
return mod && mod.__esModule ? mod : {
"default": mod
};
};
Object.defineProperty(exports, "__esModule", {

@@ -7,8 +13,6 @@ value: true

var tslib_1 = require("tslib");
var react_1 = __importDefault(require("react"));
var react_1 = tslib_1.__importDefault(require("react"));
var ConfigContext = react_1["default"].createContext({});
ConfigContext.displayName = 'UseRequestConfigContext';
exports["default"] = ConfigContext;
"use strict";
var __assign = this && this.__assign || function () {
__assign = Object.assign || function (t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) {
if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
}
}
return t;
};
return __assign.apply(this, arguments);
};
var __rest = this && this.__rest || function (s, e) {
var t = {};
for (var p in s) {
if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
}
if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
}
return t;
};
var __read = this && this.__read || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o),
r,
ar = [],
e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) {
ar.push(r.value);
}
} catch (error) {
e = {
error: error
};
} finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
} finally {
if (e) throw e.error;
}
}
return ar;
};
var __spread = this && this.__spread || function () {
for (var ar = [], i = 0; i < arguments.length; i++) {
ar = ar.concat(__read(arguments[i]));
}
return ar;
};
var __importDefault = this && this.__importDefault || function (mod) {
return mod && mod.__esModule ? mod : {
"default": mod
};
};
Object.defineProperty(exports, "__esModule", {

@@ -7,22 +77,19 @@ value: true

exports.UseAPIProvider = exports.UseRequestProvider = exports.useLoadMore = exports.usePaginated = exports.useAsync = void 0;
var tslib_1 = require("tslib");
/* eslint-disable react-hooks/rules-of-hooks */
var react_1 = require("react");
var useAsync_1 = tslib_1.__importDefault(require("./useAsync"));
var useAsync_1 = __importDefault(require("./useAsync"));
exports.useAsync = useAsync_1["default"];
var useLoadMore_1 = tslib_1.__importDefault(require("./useLoadMore"));
var useLoadMore_1 = __importDefault(require("./useLoadMore"));
exports.useLoadMore = useLoadMore_1["default"];
var usePaginated_1 = tslib_1.__importDefault(require("./usePaginated"));
var usePaginated_1 = __importDefault(require("./usePaginated"));
exports.usePaginated = usePaginated_1["default"];
var configContext_1 = tslib_1.__importDefault(require("./configContext"));
var configContext_1 = __importDefault(require("./configContext"));

@@ -35,3 +102,5 @@ function useRequest(service, options) {

var contextConfig = react_1.useContext(configContext_1["default"]);
var finalOptions = Object.assign(Object.assign({}, contextConfig), options);
var finalOptions = __assign(__assign({}, contextConfig), options);
var paginated = finalOptions.paginated,

@@ -55,11 +124,16 @@ loadMore = finalOptions.loadMore,

var fetchProxy = function fetchProxy() {
return (// @ts-ignore
fetch.apply(void 0, arguments).then(function (res) {
if (res.ok) {
return res.json();
}
var args = [];
throw new Error(res.statusText);
})
);
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
} // @ts-ignore
return fetch.apply(void 0, __spread(args)).then(function (res) {
if (res.ok) {
return res.json();
}
throw new Error(res.statusText);
});
};

@@ -70,55 +144,51 @@

if (typeof service === 'string') {
promiseService = function promiseService() {
return finalRequestMethod(service);
};
} else if (typeof service === 'object') {
var url = service.url,
rest = tslib_1.__rest(service, ["url"]);
switch (typeof service) {
case 'string':
promiseService = function promiseService() {
return finalRequestMethod(service);
};
promiseService = function promiseService() {
return requestMethod ? requestMethod(service) : fetchProxy(url, rest);
};
} else {
promiseService = function promiseService() {
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
break;
return new Promise(function (resolve, reject) {
var result = service.apply(void 0, args);
case 'object':
var url_1 = service.url,
rest_1 = __rest(service, ["url"]);
if (result.then) {
result.then(function (data) {
return resolve(data);
})["catch"](function (e) {
return reject(e);
});
} else if (typeof result === 'string') {
finalRequestMethod(result).then(function (data) {
resolve(data);
})["catch"](function (e) {
return reject(e);
});
} else if (typeof result === 'object') {
// fetch 需要拆分下字段
if (requestMethod) {
requestMethod(result).then(function (data) {
resolve(data);
})["catch"](function (e) {
return reject(e);
});
} else {
var _url = result.url,
_rest = tslib_1.__rest(result, ["url"]);
promiseService = function promiseService() {
return requestMethod ? requestMethod(service) : fetchProxy(url_1, rest_1);
};
fetchProxy(_url, _rest).then(function (data) {
resolve(data);
})["catch"](function (e) {
return reject(e);
});
break;
default:
promiseService = function promiseService() {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return new Promise(function (resolve, reject) {
var s = service.apply(void 0, __spread(args));
var fn = s;
if (!s.then) {
switch (typeof s) {
case 'string':
fn = finalRequestMethod(s);
break;
case 'object':
var url_2 = s.url,
rest_2 = __rest(s, ["url"]);
fn = requestMethod ? requestMethod(s) : fetchProxy(url_2, rest_2);
break;
}
}
}
});
};
fn.then(resolve)["catch"](reject);
});
};
}

@@ -125,0 +195,0 @@

"use strict";
var __assign = this && this.__assign || function () {
__assign = Object.assign || function (t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) {
if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
}
}
return t;
};
return __assign.apply(this, arguments);
};
var __read = this && this.__read || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o),
r,
ar = [],
e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) {
ar.push(r.value);
}
} catch (error) {
e = {
error: error
};
} finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
} finally {
if (e) throw e.error;
}
}
return ar;
};
var __spread = this && this.__spread || function () {
for (var ar = [], i = 0; i < arguments.length; i++) {
ar = ar.concat(__read(arguments[i]));
}
return ar;
};
var __importDefault = this && this.__importDefault || function (mod) {
return mod && mod.__esModule ? mod : {
"default": mod
};
};
Object.defineProperty(exports, "__esModule", {

@@ -7,8 +64,6 @@ value: true

var tslib_1 = require("tslib");
var lodash_debounce_1 = __importDefault(require("lodash.debounce"));
var lodash_debounce_1 = tslib_1.__importDefault(require("lodash.debounce"));
var lodash_throttle_1 = __importDefault(require("lodash.throttle"));
var lodash_throttle_1 = tslib_1.__importDefault(require("lodash.throttle"));
var react_1 = require("react");

@@ -20,15 +75,17 @@

var limit_1 = tslib_1.__importDefault(require("./utils/limit"));
var limit_1 = __importDefault(require("./utils/limit"));
var usePersistFn_1 = tslib_1.__importDefault(require("./utils/usePersistFn"));
var usePersistFn_1 = __importDefault(require("./utils/usePersistFn"));
var useUpdateEffect_1 = tslib_1.__importDefault(require("./utils/useUpdateEffect"));
var useUpdateEffect_1 = __importDefault(require("./utils/useUpdateEffect"));
var windowFocus_1 = tslib_1.__importDefault(require("./utils/windowFocus"));
var windowFocus_1 = __importDefault(require("./utils/windowFocus"));
var windowVisible_1 = tslib_1.__importDefault(require("./utils/windowVisible"));
var windowVisible_1 = __importDefault(require("./utils/windowVisible"));
var DEFAULT_KEY = 'AHOOKS_USE_REQUEST_DEFAULT_KEY';
var Fetch = /*#__PURE__*/function () {
var Fetch =
/** @class */
function () {
function Fetch(service, config, subscribe, initState) {

@@ -61,3 +118,3 @@ // 请求时序

if (initState) {
this.state = Object.assign(Object.assign({}, this.state), initState);
this.state = __assign(__assign({}, this.state), initState);
}

@@ -78,5 +135,3 @@

var _proto = Fetch.prototype;
_proto.setState = function setState(s) {
Fetch.prototype.setState = function (s) {
if (s === void 0) {

@@ -86,14 +141,16 @@ s = {};

this.state = Object.assign(Object.assign({}, this.state), s);
this.state = __assign(__assign({}, this.state), s);
this.subscribe(this.state);
};
_proto._run = function _run() {
Fetch.prototype._run = function () {
var _this = this;
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
var args = [];
// 取消已有定时器
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
} // 取消已有定时器
if (this.pollingTimer) {

@@ -124,3 +181,3 @@ clearTimeout(this.pollingTimer);

return this.service.apply(this, args).then(function (res) {
return this.service.apply(this, __spread(args)).then(function (res) {
if (!_this.unmountedFlag && currentCount === _this.count) {

@@ -181,3 +238,3 @@ if (_this.loadingDelayTimer) {

_this.pollingTimer = setTimeout(function () {
_this._run.apply(_this, args);
_this._run.apply(_this, __spread(args));
}, _this.config.pollingInterval);

@@ -189,5 +246,11 @@ }

_proto.run = function run() {
Fetch.prototype.run = function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
if (this.debounceRun) {
this.debounceRun.apply(this, arguments); // TODO 如果 options 存在 debounceInterval,或 throttleInterval,则 run 和 refresh 不会返回 Promise。 带类型需要修复后,此处变成 return;。
this.debounceRun.apply(this, __spread(args)); // TODO 如果 options 存在 debounceInterval,或 throttleInterval,则 run 和 refresh 不会返回 Promise。 带类型需要修复后,此处变成 return;。

@@ -198,10 +261,10 @@ return Promise.resolve(null);

if (this.throttleRun) {
this.throttleRun.apply(this, arguments);
this.throttleRun.apply(this, __spread(args));
return Promise.resolve(null);
}
return this._run.apply(this, arguments);
return this._run.apply(this, __spread(args));
};
_proto.cancel = function cancel() {
Fetch.prototype.cancel = function () {
if (this.debounceRun) {

@@ -230,7 +293,7 @@ this.debounceRun.cancel();

_proto.refresh = function refresh() {
return this.run.apply(this, this.state.params);
Fetch.prototype.refresh = function () {
return this.run.apply(this, __spread(this.state.params));
};
_proto.rePolling = function rePolling() {
Fetch.prototype.rePolling = function () {
if (this.pollingWhenVisibleFlag) {

@@ -242,3 +305,3 @@ this.pollingWhenVisibleFlag = false;

_proto.mutate = function mutate(data) {
Fetch.prototype.mutate = function (data) {
if (typeof data === 'function') {

@@ -256,3 +319,3 @@ this.setState({

_proto.unmount = function unmount() {
Fetch.prototype.unmount = function () {
this.unmountedFlag = true;

@@ -271,36 +334,36 @@ this.cancel();

var _options$refreshDeps = _options.refreshDeps,
refreshDeps = _options$refreshDeps === void 0 ? [] : _options$refreshDeps,
_options$manual = _options.manual,
manual = _options$manual === void 0 ? false : _options$manual,
_options$onSuccess = _options.onSuccess,
onSuccess = _options$onSuccess === void 0 ? function () {} : _options$onSuccess,
_options$onError = _options.onError,
onError = _options$onError === void 0 ? function () {} : _options$onError,
_options$defaultLoadi = _options.defaultLoading,
defaultLoading = _options$defaultLoadi === void 0 ? false : _options$defaultLoadi,
var _a = _options.refreshDeps,
refreshDeps = _a === void 0 ? [] : _a,
_b = _options.manual,
manual = _b === void 0 ? false : _b,
_c = _options.onSuccess,
onSuccess = _c === void 0 ? function () {} : _c,
_d = _options.onError,
onError = _d === void 0 ? function () {} : _d,
_e = _options.defaultLoading,
defaultLoading = _e === void 0 ? false : _e,
loadingDelay = _options.loadingDelay,
_options$pollingInter = _options.pollingInterval,
pollingInterval = _options$pollingInter === void 0 ? 0 : _options$pollingInter,
_options$pollingWhenH = _options.pollingWhenHidden,
pollingWhenHidden = _options$pollingWhenH === void 0 ? true : _options$pollingWhenH,
_options$defaultParam = _options.defaultParams,
defaultParams = _options$defaultParam === void 0 ? [] : _options$defaultParam,
_options$refreshOnWin = _options.refreshOnWindowFocus,
refreshOnWindowFocus = _options$refreshOnWin === void 0 ? false : _options$refreshOnWin,
_options$focusTimespa = _options.focusTimespan,
focusTimespan = _options$focusTimespa === void 0 ? 5000 : _options$focusTimespa,
_f = _options.pollingInterval,
pollingInterval = _f === void 0 ? 0 : _f,
_g = _options.pollingWhenHidden,
pollingWhenHidden = _g === void 0 ? true : _g,
_h = _options.defaultParams,
defaultParams = _h === void 0 ? [] : _h,
_j = _options.refreshOnWindowFocus,
refreshOnWindowFocus = _j === void 0 ? false : _j,
_k = _options.focusTimespan,
focusTimespan = _k === void 0 ? 5000 : _k,
fetchKey = _options.fetchKey,
cacheKey = _options.cacheKey,
_options$cacheTime = _options.cacheTime,
cacheTime = _options$cacheTime === void 0 ? 5 * 60 * 1000 : _options$cacheTime,
_options$staleTime = _options.staleTime,
staleTime = _options$staleTime === void 0 ? 0 : _options$staleTime,
_l = _options.cacheTime,
cacheTime = _l === void 0 ? 5 * 60 * 1000 : _l,
_m = _options.staleTime,
staleTime = _m === void 0 ? 0 : _m,
debounceInterval = _options.debounceInterval,
throttleInterval = _options.throttleInterval,
initialData = _options.initialData,
_options$ready = _options.ready,
ready = _options$ready === void 0 ? true : _options$ready,
_options$throwOnError = _options.throwOnError,
throwOnError = _options$throwOnError === void 0 ? false : _options$throwOnError;
_o = _options.ready,
ready = _o === void 0 ? true : _o,
_p = _options.throwOnError,
throwOnError = _p === void 0 ? false : _p;
var newstFetchKey = react_1.useRef(DEFAULT_KEY); // 持久化一些函数

@@ -337,7 +400,7 @@

s[key] = data;
return Object.assign({}, s);
return __assign({}, s);
});
});
var _react_1$useState = react_1.useState(function () {
var _q = __read(react_1.useState(function () {
var _a; // 如果有 缓存,则从缓存中读数据

@@ -347,11 +410,11 @@

if (cacheKey) {
var cacheData = (_a = cache_1.getCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
var cacheData_1 = (_a = cache_1.getCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
if (cacheData) {
newstFetchKey.current = cacheData.newstFetchKey;
if (cacheData_1) {
newstFetchKey.current = cacheData_1.newstFetchKey;
/* 使用 initState, 重新 new Fetch */
var newFetches = {};
Object.keys(cacheData.fetches).forEach(function (key) {
var cacheFetch = cacheData.fetches[key];
var newFetches_1 = {};
Object.keys(cacheData_1.fetches).forEach(function (key) {
var cacheFetch = cacheData_1.fetches[key];
var newFetch = new Fetch(servicePersist, config, subscribe.bind(null, key), {

@@ -363,5 +426,5 @@ loading: cacheFetch.loading,

});
newFetches[key] = newFetch.state;
newFetches_1[key] = newFetch.state;
});
return newFetches;
return newFetches_1;
}

@@ -371,5 +434,5 @@ }

return [];
}),
fetches = _react_1$useState[0],
setFeches = _react_1$useState[1];
}), 2),
fetches = _q[0],
setFeches = _q[1];

@@ -380,6 +443,6 @@ var fetchesRef = react_1.useRef(fetches);

var run = react_1.useCallback(function () {
var _currentFetch;
var args = [];
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
args[_key2] = arguments[_key2];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}

@@ -394,3 +457,3 @@

if (fetchKeyPersist) {
var key = fetchKeyPersist.apply(void 0, args);
var key = fetchKeyPersist.apply(void 0, __spread(args));
newstFetchKey.current = key === undefined ? DEFAULT_KEY : key;

@@ -412,7 +475,7 @@ }

s[currentFetchKey] = currentFetch;
return Object.assign({}, s);
return __assign({}, s);
});
}
return (_currentFetch = currentFetch).run.apply(_currentFetch, args);
return currentFetch.run.apply(currentFetch, __spread(args));
}, [fetchKey, subscribe, ready]);

@@ -435,3 +498,3 @@ var runRef = react_1.useRef(run);

if (!hasTriggeredByReady.current && readyMemoryParams.current) {
runRef.current.apply(runRef, readyMemoryParams.current);
runRef.current.apply(runRef, __spread(readyMemoryParams.current));
}

@@ -461,3 +524,3 @@

// 第一次默认执行,可以通过 defaultParams 设置参数
runRef.current.apply(runRef, defaultParams);
runRef.current.apply(runRef, __spread(defaultParams));
}

@@ -484,3 +547,3 @@ }

}
}, [].concat(refreshDeps)); // 卸载组件触发
}, __spread(refreshDeps)); // 卸载组件触发

@@ -496,6 +559,6 @@ react_1.useEffect(function () {

return function () {
throw new Error("Cannot call " + name + " when service not executed once.");
console.warn("You should't call " + name + " when service not executed once.");
};
}, []);
return Object.assign(Object.assign({
return __assign(__assign({
loading: ready && !manual || defaultLoading,

@@ -502,0 +565,0 @@ data: initialData,

"use strict";
var __assign = this && this.__assign || function () {
__assign = Object.assign || function (t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) {
if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
}
}
return t;
};
return __assign.apply(this, arguments);
};
var __rest = this && this.__rest || function (s, e) {
var t = {};
for (var p in s) {
if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
}
if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
}
return t;
};
var __read = this && this.__read || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o),
r,
ar = [],
e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) {
ar.push(r.value);
}
} catch (error) {
e = {
error: error
};
} finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
} finally {
if (e) throw e.error;
}
}
return ar;
};
var __spread = this && this.__spread || function () {
for (var ar = [], i = 0; i < arguments.length; i++) {
ar = ar.concat(__read(arguments[i]));
}
return ar;
};
var __importDefault = this && this.__importDefault || function (mod) {
return mod && mod.__esModule ? mod : {
"default": mod
};
};
Object.defineProperty(exports, "__esModule", {

@@ -7,23 +77,21 @@ value: true

var tslib_1 = require("tslib");
var react_1 = require("react");
var useAsync_1 = tslib_1.__importDefault(require("./useAsync"));
var useAsync_1 = __importDefault(require("./useAsync"));
var useUpdateEffect_1 = tslib_1.__importDefault(require("./utils/useUpdateEffect"));
var useUpdateEffect_1 = __importDefault(require("./utils/useUpdateEffect"));
function useLoadMore(service, options) {
var _options$refreshDeps = options.refreshDeps,
refreshDeps = _options$refreshDeps === void 0 ? [] : _options$refreshDeps,
var _a = options.refreshDeps,
refreshDeps = _a === void 0 ? [] : _a,
ref = options.ref,
isNoMore = options.isNoMore,
_options$threshold = options.threshold,
threshold = _options$threshold === void 0 ? 100 : _options$threshold,
_b = options.threshold,
threshold = _b === void 0 ? 100 : _b,
fetchKey = options.fetchKey,
restOptions = tslib_1.__rest(options, ["refreshDeps", "ref", "isNoMore", "threshold", "fetchKey"]);
restOptions = __rest(options, ["refreshDeps", "ref", "isNoMore", "threshold", "fetchKey"]);
var _react_1$useState = react_1.useState(false),
loadingMore = _react_1$useState[0],
setLoadingMore = _react_1$useState[1];
var _c = __read(react_1.useState(false), 2),
loadingMore = _c[0],
setLoadingMore = _c[1];

@@ -35,3 +103,3 @@ react_1.useEffect(function () {

}, []);
var result = useAsync_1["default"](service, Object.assign(Object.assign({}, restOptions), {
var result = useAsync_1["default"](service, __assign(__assign({}, restOptions), {
fetchKey: function fetchKey(d) {

@@ -43,6 +111,12 @@ var _a;

onSuccess: function onSuccess() {
var params = [];
for (var _i = 0; _i < arguments.length; _i++) {
params[_i] = arguments[_i];
}
setLoadingMore(false);
if (options.onSuccess) {
options.onSuccess.apply(options, arguments);
options.onSuccess.apply(options, __spread(params));
}

@@ -59,4 +133,7 @@ }

reset();
var restParams = params.slice(1);
run.apply(void 0, [undefined].concat(restParams));
var _a = __read(params),
restParams = _a.slice(1);
run.apply(void 0, __spread([undefined], restParams));
}, [run, reset, params]);

@@ -72,3 +149,3 @@ var reloadRef = react_1.useRef(reload);

}
}, [].concat(refreshDeps));
}, __spread(refreshDeps));
var dataGroup = react_1.useMemo(function () {

@@ -89,3 +166,3 @@ var listGroup = []; // 在 loadMore 时,不希望清空上一次的 data。需要把最后一个 非 loading 的请求 data,放回去。

});
return Object.assign(Object.assign({}, lastNoLoadingData), {
return __assign(__assign({}, lastNoLoadingData), {
list: listGroup

@@ -101,4 +178,7 @@ });

setLoadingMore(true);
var restParams = params.slice(1);
run.apply(void 0, [dataGroup].concat(restParams));
var _a = __read(params),
restParams = _a.slice(1);
run.apply(void 0, __spread([dataGroup], restParams));
}, [noMore, run, dataGroup, params]);

@@ -130,3 +210,3 @@ /* 上拉加载的方法 */

}, [scrollMethod]);
return Object.assign(Object.assign({}, result), {
return __assign(__assign({}, result), {
data: dataGroup,

@@ -133,0 +213,0 @@ reload: reload,

"use strict";
var __assign = this && this.__assign || function () {
__assign = Object.assign || function (t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) {
if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
}
}
return t;
};
return __assign.apply(this, arguments);
};
var __rest = this && this.__rest || function (s, e) {
var t = {};
for (var p in s) {
if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
}
if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
}
return t;
};
var __read = this && this.__read || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o),
r,
ar = [],
e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) {
ar.push(r.value);
}
} catch (error) {
e = {
error: error
};
} finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
} finally {
if (e) throw e.error;
}
}
return ar;
};
var __spread = this && this.__spread || function () {
for (var ar = [], i = 0; i < arguments.length; i++) {
ar = ar.concat(__read(arguments[i]));
}
return ar;
};
var __importDefault = this && this.__importDefault || function (mod) {
return mod && mod.__esModule ? mod : {
"default": mod
};
};
Object.defineProperty(exports, "__esModule", {

@@ -7,18 +77,16 @@ value: true

var tslib_1 = require("tslib");
var react_1 = require("react");
var useAsync_1 = tslib_1.__importDefault(require("./useAsync"));
var useAsync_1 = __importDefault(require("./useAsync"));
var useUpdateEffect_1 = tslib_1.__importDefault(require("./utils/useUpdateEffect"));
var useUpdateEffect_1 = __importDefault(require("./utils/useUpdateEffect"));
function usePaginated(service, options) {
var paginated = options.paginated,
_options$defaultPageS = options.defaultPageSize,
defaultPageSize = _options$defaultPageS === void 0 ? 10 : _options$defaultPageS,
_options$refreshDeps = options.refreshDeps,
refreshDeps = _options$refreshDeps === void 0 ? [] : _options$refreshDeps,
_a = options.defaultPageSize,
defaultPageSize = _a === void 0 ? 10 : _a,
_b = options.refreshDeps,
refreshDeps = _b === void 0 ? [] : _b,
fetchKey = options.fetchKey,
restOptions = tslib_1.__rest(options, ["paginated", "defaultPageSize", "refreshDeps", "fetchKey"]);
restOptions = __rest(options, ["paginated", "defaultPageSize", "refreshDeps", "fetchKey"]);

@@ -31,3 +99,3 @@ react_1.useEffect(function () {

var _a = useAsync_1["default"](service, Object.assign({
var _c = useAsync_1["default"](service, __assign({
defaultParams: [{

@@ -38,23 +106,25 @@ current: 1,

}, restOptions)),
data = _a.data,
params = _a.params,
run = _a.run,
loading = _a.loading,
rest = tslib_1.__rest(_a, ["data", "params", "run", "loading"]);
data = _c.data,
params = _c.params,
run = _c.run,
loading = _c.loading,
rest = __rest(_c, ["data", "params", "run", "loading"]);
var _ref = params && params[0] ? params[0] : {},
_ref$current = _ref.current,
current = _ref$current === void 0 ? 1 : _ref$current,
_ref$pageSize = _ref.pageSize,
pageSize = _ref$pageSize === void 0 ? defaultPageSize : _ref$pageSize,
_ref$sorter = _ref.sorter,
sorter = _ref$sorter === void 0 ? {} : _ref$sorter,
_ref$filters = _ref.filters,
filters = _ref$filters === void 0 ? {} : _ref$filters; // 只改变 pagination,其他参数原样传递
var _d = params && params[0] ? params[0] : {},
_e = _d.current,
current = _e === void 0 ? 1 : _e,
_f = _d.pageSize,
pageSize = _f === void 0 ? defaultPageSize : _f,
_g = _d.sorter,
sorter = _g === void 0 ? {} : _g,
_h = _d.filters,
filters = _h === void 0 ? {} : _h; // 只改变 pagination,其他参数原样传递
var runChangePaination = react_1.useCallback(function (paginationParams) {
var oldPaginationParams = params[0],
restParams = params.slice(1);
run.apply(void 0, [Object.assign(Object.assign({}, oldPaginationParams), paginationParams)].concat(restParams));
var _a = __read(params),
oldPaginationParams = _a[0],
restParams = _a.slice(1);
run.apply(void 0, __spread([__assign(__assign({}, oldPaginationParams), paginationParams)], restParams));
}, [run, params]);

@@ -94,3 +164,3 @@ var total = (data === null || data === void 0 ? void 0 : data.total) || 0;

}
}, [].concat(refreshDeps)); // 表格翻页 排序 筛选等
}, __spread(refreshDeps)); // 表格翻页 排序 筛选等

@@ -105,3 +175,3 @@ var changeTable = react_1.useCallback(function (p, f, s) {

}, [filters, sorter, runChangePaination]);
return Object.assign({
return __assign({
loading: loading,

@@ -108,0 +178,0 @@ data: data,

"use strict";
var __rest = this && this.__rest || function (s, e) {
var t = {};
for (var p in s) {
if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
}
if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
}
return t;
};
var __read = this && this.__read || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o),
r,
ar = [],
e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) {
ar.push(r.value);
}
} catch (error) {
e = {
error: error
};
} finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
} finally {
if (e) throw e.error;
}
}
return ar;
};
var __spread = this && this.__spread || function () {
for (var ar = [], i = 0; i < arguments.length; i++) {
ar = ar.concat(__read(arguments[i]));
}
return ar;
};
var __importDefault = this && this.__importDefault || function (mod) {
return mod && mod.__esModule ? mod : {
"default": mod
};
};
Object.defineProperty(exports, "__esModule", {

@@ -7,8 +61,6 @@ value: true

var tslib_1 = require("tslib");
var umi_request_1 = __importDefault(require("umi-request"));
var umi_request_1 = tslib_1.__importDefault(require("umi-request"));
var useAsync_1 = __importDefault(require("./useAsync"));
var useAsync_1 = tslib_1.__importDefault(require("./useAsync"));
function useRequest(service, options) {

@@ -22,16 +74,18 @@ var promiseService;

} else if (typeof service === 'object') {
var url = service.url,
rest = tslib_1.__rest(service, ["url"]);
var url_1 = service.url,
rest_1 = __rest(service, ["url"]);
promiseService = function promiseService() {
return umi_request_1["default"](url, rest);
return umi_request_1["default"](url_1, rest_1);
};
} else {
promiseService = function promiseService() {
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return new Promise(function (resolve) {
var result = service.apply(void 0, args);
var result = service.apply(void 0, __spread(args));

@@ -43,6 +97,6 @@ if (typeof result === 'string') {

} else if (typeof result === 'object') {
var _url = result.url,
_rest = tslib_1.__rest(result, ["url"]);
var url = result.url,
rest = __rest(result, ["url"]);
umi_request_1["default"](_url, _rest).then(function (data) {
umi_request_1["default"](url, rest).then(function (data) {
resolve(data);

@@ -49,0 +103,0 @@ });

@@ -0,5 +1,6 @@

declare type Timer = ReturnType<typeof setTimeout>;
export declare type CachedKeyType = string | number;
export declare type cachedData = {
data: any;
timer: ReturnType<typeof setTimeout>;
timer: Timer;
startTime: number;

@@ -6,0 +7,0 @@ };

"use strict";
var __read = this && this.__read || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o),
r,
ar = [],
e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) {
ar.push(r.value);
}
} catch (error) {
e = {
error: error
};
} finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
} finally {
if (e) throw e.error;
}
}
return ar;
};
var __spread = this && this.__spread || function () {
for (var ar = [], i = 0; i < arguments.length; i++) {
ar = ar.concat(__read(arguments[i]));
}
return ar;
};
Object.defineProperty(exports, "__esModule", {

@@ -10,5 +45,11 @@ value: true

return function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
if (pending) return;
pending = true;
fn.apply(void 0, arguments);
fn.apply(void 0, __spread(args));
setTimeout(function () {

@@ -15,0 +56,0 @@ pending = false;

"use strict";
var __read = this && this.__read || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o),
r,
ar = [],
e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) {
ar.push(r.value);
}
} catch (error) {
e = {
error: error
};
} finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
} finally {
if (e) throw e.error;
}
}
return ar;
};
var __spread = this && this.__spread || function () {
for (var ar = [], i = 0; i < arguments.length; i++) {
ar = ar.concat(__read(arguments[i]));
}
return ar;
};
Object.defineProperty(exports, "__esModule", {

@@ -15,6 +50,12 @@ value: true

var persist = react_1.useCallback(function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
var refFn = ref.current;
if (refFn) {
return refFn.apply(void 0, arguments);
return refFn.apply(void 0, __spread(args));
}

@@ -21,0 +62,0 @@ }, [ref]);

{
"name": "@ahooksjs/use-request",
"version": "2.0.2",
"version": "2.1.0-beta",
"description": "React Hooks for fetching, caching and updating asynchronous data",

@@ -5,0 +5,0 @@ "main": "./lib/index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc