Comparing version 0.1.17 to 0.1.18
@@ -1,1 +0,1 @@ | ||
module.exports=function(e,r){"use strict";var t={};function __webpack_require__(r){if(t[r]){return t[r].exports}var n=t[r]={i:r,l:false,exports:{}};e[r].call(n.exports,n,n.exports,__webpack_require__);n.l=true;return n.exports}__webpack_require__.ab=__dirname+"/";function startup(){return __webpack_require__(325)}return startup()}({202:function(e,r){"use strict";Object.defineProperty(r,"__esModule",{value:true});var t=new WeakMap;var n=0;function hash(e){if(!e.length)return"";var r="arg";for(var a=0;a<e.length;++a){var u=void 0;if(e[a]===null||typeof e[a]!=="object"){if(typeof e[a]==="string"){u='"'+e[a]+'"'}else{u=String(e[a])}}else{if(!t.has(e[a])){u=n;t.set(e[a],n++)}else{u=t.get(e[a])}}r+="@"+u}return r}r.default=hash},205:function(e,r){"use strict";Object.defineProperty(r,"__esModule",{value:true});function isOnline(){if(typeof navigator.onLine!=="undefined"){return navigator.onLine}return true}r.default=isOnline},209:function(e,r,t){"use strict";Object.defineProperty(r,"__esModule",{value:true});var n=t(297);var a=n.createContext({});a.displayName="SWRConfigContext";r.default=a},297:function(e){e.exports=require("react")},325:function(e,r,t){"use strict";function __export(e){for(var t in e)if(!r.hasOwnProperty(t))r[t]=e[t]}var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(r,"__esModule",{value:true});__export(t(516));var a=n(t(516));var u=t(926);r.useSWRPages=u.useSWRPages;r.default=a.default},459:function(e,r){"use strict";Object.defineProperty(r,"__esModule",{value:true});function isDocumentVisible(){if(typeof document!=="undefined"&&typeof document.visibilityState!=="undefined"){return document.visibilityState!=="hidden"}return true}r.default=isDocumentVisible},516:function(e,r,t){"use strict";var n=this&&this.__awaiter||function(e,r,t,n){function adopt(e){return e instanceof t?e:new t(function(r){r(e)})}return new(t||(t=Promise))(function(t,a){function fulfilled(e){try{step(n.next(e))}catch(e){a(e)}}function rejected(e){try{step(n["throw"](e))}catch(e){a(e)}}function step(e){e.done?t(e.value):adopt(e.value).then(fulfilled,rejected)}step((n=n.apply(e,r||[])).next())})};var a=this&&this.__generator||function(e,r){var t={label:0,sent:function(){if(u[0]&1)throw u[1];return u[1]},trys:[],ops:[]},n,a,u,i;return i={next:verb(0),throw:verb(1),return:verb(2)},typeof Symbol==="function"&&(i[Symbol.iterator]=function(){return this}),i;function verb(e){return function(r){return step([e,r])}}function step(i){if(n)throw new TypeError("Generator is already executing.");while(t)try{if(n=1,a&&(u=i[0]&2?a["return"]:i[0]?a["throw"]||((u=a["return"])&&u.call(a),0):a.next)&&!(u=u.call(a,i[1])).done)return u;if(a=0,u)i=[i[0]&2,u.value];switch(i[0]){case 0:case 1:u=i;break;case 4:t.label++;return{value:i[1],done:false};case 5:t.label++;a=i[1];i=[0];continue;case 7:i=t.ops.pop();t.trys.pop();continue;default:if(!(u=t.trys,u=u.length>0&&u[u.length-1])&&(i[0]===6||i[0]===2)){t=0;continue}if(i[0]===3&&(!u||i[1]>u[0]&&i[1]<u[3])){t.label=i[1];break}if(i[0]===6&&t.label<u[1]){t.label=u[1];u=i;break}if(u&&t.label<u[2]){t.label=u[2];t.ops.push(i);break}if(u[2])t.ops.pop();t.trys.pop();continue}i=r.call(e,t)}catch(e){i=[6,e];a=0}finally{n=u=0}if(i[0]&5)throw i[1];return{value:i[0]?i[1]:void 0,done:true}}};var u=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var r={};if(e!=null)for(var t in e)if(Object.hasOwnProperty.call(e,t))r[t]=e[t];r["default"]=e;return r};var i=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(r,"__esModule",{value:true});var f=t(297);var o=u(t(641));var l=i(t(202));var c=i(t(459));var s=i(t(205));var d=i(t(542));var v=i(t(209));var p=typeof window==="undefined";var R=p?f.useEffect:f.useLayoutEffect;var h=function(e){return e?"err@"+e:""};var S=function(e){var r=null;if(typeof e==="function"){try{e=e()}catch(r){e=""}}if(Array.isArray(e)){r=e;e=l.default(e)}else{e=String(e||"")}return[e,r]};var _=function(e,r){if(r===void 0){r=true}var t=S(e)[0];if(!t)return;var n=o.CACHE_REVALIDATORS[t];if(t&&n){var a=o.cacheGet(t);var u=o.cacheGet(h(t));for(var i=0;i<n.length;++i){n[i](r,a,u,true)}}};r.trigger=_;var O=function(e,r,t){var n=o.CACHE_REVALIDATORS[e];if(e&&n){for(var a=0;a<n.length;++a){n[a](false,r,t)}}};var E=function(e,r,t){return n(void 0,void 0,void 0,function(){var n,u,i,f,l,c;return a(this,function(a){switch(a.label){case 0:n=S(e)[0];if(!n)return[2];o.MUTATION_TS[n]=Date.now()-1;if(!(r&&typeof r.then==="function"))return[3,5];a.label=1;case 1:a.trys.push([1,3,,4]);return[4,r];case 2:u=a.sent();return[3,4];case 3:f=a.sent();i=f;return[3,4];case 4:return[3,6];case 5:u=r;if(typeof t==="undefined"){t=true}a.label=6;case 6:if(typeof u!=="undefined"){o.cacheSet(n,u)}l=o.CACHE_REVALIDATORS[n];if(l){for(c=0;c<l.length;++c){l[c](!!t,u,i,true)}}return[2]}})})};r.mutate=E;function useSWR(){var e=this;var r=[];for(var t=0;t<arguments.length;t++){r[t]=arguments[t]}var u,i,l={};if(r.length>=1){u=r[0]}if(r.length>2){i=r[1];l=r[2]}else{if(typeof r[1]==="function"){i=r[1]}else if(typeof r[1]==="object"){l=r[1]}}var _=S(u),E=_[0],C=_[1];var y=h(E);l=Object.assign({},o.default,f.useContext(v.default),l);if(typeof i==="undefined"){i=l.fetcher}var T=o.cacheGet(E)||l.initialData;var b=o.cacheGet(y);var g=f.useRef({data:false,error:false,isValidating:false});var w=f.useRef({data:T,error:b,isValidating:false});var I=f.useState(null)[1];var A=f.useCallback(function(e){var r=false;for(var t in e){w.current[t]=e[t];if(g.current[t]){r=true}}if(r||l.suspense){I({})}},[]);var M=f.useRef(false);var N=f.useRef(E);var m=f.useCallback(function(r){if(r===void 0){r={}}return n(e,void 0,void 0,function(){var e,t,n,u,f,c,s;return a(this,function(a){switch(a.label){case 0:if(!E||!i)return[2,false];if(M.current)return[2,false];r=Object.assign({dedupe:false},r);e=true;t=typeof o.CONCURRENT_PROMISES[E]!=="undefined"&&r.dedupe;a.label=1;case 1:a.trys.push([1,6,,7]);A({isValidating:true});n=void 0;u=void 0;if(!t)return[3,3];u=o.CONCURRENT_PROMISES_TS[E];return[4,o.CONCURRENT_PROMISES[E]];case 2:n=a.sent();return[3,5];case 3:if(o.CONCURRENT_PROMISES[E]){o.MUTATION_TS[E]=Date.now()-1}if(l.loadingTimeout&&!o.cacheGet(E)){setTimeout(function(){if(e)l.onLoadingSlow(E,l)},l.loadingTimeout)}if(C!==null){o.CONCURRENT_PROMISES[E]=i.apply(void 0,C)}else{o.CONCURRENT_PROMISES[E]=i(E)}o.CONCURRENT_PROMISES_TS[E]=u=Date.now();return[4,o.CONCURRENT_PROMISES[E]];case 4:n=a.sent();setTimeout(function(){delete o.CONCURRENT_PROMISES[E];delete o.CONCURRENT_PROMISES_TS[E]},l.dedupingInterval);l.onSuccess(n,E,l);a.label=5;case 5:if(o.MUTATION_TS[E]&&u<=o.MUTATION_TS[E]){A({isValidating:false});return[2,false]}o.cacheSet(E,n);o.cacheSet(y,undefined);N.current=E;f={isValidating:false};if(typeof w.current.error!=="undefined"){f.error=undefined}if(l.compare(w.current.data,n)){}else{f.data=n}A(f);if(!t){O(E,n,undefined)}return[3,7];case 6:c=a.sent();delete o.CONCURRENT_PROMISES[E];delete o.CONCURRENT_PROMISES_TS[E];o.cacheSet(y,c);N.current=E;if(w.current.error!==c){A({isValidating:false,error:c});if(!t){O(E,undefined,c)}}l.onError(c,E,l);if(l.shouldRetryOnError){s=(r.retryCount||0)+1;l.onErrorRetry(c,E,l,m,Object.assign({dedupe:true},r,{retryCount:s}))}return[3,7];case 7:e=false;return[2,true]}})})},[E]);R(function(){if(!E)return undefined;M.current=false;var e=w.current.data;var r=o.cacheGet(E)||l.initialData;if(N.current!==E||!l.compare(e,r)){A({data:r});N.current=E}var t=function(){return m({dedupe:true})};if(!l.initialData){if(typeof r!=="undefined"&&!p&&window["requestIdleCallback"]){window["requestIdleCallback"](t)}else{t()}}var n;if(l.revalidateOnFocus){n=d.default(t,l.focusThrottleInterval);if(!o.FOCUS_REVALIDATORS[E]){o.FOCUS_REVALIDATORS[E]=[n]}else{o.FOCUS_REVALIDATORS[E].push(n)}}var a=function(e,r,n,a){if(e===void 0){e=true}if(a===void 0){a=true}var u={};var i=false;if(typeof r!=="undefined"&&!l.compare(w.current.data,r)){u.data=r;i=true}if(w.current.error!==n){u.error=n;i=true}if(i){A(u)}N.current=E;if(e){if(a){return t()}else{return m()}}return false};if(!o.CACHE_REVALIDATORS[E]){o.CACHE_REVALIDATORS[E]=[a]}else{o.CACHE_REVALIDATORS[E].push(a)}var u=null;if(typeof addEventListener!=="undefined"&&l.revalidateOnReconnect){u=addEventListener("online",t)}return function(){A=function(){return null};M.current=true;if(n&&o.FOCUS_REVALIDATORS[E]){var e=o.FOCUS_REVALIDATORS[E];var r=e.indexOf(n);if(r>=0){e[r]=e[e.length-1];e.pop()}}if(o.CACHE_REVALIDATORS[E]){var e=o.CACHE_REVALIDATORS[E];var r=e.indexOf(a);if(r>=0){e[r]=e[e.length-1];e.pop()}}if(typeof removeEventListener!=="undefined"&&u!==null){removeEventListener("online",u)}}},[E,m]);R(function(){var r=null;var t=function(){return n(e,void 0,void 0,function(){return a(this,function(e){switch(e.label){case 0:if(!(!w.current.error&&(l.refreshWhenHidden||c.default())&&(!l.refreshWhenOffline&&s.default())))return[3,2];return[4,m({dedupe:true})];case 1:e.sent();e.label=2;case 2:if(l.refreshInterval){r=setTimeout(t,l.refreshInterval)}return[2]}})})};if(l.refreshInterval){r=setTimeout(t,l.refreshInterval)}return function(){if(r)clearTimeout(r)}},[l.refreshInterval,l.refreshWhenHidden,l.refreshWhenOffline,m]);if(l.suspense){if(p)throw new Error("Suspense on server side is not yet supported!");var P=o.cacheGet(E);var V=o.cacheGet(y);if(typeof P==="undefined"&&typeof V==="undefined"){if(!o.CONCURRENT_PROMISES[E]){m()}if(o.CONCURRENT_PROMISES[E]&&typeof o.CONCURRENT_PROMISES[E].then==="function"){throw o.CONCURRENT_PROMISES[E]}P=o.CONCURRENT_PROMISES[E]}if(typeof P==="undefined"&&V){throw V}return{error:V,data:P,revalidate:m,isValidating:w.current.isValidating}}return f.useMemo(function(){var e={revalidate:m};Object.defineProperties(e,{error:{get:function(){g.current.error=true;return N.current===E?w.current.error:b}},data:{get:function(){g.current.data=true;return N.current===E?w.current.data:T}},isValidating:{get:function(){g.current.isValidating=true;return w.current.isValidating}}});return e},[m])}var C=v.default.Provider;r.SWRConfig=C;r.default=useSWR},542:function(e,r){"use strict";Object.defineProperty(r,"__esModule",{value:true});function throttle(e,r){var t=false;return function(){var n=[];for(var a=0;a<arguments.length;a++){n[a]=arguments[a]}if(t)return;t=true;e.apply(void 0,n);setTimeout(function(){return t=false},r)}}r.default=throttle},641:function(e,r,t){"use strict";var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(r,"__esModule",{value:true});var a=n(t(832));var u=n(t(459));var i=n(t(205));var f=new Map;function cacheGet(e){return f.get(e)}r.cacheGet=cacheGet;function cacheSet(e,r){return f.set(e,r)}r.cacheSet=cacheSet;function cacheClear(){f.clear()}r.cacheClear=cacheClear;var o={};r.CONCURRENT_PROMISES=o;var l={};r.CONCURRENT_PROMISES_TS=l;var c={};r.FOCUS_REVALIDATORS=c;var s={};r.CACHE_REVALIDATORS=s;var d={};r.MUTATION_TS=d;function onErrorRetry(e,r,t,n,a){if(!u.default()){return}var i=Math.min(a.retryCount||0,8);var f=~~((Math.random()+.5)*(1<<i))*t.errorRetryInterval;setTimeout(n,f,a)}var v=typeof window!=="undefined"&&navigator["connection"]&&["slow-2g","2g"].indexOf(navigator["connection"].effectiveType)!==-1;var p={onLoadingSlow:function(){},onSuccess:function(){},onError:function(){},onErrorRetry:onErrorRetry,errorRetryInterval:(v?10:5)*1e3,focusThrottleInterval:5*1e3,dedupingInterval:2*1e3,loadingTimeout:(v?5:3)*1e3,refreshInterval:0,revalidateOnFocus:true,revalidateOnReconnect:true,refreshWhenHidden:false,refreshWhenOffline:false,shouldRetryOnError:true,suspense:false,compare:a.default};var R=false;if(typeof window!=="undefined"&&window.addEventListener&&!R){var h=function(){if(!u.default()||!i.default())return;for(var e in c){if(c[e][0])c[e][0]()}};window.addEventListener("visibilitychange",h,false);window.addEventListener("focus",h,false);R=true}r.default=p},832:function(e){"use strict";var r=Array.isArray;var t=Object.keys;var n=Object.prototype.hasOwnProperty;e.exports=function equal(e,a){if(e===a)return true;if(e&&a&&typeof e=="object"&&typeof a=="object"){var u=r(e),i=r(a),f,o,l;if(u&&i){o=e.length;if(o!=a.length)return false;for(f=o;f--!==0;)if(!equal(e[f],a[f]))return false;return true}if(u!=i)return false;var c=e instanceof Date,s=a instanceof Date;if(c!=s)return false;if(c&&s)return e.getTime()==a.getTime();var d=e instanceof RegExp,v=a instanceof RegExp;if(d!=v)return false;if(d&&v)return e.toString()==a.toString();var p=t(e);o=p.length;if(o!==t(a).length)return false;for(f=o;f--!==0;)if(!n.call(a,p[f]))return false;for(f=o;f--!==0;){l=p[f];if(!equal(e[l],a[l]))return false}return true}return e!==e&&a!==a}},926:function(e,r,t){"use strict";var n=this&&this.__spreadArrays||function(){for(var e=0,r=0,t=arguments.length;r<t;r++)e+=arguments[r].length;for(var n=Array(e),a=0,r=0;r<t;r++)for(var u=arguments[r],i=0,f=u.length;i<f;i++,a++)n[a]=u[i];return n};var a=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var r={};if(e!=null)for(var t in e)if(Object.hasOwnProperty.call(e,t))r[t]=e[t];r["default"]=e;return r};Object.defineProperty(r,"__esModule",{value:true});var u=a(t(297));var i=t(641);var f=new Map;function useSWRPages(e,r,t,a){if(a===void 0){a=[]}var o="_swr_page_count_"+e;var l="_swr_page_offset_"+e;var c=u.useState(i.cacheGet(o)||1),s=c[0],d=c[1];var v=u.useState(i.cacheGet(l)||[null]),p=v[0],R=v[1];var h=u.useState([]),S=h[0],_=h[1];var O=u.useRef(r);var E=u.useRef(false);var C=u.useCallback(function(e){var r=O.current(e);if(r&&!r.length){E.current=true}else{E.current=false}return r},[]);var y=p[s]===null;var T=s===p.length;var b=y&&s===1&&E.current;var g=u.useCallback(function(){if(T||y)return;d(function(e){i.cacheSet(o,e+1);return e+1})},[T||y]);var w=u.useCallback(r,a);O.current=w;var I=u.useMemo(function(){var r=function(e){return function(r){if(!S[e]||S[e].data!==r.data||S[e].error!==r.error||S[e].revalidate!==r.revalidate){_(function(t){var a=n(t);a[e]={data:r.data,error:r.error,revalidate:r.revalidate,isValidating:r.isValidating};return a});if(typeof r.data!=="undefined"){var a=t(r,e);if(p[e+1]!==a){R(function(r){var t=n(r);t[e+1]=a;i.cacheSet(l,t);return t})}}}return r}};var a=[];if(!f.has(e)){f.set(e,[])}var o=f.get(e);for(var c=0;c<s;++c){if(!o[c]||o[c].offset!==p[c]||o[c].pageFn!==w){o[c]={component:u.default.createElement(C,{key:"page-"+p[c]+"-"+c,offset:p[c],withSWR:r(c)}),pageFn:w,offset:p[c]}}a.push(o[c].component)}return a},[w,s,S,p,e]);return{pages:I,pageCount:s,pageSWRs:S,isLoadingMore:T,isReachingEnd:y,isEmpty:b,loadMore:g}}r.useSWRPages=useSWRPages}}); | ||
module.exports=function(e,r){"use strict";var t={};function __webpack_require__(r){if(t[r]){return t[r].exports}var n=t[r]={i:r,l:false,exports:{}};e[r].call(n.exports,n,n.exports,__webpack_require__);n.l=true;return n.exports}__webpack_require__.ab=__dirname+"/";function startup(){return __webpack_require__(325)}return startup()}({202:function(e,r){"use strict";Object.defineProperty(r,"__esModule",{value:true});var t=new WeakMap;var n=0;function hash(e){if(!e.length)return"";var r="arg";for(var a=0;a<e.length;++a){var u=void 0;if(e[a]===null||typeof e[a]!=="object"){if(typeof e[a]==="string"){u='"'+e[a]+'"'}else{u=String(e[a])}}else{if(!t.has(e[a])){u=n;t.set(e[a],n++)}else{u=t.get(e[a])}}r+="@"+u}return r}r.default=hash},205:function(e,r){"use strict";Object.defineProperty(r,"__esModule",{value:true});function isOnline(){if(typeof navigator.onLine!=="undefined"){return navigator.onLine}return true}r.default=isOnline},209:function(e,r,t){"use strict";Object.defineProperty(r,"__esModule",{value:true});var n=t(297);var a=n.createContext({});a.displayName="SWRConfigContext";r.default=a},297:function(e){e.exports=require("react")},325:function(e,r,t){"use strict";function __export(e){for(var t in e)if(!r.hasOwnProperty(t))r[t]=e[t]}var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(r,"__esModule",{value:true});__export(t(516));var a=n(t(516));var u=t(926);r.useSWRPages=u.useSWRPages;r.default=a.default},459:function(e,r){"use strict";Object.defineProperty(r,"__esModule",{value:true});function isDocumentVisible(){if(typeof document!=="undefined"&&typeof document.visibilityState!=="undefined"){return document.visibilityState!=="hidden"}return true}r.default=isDocumentVisible},516:function(e,r,t){"use strict";var n=this&&this.__awaiter||function(e,r,t,n){function adopt(e){return e instanceof t?e:new t(function(r){r(e)})}return new(t||(t=Promise))(function(t,a){function fulfilled(e){try{step(n.next(e))}catch(e){a(e)}}function rejected(e){try{step(n["throw"](e))}catch(e){a(e)}}function step(e){e.done?t(e.value):adopt(e.value).then(fulfilled,rejected)}step((n=n.apply(e,r||[])).next())})};var a=this&&this.__generator||function(e,r){var t={label:0,sent:function(){if(u[0]&1)throw u[1];return u[1]},trys:[],ops:[]},n,a,u,i;return i={next:verb(0),throw:verb(1),return:verb(2)},typeof Symbol==="function"&&(i[Symbol.iterator]=function(){return this}),i;function verb(e){return function(r){return step([e,r])}}function step(i){if(n)throw new TypeError("Generator is already executing.");while(t)try{if(n=1,a&&(u=i[0]&2?a["return"]:i[0]?a["throw"]||((u=a["return"])&&u.call(a),0):a.next)&&!(u=u.call(a,i[1])).done)return u;if(a=0,u)i=[i[0]&2,u.value];switch(i[0]){case 0:case 1:u=i;break;case 4:t.label++;return{value:i[1],done:false};case 5:t.label++;a=i[1];i=[0];continue;case 7:i=t.ops.pop();t.trys.pop();continue;default:if(!(u=t.trys,u=u.length>0&&u[u.length-1])&&(i[0]===6||i[0]===2)){t=0;continue}if(i[0]===3&&(!u||i[1]>u[0]&&i[1]<u[3])){t.label=i[1];break}if(i[0]===6&&t.label<u[1]){t.label=u[1];u=i;break}if(u&&t.label<u[2]){t.label=u[2];t.ops.push(i);break}if(u[2])t.ops.pop();t.trys.pop();continue}i=r.call(e,t)}catch(e){i=[6,e];a=0}finally{n=u=0}if(i[0]&5)throw i[1];return{value:i[0]?i[1]:void 0,done:true}}};var u=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var r={};if(e!=null)for(var t in e)if(Object.hasOwnProperty.call(e,t))r[t]=e[t];r["default"]=e;return r};var i=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(r,"__esModule",{value:true});var f=t(297);var o=u(t(641));var l=i(t(202));var c=i(t(459));var s=i(t(205));var d=i(t(542));var v=i(t(209));var p=typeof window==="undefined";var R=p?f.useEffect:f.useLayoutEffect;var h=function(e){return e?"err@"+e:""};var S=function(e){var r=null;if(typeof e==="function"){try{e=e()}catch(r){e=""}}if(Array.isArray(e)){r=e;e=l.default(e)}else{e=String(e||"")}return[e,r]};var _=false;var O=function(e,r){if(r===void 0){r=true}var t=S(e)[0];if(!t)return;var n=o.CACHE_REVALIDATORS[t];if(t&&n){var a=o.cacheGet(t);var u=o.cacheGet(h(t));for(var i=0;i<n.length;++i){n[i](r,a,u,_)}}};r.trigger=O;var E=function(e,r,t){var n=o.CACHE_REVALIDATORS[e];if(e&&n){for(var a=0;a<n.length;++a){n[a](false,r,t)}}};var C=function(e,r,t){if(t===void 0){t=true}return n(void 0,void 0,void 0,function(){var n,u,i,f,l,c,s;return a(this,function(a){switch(a.label){case 0:n=S(e)[0];if(!n)return[2];if(typeof r==="undefined")return[2,O(e,t)];o.MUTATION_TS[n]=Date.now()-1;if(!(r&&typeof r==="function"))return[3,5];a.label=1;case 1:a.trys.push([1,3,,4]);return[4,r(o.cacheGet(n))];case 2:u=a.sent();return[3,4];case 3:f=a.sent();i=f;return[3,4];case 4:return[3,11];case 5:if(!(r&&typeof r.then==="function"))return[3,10];a.label=6;case 6:a.trys.push([6,8,,9]);return[4,r];case 7:u=a.sent();return[3,9];case 8:l=a.sent();i=l;return[3,9];case 9:return[3,11];case 10:u=r;a.label=11;case 11:if(typeof u!=="undefined"){o.cacheSet(n,u)}c=o.CACHE_REVALIDATORS[n];if(c){for(s=0;s<c.length;++s){c[s](!!t,u,i,_)}}if(i)throw i;return[2,u]}})})};r.mutate=C;function useSWR(){var e=this;var r=[];for(var t=0;t<arguments.length;t++){r[t]=arguments[t]}var u,i,l={};if(r.length>=1){u=r[0]}if(r.length>2){i=r[1];l=r[2]}else{if(typeof r[1]==="function"){i=r[1]}else if(typeof r[1]==="object"){l=r[1]}}var _=S(u),O=_[0],y=_[1];var T=h(O);l=Object.assign({},o.default,f.useContext(v.default),l);if(typeof i==="undefined"){i=l.fetcher}var b=o.cacheGet(O)||l.initialData;var w=o.cacheGet(T);var g=f.useRef({data:false,error:false,isValidating:false});var I=f.useRef({data:b,error:w,isValidating:false});var A=f.useState(null)[1];var M=f.useCallback(function(e){var r=false;for(var t in e){I.current[t]=e[t];if(g.current[t]){r=true}}if(r||l.suspense){A({})}},[]);var m=f.useRef(false);var N=f.useRef(O);var P=f.useCallback(function(e,r){return C(O,e,r)},[O]);var V=f.useCallback(function(r){if(r===void 0){r={}}return n(e,void 0,void 0,function(){var e,t,n,u,f,c,s;return a(this,function(a){switch(a.label){case 0:if(!O||!i)return[2,false];if(m.current)return[2,false];r=Object.assign({dedupe:false},r);e=true;t=typeof o.CONCURRENT_PROMISES[O]!=="undefined"&&r.dedupe;a.label=1;case 1:a.trys.push([1,6,,7]);M({isValidating:true});n=void 0;u=void 0;if(!t)return[3,3];u=o.CONCURRENT_PROMISES_TS[O];return[4,o.CONCURRENT_PROMISES[O]];case 2:n=a.sent();return[3,5];case 3:if(o.CONCURRENT_PROMISES[O]){o.MUTATION_TS[O]=Date.now()-1}if(l.loadingTimeout&&!o.cacheGet(O)){setTimeout(function(){if(e)l.onLoadingSlow(O,l)},l.loadingTimeout)}if(y!==null){o.CONCURRENT_PROMISES[O]=i.apply(void 0,y)}else{o.CONCURRENT_PROMISES[O]=i(O)}o.CONCURRENT_PROMISES_TS[O]=u=Date.now();return[4,o.CONCURRENT_PROMISES[O]];case 4:n=a.sent();setTimeout(function(){delete o.CONCURRENT_PROMISES[O];delete o.CONCURRENT_PROMISES_TS[O]},l.dedupingInterval);l.onSuccess(n,O,l);a.label=5;case 5:if(o.MUTATION_TS[O]&&u<=o.MUTATION_TS[O]){M({isValidating:false});return[2,false]}o.cacheSet(O,n);o.cacheSet(T,undefined);N.current=O;f={isValidating:false};if(typeof I.current.error!=="undefined"){f.error=undefined}if(l.compare(I.current.data,n)){}else{f.data=n}M(f);if(!t){E(O,n,undefined)}return[3,7];case 6:c=a.sent();delete o.CONCURRENT_PROMISES[O];delete o.CONCURRENT_PROMISES_TS[O];o.cacheSet(T,c);N.current=O;if(I.current.error!==c){M({isValidating:false,error:c});if(!t){E(O,undefined,c)}}l.onError(c,O,l);if(l.shouldRetryOnError){s=(r.retryCount||0)+1;l.onErrorRetry(c,O,l,V,Object.assign({dedupe:true},r,{retryCount:s}))}return[3,7];case 7:e=false;return[2,true]}})})},[O]);R(function(){if(!O)return undefined;m.current=false;var e=I.current.data;var r=o.cacheGet(O)||l.initialData;if(N.current!==O||!l.compare(e,r)){M({data:r});N.current=O}var t=function(){return V({dedupe:true})};if(!l.initialData){if(typeof r!=="undefined"&&!p&&window["requestIdleCallback"]){window["requestIdleCallback"](t)}else{t()}}var n;if(l.revalidateOnFocus){n=d.default(t,l.focusThrottleInterval);if(!o.FOCUS_REVALIDATORS[O]){o.FOCUS_REVALIDATORS[O]=[n]}else{o.FOCUS_REVALIDATORS[O].push(n)}}var a=function(e,r,n,a){if(e===void 0){e=true}if(a===void 0){a=true}var u={};var i=false;if(typeof r!=="undefined"&&!l.compare(I.current.data,r)){u.data=r;i=true}if(I.current.error!==n){u.error=n;i=true}if(i){M(u)}N.current=O;if(e){if(a){return t()}else{return V()}}return false};if(!o.CACHE_REVALIDATORS[O]){o.CACHE_REVALIDATORS[O]=[a]}else{o.CACHE_REVALIDATORS[O].push(a)}var u=null;if(typeof addEventListener!=="undefined"&&l.revalidateOnReconnect){u=addEventListener("online",t)}return function(){M=function(){return null};m.current=true;if(n&&o.FOCUS_REVALIDATORS[O]){var e=o.FOCUS_REVALIDATORS[O];var r=e.indexOf(n);if(r>=0){e[r]=e[e.length-1];e.pop()}}if(o.CACHE_REVALIDATORS[O]){var e=o.CACHE_REVALIDATORS[O];var r=e.indexOf(a);if(r>=0){e[r]=e[e.length-1];e.pop()}}if(typeof removeEventListener!=="undefined"&&u!==null){removeEventListener("online",u)}}},[O,V]);R(function(){var r=null;var t=function(){return n(e,void 0,void 0,function(){return a(this,function(e){switch(e.label){case 0:if(!(!I.current.error&&(l.refreshWhenHidden||c.default())&&(!l.refreshWhenOffline&&s.default())))return[3,2];return[4,V({dedupe:true})];case 1:e.sent();e.label=2;case 2:if(l.refreshInterval){r=setTimeout(t,l.refreshInterval)}return[2]}})})};if(l.refreshInterval){r=setTimeout(t,l.refreshInterval)}return function(){if(r)clearTimeout(r)}},[l.refreshInterval,l.refreshWhenHidden,l.refreshWhenOffline,V]);if(l.suspense){if(p)throw new Error("Suspense on server side is not yet supported!");var D=o.cacheGet(O);var L=o.cacheGet(T);if(typeof D==="undefined"&&typeof L==="undefined"){if(!o.CONCURRENT_PROMISES[O]){V()}if(o.CONCURRENT_PROMISES[O]&&typeof o.CONCURRENT_PROMISES[O].then==="function"){throw o.CONCURRENT_PROMISES[O]}D=o.CONCURRENT_PROMISES[O]}if(typeof D==="undefined"&&L){throw L}return{error:L,data:D,revalidate:V,mutate:P,isValidating:I.current.isValidating}}return f.useMemo(function(){var e={revalidate:V,mutate:P};Object.defineProperties(e,{error:{get:function(){g.current.error=true;return N.current===O?I.current.error:w}},data:{get:function(){g.current.data=true;return N.current===O?I.current.data:b}},isValidating:{get:function(){g.current.isValidating=true;return I.current.isValidating}}});return e},[V])}var y=v.default.Provider;r.SWRConfig=y;r.default=useSWR},542:function(e,r){"use strict";Object.defineProperty(r,"__esModule",{value:true});function throttle(e,r){var t=false;return function(){var n=[];for(var a=0;a<arguments.length;a++){n[a]=arguments[a]}if(t)return;t=true;e.apply(void 0,n);setTimeout(function(){return t=false},r)}}r.default=throttle},641:function(e,r,t){"use strict";var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(r,"__esModule",{value:true});var a=n(t(832));var u=n(t(459));var i=n(t(205));var f=new Map;function cacheGet(e){return f.get(e)}r.cacheGet=cacheGet;function cacheSet(e,r){return f.set(e,r)}r.cacheSet=cacheSet;function cacheClear(){f.clear()}r.cacheClear=cacheClear;var o={};r.CONCURRENT_PROMISES=o;var l={};r.CONCURRENT_PROMISES_TS=l;var c={};r.FOCUS_REVALIDATORS=c;var s={};r.CACHE_REVALIDATORS=s;var d={};r.MUTATION_TS=d;function onErrorRetry(e,r,t,n,a){if(!u.default()){return}if(t.errorRetryCount&&a.retryCount>t.errorRetryCount){return}var i=Math.min(a.retryCount||0,8);var f=~~((Math.random()+.5)*(1<<i))*t.errorRetryInterval;setTimeout(n,f,a)}var v=typeof window!=="undefined"&&navigator["connection"]&&["slow-2g","2g"].indexOf(navigator["connection"].effectiveType)!==-1;var p={onLoadingSlow:function(){},onSuccess:function(){},onError:function(){},onErrorRetry:onErrorRetry,errorRetryInterval:(v?10:5)*1e3,focusThrottleInterval:5*1e3,dedupingInterval:2*1e3,loadingTimeout:(v?5:3)*1e3,refreshInterval:0,revalidateOnFocus:true,revalidateOnReconnect:true,refreshWhenHidden:false,refreshWhenOffline:false,shouldRetryOnError:true,suspense:false,compare:a.default};var R=false;if(typeof window!=="undefined"&&window.addEventListener&&!R){var h=function(){if(!u.default()||!i.default())return;for(var e in c){if(c[e][0])c[e][0]()}};window.addEventListener("visibilitychange",h,false);window.addEventListener("focus",h,false);R=true}r.default=p},832:function(e){"use strict";var r=Array.isArray;var t=Object.keys;var n=Object.prototype.hasOwnProperty;e.exports=function equal(e,a){if(e===a)return true;if(e&&a&&typeof e=="object"&&typeof a=="object"){var u=r(e),i=r(a),f,o,l;if(u&&i){o=e.length;if(o!=a.length)return false;for(f=o;f--!==0;)if(!equal(e[f],a[f]))return false;return true}if(u!=i)return false;var c=e instanceof Date,s=a instanceof Date;if(c!=s)return false;if(c&&s)return e.getTime()==a.getTime();var d=e instanceof RegExp,v=a instanceof RegExp;if(d!=v)return false;if(d&&v)return e.toString()==a.toString();var p=t(e);o=p.length;if(o!==t(a).length)return false;for(f=o;f--!==0;)if(!n.call(a,p[f]))return false;for(f=o;f--!==0;){l=p[f];if(!equal(e[l],a[l]))return false}return true}return e!==e&&a!==a}},926:function(e,r,t){"use strict";var n=this&&this.__spreadArrays||function(){for(var e=0,r=0,t=arguments.length;r<t;r++)e+=arguments[r].length;for(var n=Array(e),a=0,r=0;r<t;r++)for(var u=arguments[r],i=0,f=u.length;i<f;i++,a++)n[a]=u[i];return n};var a=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var r={};if(e!=null)for(var t in e)if(Object.hasOwnProperty.call(e,t))r[t]=e[t];r["default"]=e;return r};Object.defineProperty(r,"__esModule",{value:true});var u=a(t(297));var i=t(641);var f=new Map;function useSWRPages(e,r,t,a){if(a===void 0){a=[]}var o="_swr_page_count_"+e;var l="_swr_page_offset_"+e;var c=u.useState(i.cacheGet(o)||1),s=c[0],d=c[1];var v=u.useState(i.cacheGet(l)||[null]),p=v[0],R=v[1];var h=u.useState([]),S=h[0],_=h[1];var O=u.useRef(r);var E=u.useRef(false);var C=u.useCallback(function(e){var r=O.current(e);if(r&&!r.length){E.current=true}else{E.current=false}return r},[]);var y=p[s]===null;var T=s===p.length;var b=y&&s===1&&E.current;var w=u.useCallback(function(){if(T||y)return;d(function(e){i.cacheSet(o,e+1);return e+1})},[T||y]);var g=u.useCallback(r,a);O.current=g;var I=u.useMemo(function(){var r=function(e){return function(r){if(!S[e]||S[e].data!==r.data||S[e].error!==r.error||S[e].revalidate!==r.revalidate){_(function(t){var a=n(t);a[e]={data:r.data,error:r.error,revalidate:r.revalidate,isValidating:r.isValidating,mutate:r.mutate};return a});if(typeof r.data!=="undefined"){var a=t(r,e);if(p[e+1]!==a){R(function(r){var t=n(r);t[e+1]=a;i.cacheSet(l,t);return t})}}}return r}};var a=[];if(!f.has(e)){f.set(e,[])}var o=f.get(e);for(var c=0;c<s;++c){if(!o[c]||o[c].offset!==p[c]||o[c].pageFn!==g){o[c]={component:u.default.createElement(C,{key:"page-"+p[c]+"-"+c,offset:p[c],withSWR:r(c)}),pageFn:g,offset:p[c]}}a.push(o[c].component)}return a},[g,s,S,p,e]);return{pages:I,pageCount:s,pageSWRs:S,isLoadingMore:T,isReachingEnd:y,isEmpty:b,loadMore:w}}r.useSWRPages=useSWRPages}}); |
export declare type fetcherFn<Data> = (...args: any) => Data | Promise<Data>; | ||
export interface ConfigInterface<Data = any, Error = any, Fn extends fetcherFn<Data> = fetcherFn<Data>> { | ||
errorRetryInterval?: number; | ||
errorRetryCount?: number; | ||
loadingTimeout?: number; | ||
@@ -30,3 +31,4 @@ focusThrottleInterval?: number; | ||
export declare type triggerInterface = (key: keyInterface, shouldRevalidate?: boolean) => void; | ||
export declare type mutateInterface<Data = any> = (key: keyInterface, data: Data | Promise<Data>, shouldRevalidate?: boolean) => void; | ||
declare type mutateCallback<Data = any> = (currentValue: Data) => Data; | ||
export declare type mutateInterface<Data = any> = (key: keyInterface, data?: Data | Promise<Data> | mutateCallback<Data>, shouldRevalidate?: boolean) => Promise<Data | undefined>; | ||
export declare type broadcastStateInterface<Data = any, Error = any> = (key: string, data: Data, error?: Error) => void; | ||
@@ -37,2 +39,3 @@ export declare type responseInterface<Data, Error> = { | ||
revalidate: () => Promise<boolean>; | ||
mutate: (data?: Data | Promise<Data> | mutateCallback<Data>, shouldRevalidate?: boolean) => Promise<Data | undefined>; | ||
isValidating: boolean; | ||
@@ -39,0 +42,0 @@ }; |
@@ -28,2 +28,5 @@ import deepEqual from 'fast-deep-equal'; | ||
} | ||
if (config.errorRetryCount && opts.retryCount > config.errorRetryCount) { | ||
return; | ||
} | ||
// exponential backoff | ||
@@ -30,0 +33,0 @@ const count = Math.min(opts.retryCount || 0, 8); |
export declare type fetcherFn<Data> = (...args: any) => Data | Promise<Data>; | ||
export interface ConfigInterface<Data = any, Error = any, Fn extends fetcherFn<Data> = fetcherFn<Data>> { | ||
errorRetryInterval?: number; | ||
errorRetryCount?: number; | ||
loadingTimeout?: number; | ||
@@ -30,3 +31,4 @@ focusThrottleInterval?: number; | ||
export declare type triggerInterface = (key: keyInterface, shouldRevalidate?: boolean) => void; | ||
export declare type mutateInterface<Data = any> = (key: keyInterface, data: Data | Promise<Data>, shouldRevalidate?: boolean) => void; | ||
declare type mutateCallback<Data = any> = (currentValue: Data) => Data; | ||
export declare type mutateInterface<Data = any> = (key: keyInterface, data?: Data | Promise<Data> | mutateCallback<Data>, shouldRevalidate?: boolean) => Promise<Data | undefined>; | ||
export declare type broadcastStateInterface<Data = any, Error = any> = (key: string, data: Data, error?: Error) => void; | ||
@@ -37,2 +39,3 @@ export declare type responseInterface<Data, Error> = { | ||
revalidate: () => Promise<boolean>; | ||
mutate: (data?: Data | Promise<Data> | mutateCallback<Data>, shouldRevalidate?: boolean) => Promise<Data | undefined>; | ||
isValidating: boolean; | ||
@@ -39,0 +42,0 @@ }; |
@@ -132,3 +132,4 @@ import React, { useCallback, useMemo, useState, useRef } from 'react'; | ||
revalidate: swr.revalidate, | ||
isValidating: swr.isValidating | ||
isValidating: swr.isValidating, | ||
mutate: swr.mutate | ||
}; | ||
@@ -135,0 +136,0 @@ return _swrs; |
@@ -37,2 +37,3 @@ import { useCallback, useContext, useEffect, useLayoutEffect, useState, useRef, useMemo } from 'react'; | ||
}; | ||
const NO_DEDUPE = false; | ||
const trigger = (_key, shouldRevalidate = true) => { | ||
@@ -47,3 +48,3 @@ const [key] = getKeyArgs(_key); | ||
for (let i = 0; i < updaters.length; ++i) { | ||
updaters[i](shouldRevalidate, currentData, currentError, true); | ||
updaters[i](shouldRevalidate, currentData, currentError, NO_DEDUPE); | ||
} | ||
@@ -60,10 +61,22 @@ } | ||
}; | ||
const mutate = async (_key, _data, shouldRevalidate) => { | ||
const mutate = async (_key, _data, shouldRevalidate = true) => { | ||
const [key] = getKeyArgs(_key); | ||
if (!key) | ||
return; | ||
// if there is no new data, call revalidate against the key | ||
if (typeof _data === 'undefined') | ||
return trigger(_key, shouldRevalidate); | ||
// update timestamp | ||
MUTATION_TS[key] = Date.now() - 1; | ||
let data, error; | ||
if (_data && typeof _data.then === 'function') { | ||
if (_data && typeof _data === 'function') { | ||
// `_data` is a function, call it passing current cache value | ||
try { | ||
data = await _data(cacheGet(key)); | ||
} | ||
catch (err) { | ||
error = err; | ||
} | ||
} | ||
else if (_data && typeof _data.then === 'function') { | ||
// `_data` is a promise | ||
@@ -79,7 +92,2 @@ try { | ||
data = _data; | ||
if (typeof shouldRevalidate === 'undefined') { | ||
// if it's a sync mutation, we trigger the revalidation by default | ||
// because in most cases it's a local mutation | ||
shouldRevalidate = true; | ||
} | ||
} | ||
@@ -94,5 +102,9 @@ if (typeof data !== 'undefined') { | ||
for (let i = 0; i < updaters.length; ++i) { | ||
updaters[i](!!shouldRevalidate, data, error, true); | ||
updaters[i](!!shouldRevalidate, data, error, NO_DEDUPE); | ||
} | ||
} | ||
// throw error or return data to be used by caller of mutate | ||
if (error) | ||
throw error; | ||
return data; | ||
}; | ||
@@ -158,2 +170,5 @@ function useSWR(...args) { | ||
const keyRef = useRef(key); | ||
const boundMutate = useCallback((data, shouldRevalidate) => { | ||
return mutate(key, data, shouldRevalidate); | ||
}, [key]); | ||
// start a revalidation | ||
@@ -461,2 +476,3 @@ const revalidate = useCallback(async (revalidateOpts = {}) => { | ||
revalidate, | ||
mutate: boundMutate, | ||
isValidating: stateRef.current.isValidating | ||
@@ -468,3 +484,3 @@ }; | ||
return useMemo(() => { | ||
const state = { revalidate }; | ||
const state = { revalidate, mutate: boundMutate }; | ||
Object.defineProperties(state, { | ||
@@ -471,0 +487,0 @@ error: { |
{ | ||
"name": "swr", | ||
"version": "0.1.17", | ||
"version": "0.1.18", | ||
"description": "React Hooks library for remote data fetching", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.js", |
@@ -93,3 +93,3 @@ [![SWR](https://assets.zeit.co/image/upload/v1572289618/swr/banner.png)](https://swr.now.sh) | ||
```js | ||
const { data, error, isValidating, revalidate } = useSWR(key, fetcher, options) | ||
const { data, error, isValidating, mutate } = useSWR(key, fetcher, options) | ||
``` | ||
@@ -107,3 +107,3 @@ | ||
- `isValidating`: if there's a request or revalidation loading | ||
- `revalidate`: function to trigger the validation manually | ||
- `mutate`: function to mutate the cached data | ||
@@ -125,2 +125,3 @@ #### Options | ||
- `errorRetryInterval = 5000`: error retry interval [(details)](#error-retries) | ||
- `errorRetryCount`: max error retry count [(details)](#error-retries) | ||
- `onLoadingSlow`: callback function when a request takes too long to load (see `loadingTimeout`) | ||
@@ -147,2 +148,4 @@ - `onSuccess`: callback function when a request finishes successfully | ||
- [Mutation and Post Request](#mutation-and-post-request) | ||
- [Mutate Based on Current Data](#mutate-based-on-current-data) | ||
- [Returned Data from Mutate](#returned-data-from-mutate) | ||
- [SSR with Next.js](#ssr-with-nextjs) | ||
@@ -296,3 +299,3 @@ - [Suspense Mode](#suspense-mode) | ||
You can broadcast a revalidation message globally to all SWRs with the same key by calling | ||
`trigger(key)`. | ||
`mutate(key)`. | ||
@@ -303,3 +306,3 @@ This example shows how to automatically refetch the login info (e.g.: inside `<Profile/>`) | ||
```js | ||
import useSWR, { trigger } from 'swr' | ||
import useSWR, { mutate } from 'swr' | ||
@@ -315,3 +318,3 @@ function App () { | ||
// tell all SWRs with this key to revalidate | ||
trigger('/api/user') | ||
mutate('/api/user') | ||
}}> | ||
@@ -366,2 +369,29 @@ Logout | ||
### Mutate Based on Current Data | ||
In many cases, you are receiving a single value back from your API and want to update a list of them. | ||
With `mutate`, you can pass an async function which will receive the current cached value, if any, and let you return an updated document. | ||
```js | ||
mutate('/api/users', async users => { | ||
const user = await fetcher('/api/users/1') | ||
return [user, ...users.slice(1)] | ||
}) | ||
``` | ||
### Returned Data from Mutate | ||
Most probably, you need to data mutate used to update the cache when you passed a promise or async function. | ||
The function will returns the updated document, or throw an error, everytime you call it. | ||
```js | ||
try { | ||
const user = await mutate('/api/user', updateUser(newUser)) | ||
} catch (error) { | ||
// Handle an error while updating the user here | ||
} | ||
``` | ||
### SSR with Next.js | ||
@@ -368,0 +398,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
76706
1041
494