{"version":3,"sources":["../../src/onSlowLoading/index.ts"],"names":["_root","_slowLoading","_callbacks"],"mappings":";;;AA2BA,IAAM,aAAA,GAAgB,CAAC,KAAA,EAAmB,EAAmB,KAAA;AAC3D,EAAM,MAAA,WAAA,GAAc,MAAMA,CAAMC,CAAAA,CAAAA;AAEhC,EAAA,IAAI,CAAC,WAAa,EAAA;AAChB,IAAM,MAAA,IAAI,MAAM,uCAAuC,CAAA;AAAA;AAGzD,EAAA,MAAM,MAAM,WAAYC,CAAAA,CAAAA;AAExB,EAAA,GAAA,CAAI,IAAI,EAAE,CAAA;AAEV,EAAA,OAAO,MAAM;AACX,IAAA,GAAA,CAAI,OAAO,EAAE,CAAA;AAAA,GACf;AACF,CAAA;AAEA,IAAO,qBAAQ,GAAA","file":"chunk-SGGRHT4S.cjs","sourcesContent":["import type { AsyncState } from '../types';\n\n/**\n * Registers a callback to be invoked when the given {@link state} triggers a slow loading timeout.\n * Throws an error if the state does not have a slow loading timeout configured.\n *\n * @param state - The asynchronous state to monitor.\n * @param cb - The callback function to invoke when the loading is considered slow.\n * @returns A function to remove the registered callback.\n *\n * @throws {Error} - If the state does not have a slow loading timeout configured.\n *\n * @example\n * ```js\n * const asyncState = createAsyncState({\n *   ...options,\n *   loadingTimeout: 3000, // Configure the slow loading timeout\n * });\n *\n * const unsubscribe = onSlowLoading(asyncState, () => {\n *   console.warn('Loading is taking longer than expected.');\n * });\n *\n * // To remove the callback later\n * unsubscribe();\n * ```\n */\nconst onSlowLoading = (state: AsyncState, cb: () => void) => {\n  const slowLoading = state._root._slowLoading;\n\n  if (!slowLoading) {\n    throw new Error('slow loading timeout was not provided');\n  }\n\n  const set = slowLoading._callbacks;\n\n  set.add(cb);\n\n  return () => {\n    set.delete(cb);\n  };\n};\n\nexport default onSlowLoading;\n"]}