@rxap/utilities
Version:
A collection of utility functions, types and interfaces.
32 lines (31 loc) • 1.34 kB
TypeScript
/**
* `DebounceCall` is a method decorator that delays the execution of the method it decorates.
* It is used to ensure that time-consuming tasks do not fire so often, which can lead to performance issues.
*
* @export
* @function
* @param {number} [delay=300] - The delay in milliseconds before the decorated method is called. Default is 300ms.
* @returns {MethodDecorator} - A method decorator that can be applied to a method with the '@' syntax.
*
* @example
*
* class MyClass {
* @DebounceCall(500)
* myMethod() {
* // This method will be debounced
* }
* }
* ```
*
* @remarks
* The decorator works by replacing the descriptor's value (the original method) with a new function that clears any existing timeout and sets a new one each time the method is called.
* The new timeout will call the original method after the specified delay.
* The timeout ID is stored on the instance using a unique key derived from the method's name.
*
* @param target - The prototype of the class (or the constructor function for a static method).
* @param propertyKey - The name of the method being decorated.
* @param descriptor - The Property Descriptor for the method.
*
* @throws {TypeError} - Throws a TypeError if the `propertyKey` is not a string.
*/
export declare function DebounceCall(delay?: number): MethodDecorator;