{"version":3,"file":"useRateLimitedCallback.cjs","names":["useRateLimiter"],"sources":["../../src/rate-limiter/useRateLimitedCallback.ts"],"sourcesContent":["import { useCallback } from 'react'\nimport { useRateLimiter } from './useRateLimiter'\nimport type { AnyFunction } from '@tanstack/pacer/types'\nimport type { ReactRateLimiterOptions } from './useRateLimiter'\n\n/**\n * A React hook that creates a rate-limited version of a callback function.\n * This hook is essentially a wrapper around the basic `rateLimiter` function\n * that is exported from `@tanstack/pacer`,\n * but optimized for React with reactive options and a stable function reference.\n *\n * Rate limiting is a simple \"hard limit\" approach - it allows all calls until the limit\n * is reached, then blocks subsequent calls until the window resets. Unlike throttling\n * or debouncing, it does not attempt to space out or intelligently collapse calls.\n * This can lead to bursts of rapid executions followed by periods where all calls\n * are blocked.\n *\n * The rate limiter supports two types of windows:\n * - 'fixed': A strict window that resets after the window period. All executions within the window count\n *   towards the limit, and the window resets completely after the period.\n * - 'sliding': A rolling window that allows executions as old ones expire. This provides a more\n *   consistent rate of execution over time.\n *\n * For smoother execution patterns, consider:\n * - useThrottledCallback: When you want consistent spacing between executions (e.g. UI updates)\n * - useDebouncedCallback: When you want to collapse rapid calls into a single execution (e.g. search input)\n *\n * Rate limiting should primarily be used when you need to enforce strict limits,\n * like API rate limits or other scenarios requiring hard caps on execution frequency.\n *\n * This hook provides a simpler API compared to `useRateLimiter`, making it ideal for basic\n * rate limiting needs. However, it does not expose the underlying RateLimiter instance.\n *\n * For advanced usage requiring features like:\n * - Manual cancellation\n * - Access to execution counts\n * - Custom useCallback dependencies\n *\n * Consider using the `useRateLimiter` hook instead.\n *\n * @example\n * ```tsx\n * // Rate limit API calls to maximum 5 calls per minute with a sliding window\n * const makeApiCall = useRateLimitedCallback(\n *   (data: ApiData) => {\n *     return fetch('/api/endpoint', { method: 'POST', body: JSON.stringify(data) });\n *   },\n *   {\n *     limit: 5,\n *     window: 60000, // 1 minute\n *     windowType: 'sliding',\n *     onReject: () => {\n *       console.warn('API rate limit reached. Please wait before trying again.');\n *     }\n *   }\n * );\n * ```\n */\nexport function useRateLimitedCallback<TFn extends AnyFunction>(\n  fn: TFn,\n  options: ReactRateLimiterOptions<TFn, {}>,\n): (...args: Parameters<TFn>) => boolean {\n  const rateLimitedFn = useRateLimiter(fn, options).maybeExecute\n  return useCallback((...args) => rateLimitedFn(...args), [rateLimitedFn])\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0DA,SAAgB,uBACd,IACA,SACuC;CACvC,MAAM,gBAAgBA,sCAAe,IAAI,QAAQ,CAAC;AAClD,gCAAoB,GAAG,SAAS,cAAc,GAAG,KAAK,EAAE,CAAC,cAAc,CAAC"}