Skip to content

Commit

Permalink
docs: add comment to handleInput
Browse files Browse the repository at this point in the history
  • Loading branch information
Kout95 committed Jun 11, 2024
1 parent a2af1ec commit 01d26ac
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions frontend/src/mixins/debounce.ts
Original file line number Diff line number Diff line change
@@ -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<F extends () => 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<LitElement>} superClass - The superclass to extend from.
* @returns {Constructor<DebounceMixinInterface> & T} - The extended class with debouncing functionality.
*/
export const DebounceMixin = <T extends Constructor<LitElement>>(
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<F extends () => void>(func: F, wait = 300): void {
// eslint-disable-next-line @typescript-eslint/no-this-alias
const self = this;
Expand Down

0 comments on commit 01d26ac

Please sign in to comment.