From 01d26ac5a6266558ea6df58297ee4035483ef61f Mon Sep 17 00:00:00 2001 From: Kout95 Date: Tue, 11 Jun 2024 09:15:54 +0200 Subject: [PATCH] docs: add comment to handleInput --- frontend/src/mixins/debounce.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/frontend/src/mixins/debounce.ts b/frontend/src/mixins/debounce.ts index abbce834..b1934c8b 100644 --- a/frontend/src/mixins/debounce.ts +++ b/frontend/src/mixins/debounce.ts @@ -1,17 +1,35 @@ import {LitElement} from 'lit'; import {Constructor} from './utils'; +/** + * Interface for the DebounceMixin. + * It defines the structure that DebounceMixin should adhere to. + */ export interface DebounceMixinInterface { timeout?: number; debounce void>(func: F, wait?: number): void; } +/** + * A mixin class for debouncing function calls. + * It extends the LitElement class and adds debouncing functionality. + * It is used to prevent a function from being called multiple times in a short period of time. + * It is usefull to avoid multiple calls to a function when the user is typing in an input field. + * @param {Constructor} superClass - The superclass to extend from. + * @returns {Constructor & T} - The extended class with debouncing functionality. + */ export const DebounceMixin = >( superClass: T ) => class extends superClass { timeout?: number = undefined; + /** + * Debounces a function call. + * It delays the execution of the function until after wait milliseconds have elapsed since the last time this function was invoked. + * @param {Function} func - The function to debounce. + * @param {number} wait - The number of milliseconds to delay. + */ debounce void>(func: F, wait = 300): void { // eslint-disable-next-line @typescript-eslint/no-this-alias const self = this;