Skip to content

Commit 858b733

Browse files
authored
Update task.md
1 parent 53f055c commit 858b733

File tree

1 file changed

+3
-3
lines changed
  • 1-js/06-advanced-functions/09-call-apply-decorators/03-debounce

1 file changed

+3
-3
lines changed

1-js/06-advanced-functions/09-call-apply-decorators/03-debounce/task.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ importance: 5
66

77
The result of `debounce(f, ms)` decorator is a wrapper that suspends calls to `f` until there's `ms` milliseconds of inactivity (no calls, "cooldown period"), then invokes `f` once with the latest arguments.
88

9+
In other words, `debounce` is like a secretary that accepts "phone calls", and waits until there's `ms` milliseconds of being quiet. And only then it transfers the latest call information to "the boss" (calls the actual `f`).
10+
911
For instance, we had a function `f` and replaced it with `f = debounce(f, 1000)`.
1012

1113
Then if the wrapped function is called at 0ms, 200ms and 500ms, and then there are no calls, then the actual `f` will be only called once, at 1500ms. That is: after the cooldown period of 1000ms from the last call.
@@ -25,7 +27,6 @@ setTimeout( () => f("c"), 500);
2527
// debounced function waits 1000ms after the last call and then runs: alert("c")
2628
```
2729

28-
2930
Now a practical example. Let's say, the user types something, and we'd like to send a request to the server when the input is finished.
3031

3132
There's no point in sending the request for every character typed. Instead we'd like to wait, and then process the whole result.
@@ -43,9 +44,8 @@ See? The second input calls the debounced function, so its content is processed
4344

4445
So, `debounce` is a great way to process a sequence of events: be it a sequence of key presses, mouse movements or something else.
4546

46-
4747
It waits the given time after the last call, and then runs its function, that can process the result.
4848

4949
The task is to implement `debounce` decorator.
5050

51-
Hint: that's just a few lines if you think about it :)
51+
Hint: that's just a few lines if you think about it :)

0 commit comments

Comments
 (0)