Skip to content

Commit b346b04

Browse files
committed
Improve tickers comments
1 parent 99291b1 commit b346b04

File tree

1 file changed

+29
-9
lines changed

1 file changed

+29
-9
lines changed

assets/scripts/utils/tickers.js

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
11
/**
2-
* Debounce function: fire the callback before/after the action has finished for the defined amount of time
3-
* @param {function} callback - callback function
4-
* @param {number} delay - waiting time in milisecond
5-
* @param {boolean} immediate - triggers before or after delay
6-
* @return {function} callback
2+
* Creates a debounced function.
3+
*
4+
* A debounced function delays invoking `callback` until after
5+
* `delay` milliseconds have elapsed since the last time the
6+
* debounced function was invoked.
7+
*
8+
* Useful for behaviour that should only happen _before_ or
9+
* _after_ an event has stopped occurring.
10+
*
11+
* @template {function} T
12+
*
13+
* @param {T} callback - The function to debounce.
14+
* @param {number} delay - The number of milliseconds to wait.
15+
* @param {boolean} [immediate] -
16+
* If `true`, `callback` is invoked before `delay`.
17+
* If `false`, `callback` is invoked after `delay`.
18+
* @return {function<T>} The new debounced function.
719
*/
820

921
const debounce = (callback, delay, immediate = false) => {
@@ -29,10 +41,18 @@ const debounce = (callback, delay, immediate = false) => {
2941

3042

3143
/**
32-
* Throttle function: fire the callback while the action is being performed for the defined iteration time
33-
* @param {function} callback - callback function
34-
* @param {number} delay - waiting time in milisecond
35-
* @return {function} callback
44+
* Creates a throttled function.
45+
*
46+
* A throttled function invokes `callback` at most once per every
47+
* `delay` milliseconds.
48+
*
49+
* Useful for rate-limiting an event that occurs in quick succession.
50+
*
51+
* @template {function} T
52+
*
53+
* @param {T} callback - The function to throttle.
54+
* @param {number} delay - The number of milliseconds to wait.
55+
* @return {function<T>} The new throttled function.
3656
*/
3757

3858
const throttle = (callback, delay) => {

0 commit comments

Comments
 (0)