Skip to content

Commit

Permalink
move debounce function to functions.any
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmadkadri committed Sep 17, 2024
1 parent fa0439a commit fe99747
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
18 changes: 18 additions & 0 deletions react/features/base/config/functions.any.ts
Original file line number Diff line number Diff line change
Expand Up @@ -381,3 +381,21 @@ export function getLegalUrls(state: IReduxState) {
terms: configLegalUrls?.terms || DEFAULT_TERMS_URL
};
}

/**
* Utility function to debounce the execution of a callback function.
*
* @param {Function} callback - The callback to debounce.
* @param {number} delay - The debounce delay in milliseconds.
* @returns {Function} - A debounced function that delays the execution of the callback.
*/
export function debounce(callback: (...args: any[]) => void, delay: number) {
let timerId: any;

return (...args: any[]) => {
if (timerId) {
clearTimeout(timerId);
}
timerId = setTimeout(() => callback(...args), delay);
};
}
19 changes: 1 addition & 18 deletions react/features/toolbox/components/web/DialogPortal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import ReactDOM from 'react-dom';
import { useSelector } from 'react-redux';

import { IReduxState } from '../../../app/types';
import { debounce } from '../../../base/config/functions.any';
import { ZINDEX_DIALOG_PORTAL } from '../../constants';

interface IProps {
Expand Down Expand Up @@ -44,24 +45,6 @@ interface IProps {
targetSelector?: string;
}

/**
* Utility function to debounce the execution of a callback function.
*
* @param {Function} callback - The callback to debounce.
* @param {number} delay - The debounce delay in milliseconds.
* @returns {Function} - A debounced function that delays the execution of the callback.
*/
const debounce = (callback: (...args: any[]) => void, delay: number) => {
let timerId: any;

return (...args: any[]) => {
if (timerId) {
clearTimeout(timerId);
}
timerId = setTimeout(() => callback(...args), delay);
};
};

/**
* Component meant to render a drawer at the bottom of the screen,
* by creating a portal containing the component's children.
Expand Down

0 comments on commit fe99747

Please sign in to comment.