{"version":3,"sources":["../../src/use-re-connect/index.ts"],"sourcesContent":["import { useEffectOnce } from '../use-effect-once'\nimport { useLatest } from '../use-latest'\n\nimport type { AnyFunc } from '../utils/basic'\n\nexport interface UseReConnectOptions {\n  /**\n   * Register reconnect event listener.\n   */\n  registerReConnect?: (callback: AnyFunc) => void\n}\n\nexport function registerWebReConnect(callback: AnyFunc): () => void {\n  function handleOnline() {\n    callback()\n  }\n\n  window.addEventListener('online', handleOnline, { passive: true })\n\n  return (): void => {\n    window.removeEventListener('online', handleOnline)\n  }\n}\n\n/**\n * A hook to call the callback when the network is reconnected.\n *\n * @since 1.4.0\n */\nexport function useReConnect(callback: AnyFunc, options: UseReConnectOptions = {}): void {\n  const { registerReConnect = registerWebReConnect } = options\n\n  const latest = useLatest({ callback })\n\n  useEffectOnce(() => {\n    return registerReConnect(() => latest.current.callback())\n  })\n}\n"],"names":["registerWebReConnect","useReConnect","callback","handleOnline","window","addEventListener","passive","removeEventListener","options","registerReConnect","latest","useLatest","useEffectOnce","current"],"mappings":";;;;;;;;;;;QAYgBA;eAAAA;;QAiBAC;eAAAA;;;6BA7Bc;yBACJ;AAWnB,SAASD,qBAAqBE,QAAiB;IACpD,SAASC;QACPD;IACF;IAEAE,OAAOC,gBAAgB,CAAC,UAAUF,cAAc;QAAEG,SAAS;IAAK;IAEhE,OAAO;QACLF,OAAOG,mBAAmB,CAAC,UAAUJ;IACvC;AACF;AAOO,SAASF,aAAaC,QAAiB;QAAEM,UAAAA,iEAA+B,CAAC;IAC9E,iCAAqDA,QAA7CC,mBAAAA,4DAAoBT;IAE5B,IAAMU,SAASC,IAAAA,oBAAS,EAAC;QAAET,UAAAA;IAAS;IAEpCU,IAAAA,4BAAa,EAAC;QACZ,OAAOH,kBAAkB;mBAAMC,OAAOG,OAAO,CAACX,QAAQ;;IACxD;AACF"}