diff --git a/client/src/socket/memoize-debounce.ts b/client/src/socket/memoize-debounce.ts index 9c2e4ba..7ab9f9e 100644 --- a/client/src/socket/memoize-debounce.ts +++ b/client/src/socket/memoize-debounce.ts @@ -1,15 +1,24 @@ import _ from 'lodash'; // eslint-disable-next-line @typescript-eslint/no-explicit-any -export interface MemoizeDebouncedFunction any> +type AnyFunction = (...args: any[]) => any; + +export interface MemoizeDebouncedFunction extends _.DebouncedFunc { (...args: Parameters): ReturnType | undefined; flush: (...args: Parameters) => ReturnType | undefined; cancel: (...args: Parameters) => void; } -// eslint-disable-next-line @typescript-eslint/no-explicit-any -export function memoizeDebounce any>( +/**Combines Lodash's _.debounce with _.memoize to allow for debouncing + * based on parameters passed to the function during runtime. + * + * @param func The function to debounce. + * @param wait The number of milliseconds to delay. + * @param options Lodash debounce options object. + * @param resolver The function to resolve the cache key. + */ +export function memoizeDebounce( func: F, wait = 0, options: _.DebounceSettings = {}, @@ -31,11 +40,13 @@ export function memoizeDebounce any>( const flush: MemoizeDebouncedFunction['flush'] = (...args) => { return debounceMemo(...args).flush(); }; - wrappedFunction.flush = flush; - wrappedFunction.cancel = (...args: Parameters): void => { + const cancel: MemoizeDebouncedFunction['cancel'] = (...args) => { return debounceMemo(...args).cancel(); }; + wrappedFunction.flush = flush; + wrappedFunction.cancel = cancel; + return wrappedFunction; }