From b346b043a6b21cb7c9dca3549b1f5d85a1c61f70 Mon Sep 17 00:00:00 2001 From: Lucas Vallenet Date: Wed, 1 Jun 2022 14:25:40 +0200 Subject: [PATCH] Improve tickers comments --- assets/scripts/utils/tickers.js | 38 +++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/assets/scripts/utils/tickers.js b/assets/scripts/utils/tickers.js index 3ecd7f1b..f89efe6b 100644 --- a/assets/scripts/utils/tickers.js +++ b/assets/scripts/utils/tickers.js @@ -1,9 +1,21 @@ /** - * Debounce function: fire the callback before/after the action has finished for the defined amount of time - * @param {function} callback - callback function - * @param {number} delay - waiting time in milisecond - * @param {boolean} immediate - triggers before or after delay - * @return {function} callback + * Creates a debounced function. + * + * A debounced function delays invoking `callback` until after + * `delay` milliseconds have elapsed since the last time the + * debounced function was invoked. + * + * Useful for behaviour that should only happen _before_ or + * _after_ an event has stopped occurring. + * + * @template {function} T + * + * @param {T} callback - The function to debounce. + * @param {number} delay - The number of milliseconds to wait. + * @param {boolean} [immediate] - + * If `true`, `callback` is invoked before `delay`. + * If `false`, `callback` is invoked after `delay`. + * @return {function} The new debounced function. */ const debounce = (callback, delay, immediate = false) => { @@ -29,10 +41,18 @@ const debounce = (callback, delay, immediate = false) => { /** - * Throttle function: fire the callback while the action is being performed for the defined iteration time - * @param {function} callback - callback function - * @param {number} delay - waiting time in milisecond - * @return {function} callback + * Creates a throttled function. + * + * A throttled function invokes `callback` at most once per every + * `delay` milliseconds. + * + * Useful for rate-limiting an event that occurs in quick succession. + * + * @template {function} T + * + * @param {T} callback - The function to throttle. + * @param {number} delay - The number of milliseconds to wait. + * @return {function} The new throttled function. */ const throttle = (callback, delay) => {