import type { PublicConfiguration , FullConfiguration , RevalidatorOptions , Revalidator , ScopedMutator , Cache } from '../types' ; import { stableHash } from './hash' ; import { initCache } from './cache' ; import { preset } from './web-preset' ; import { slowConnection } from './env' ; import { isUndefined , noop , mergeObjects } from './helper' ; const onErrorRetry = ( _ , __ , config , revalidate , opts ) : void => { const maxRetryCount = config . errorRetryCount ; const currentRetryCount = opts . retryCount ; const timeout = ~ ~ ( ( Math . random ( ) + 0.5 ) * ( 1 << ( currentRetryCount < 8 ? currentRetryCount : 8 ) ) ) * config . errorRetryInterval ; if ( ! isUndefined ( maxRetryCount ) && currentRetryCount > maxRetryCount ) { return ; } setTimeout ( revalidate , timeout , opts ) ; } ; const [ cache , mutate ] = initCache ( new Map ( ) ) as [ Cache < any > , ScopedMutator < any > , ( ) => { } ] ; export { cache , mutate } ; export const defaultConfig = mergeObjects ( { onLoadingSlow : noop , onSuccess : noop , onError : noop , onErrorRetry , onDiscarded : noop , revalidateOnFocus : true , revalidateOnReconnect : true , revalidateIfStale : true , shouldRetryOnError : true , errorRetryInterval : slowConnection ? 10000 : 5000 , focusThrottleInterval : 5 * 1000 , dedupingInterval : 2 * 1000 , loadingTimeout : slowConnection ? 5000 : 3000 , compare : ( currentData , newData ) => stableHash ( currentData ) == stableHash ( newData ) , isPaused : ( ) => false , cache , mutate , fallback : { } } , preset ) ;