1
1
/**
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.
7
19
*/
8
20
9
21
const debounce = ( callback , delay , immediate = false ) => {
@@ -29,10 +41,18 @@ const debounce = (callback, delay, immediate = false) => {
29
41
30
42
31
43
/**
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.
36
56
*/
37
57
38
58
const throttle = ( callback , delay ) => {
0 commit comments