TreasureTrails/node_modules/remeda/dist/debounce.cjs.map

1 line
14 KiB
Text
Raw Normal View History

2026-03-18 09:02:21 -05:00
{"version":3,"file":"debounce.cjs","names":["coolDownTimeoutId: ReturnType<typeof setTimeout> | undefined","maxWaitTimeoutId: ReturnType<typeof setTimeout> | undefined","latestCallArgs: Parameters<F> | undefined","result: ReturnType<F> | undefined"],"sources":["../src/debounce.ts"],"sourcesContent":["import type { StrictFunction } from \"./internal/types/StrictFunction\";\n\ntype Debouncer<F extends StrictFunction, IsNullable extends boolean = true> = {\n /**\n * Invoke the debounced function.\n *\n * @param args - Same as the args for the debounced function.\n * @returns The last computed value of the debounced function with the\n * latest args provided to it. If `timing` does not include `leading` then the\n * the function would return `undefined` until the first cool-down period is\n * over, otherwise the function would always return the return type of the\n * debounced function.\n */\n readonly call: (\n ...args: Parameters<F>\n ) => ReturnType<F> | (true extends IsNullable ? undefined : never);\n\n /**\n * Cancels any debounced functions without calling them, effectively resetting\n * the debouncer to the same state it is when initially created.\n */\n readonly cancel: () => void;\n\n /**\n * Similar to `cancel`, but would also trigger the `trailing` invocation if\n * the debouncer would run one at the end of the cool-down period.\n */\n readonly flush: () => ReturnType<F> | undefined;\n\n /**\n * Is `true` when there is an active cool-down period currently debouncing\n * invocations.\n */\n readonly isPending: boolean;\n\n /**\n * The last computed value of the debounced function.\n */\n readonly cachedValue: ReturnType<F> | undefined;\n};\n\ntype DebounceOptions = {\n readonly waitMs?: number;\n readonly maxWaitMs?: number;\n};\n\n/**\n * Wraps `func` with a debouncer object that \"debounces\" (delays) invocations of the function during a defined cool-down period (`waitMs`). It can be configured to invoke the function either at the start of the cool-down period, the end of it, or at both ends (`timing`).\n * It can also be configured to allow invocations during the cool-down period (`maxWaitMs`).\n * It stores the latest call's arguments so they could be used at the end of the cool-down period when invoking `func` (if configured to invoke the function at the end of the cool-down period).\n * It stores the value returned by `func` whenever its invoked. This value is returned on every call, and is accessible via the `cachedValue` property of the debouncer. Its important to note that the value might be different from the value that would be returned from running `func` with the current arguments as it is a cached value from a previous invocation.\n * **Important**: The cool-down period defines the minimum between two invocations, and not the maximum. The period will be **extended** each time a call is made until a full cool-down period has elapsed without any additional calls.\n *\n *! **DEPRECATED**: This implementation of debounce is known to have issues and might not behave as expected. It should be replaced with the `funnel` utility instead. The test file [funnel.remeda-debounce.test.ts](https://github.com/remeda/remeda/blob/main/packages/remeda/src/funnel.remeda-debounce.test.ts) offers a reference implementation that replicates `debounce` via `funnel`!\n *\n * @param func - The function to debounce, the returned `call` function will have\n * the exact same signature.\n * @param options - An object allowing further customization of the debouncer:\n * - `timing?: 'leading' | 'trailing' |'both'`. The default is `'trailing'`.\n * `leading` would result in the function being invoked at the start of the\n * cool-down period; `trailing` would result in the function being invoked at\n * the end of the cool-down period (using the args from the last call to the\n * debouncer). When `both` is selected the `trailing` invocation would only\n * take place if there were more than one call to the debouncer during the\n * cool-down period. **DEFAULT: 'trailing