{
  "version": 3,
  "sources": ["../../../src/limiter/use-limiter.ts"],
  "sourcesContent": ["import { DEFAULT_PRIORITY } from 'client-run-queue';\nimport { useEffect, useMemo, useRef } from 'react';\n\nimport { useDefaultQueue } from '../default-queue/default-queue-context.mjs';\nimport { LimiterImpl } from './internal/LimiterImpl.mjs';\nimport type { Limiter } from './types/Limiter';\nimport type { LimiterOptions } from './types/LimiterOptions';\n\nconst noOp = () => {};\n\n/** Creates a limiter which can be used to debounce or throttle a function call. */\nexport const useLimiter = ({\n  id,\n  cancelOnUnmount = false,\n  limitType = 'debounce',\n  limitMode = 'trailing',\n  limitMSec = 0,\n  priority = DEFAULT_PRIORITY,\n  queue\n}: LimiterOptions & {\n  /** A technical, but human-readable ID, which isn't guaranteed to be unique */\n  id: string;\n  /**\n   * If `true`, any previously scheduled functions are automatically canceled on unmount\n   *\n   * @defaultValue `false`\n   */\n  cancelOnUnmount?: boolean;\n}) => {\n  const defaultQueue = useDefaultQueue();\n\n  queue = queue ?? defaultQueue;\n\n  const previousLimiter = useRef<Limiter | undefined>(undefined);\n  const limiter = useMemo<Limiter>(\n    () => new LimiterImpl(id, { limitMSec, limitMode, limitType, priority, queue: queue! }),\n    [id, limitMSec, limitMode, limitType, priority, queue]\n  );\n\n  // If the limiter changed, cancel the previous one since it's no longer managed by this hook\n  if (previousLimiter.current !== undefined && previousLimiter.current !== limiter) {\n    previousLimiter.current.cancel();\n  }\n  previousLimiter.current = limiter;\n\n  const unmountCleanup = useRef(noOp);\n  unmountCleanup.current = cancelOnUnmount ? () => limiter.cancel() : noOp;\n\n  useEffect(() => (cancelOnUnmount ? () => unmountCleanup.current() : undefined));\n\n  return limiter;\n};\n"],
  "mappings": "AAAA,SAAS,wBAAwB;AACjC,SAAS,WAAW,SAAS,cAAc;AAE3C,SAAS,uBAAuB;AAChC,SAAS,mBAAmB;AAI5B,MAAM,OAAO,MAAM;AAAC;AAGb,MAAM,aAAa,CAAC;AAAA,EACzB;AAAA,EACA,kBAAkB;AAAA,EAClB,YAAY;AAAA,EACZ,YAAY;AAAA,EACZ,YAAY;AAAA,EACZ,WAAW;AAAA,EACX;AACF,MASM;AACJ,QAAM,eAAe,gBAAgB;AAErC,UAAQ,SAAS;AAEjB,QAAM,kBAAkB,OAA4B,MAAS;AAC7D,QAAM,UAAU;AAAA,IACd,MAAM,IAAI,YAAY,IAAI,EAAE,WAAW,WAAW,WAAW,UAAU,MAAc,CAAC;AAAA,IACtF,CAAC,IAAI,WAAW,WAAW,WAAW,UAAU,KAAK;AAAA,EACvD;AAGA,MAAI,gBAAgB,YAAY,UAAa,gBAAgB,YAAY,SAAS;AAChF,oBAAgB,QAAQ,OAAO;AAAA,EACjC;AACA,kBAAgB,UAAU;AAE1B,QAAM,iBAAiB,OAAO,IAAI;AAClC,iBAAe,UAAU,kBAAkB,MAAM,QAAQ,OAAO,IAAI;AAEpE,YAAU,MAAO,kBAAkB,MAAM,eAAe,QAAQ,IAAI,MAAU;AAE9E,SAAO;AACT;",
  "names": []
}
