You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 1-js/06-advanced-functions/09-call-apply-decorators/03-debounce/task.md
+3-3
Original file line number
Diff line number
Diff line change
@@ -6,6 +6,8 @@ importance: 5
6
6
7
7
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.
8
8
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
+
9
11
For instance, we had a function `f` and replaced it with `f = debounce(f, 1000)`.
10
12
11
13
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);
25
27
// debounced function waits 1000ms after the last call and then runs: alert("c")
26
28
```
27
29
28
-
29
30
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.
30
31
31
32
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
43
44
44
45
So, `debounce` is a great way to process a sequence of events: be it a sequence of key presses, mouse movements or something else.
45
46
46
-
47
47
It waits the given time after the last call, and then runs its function, that can process the result.
48
48
49
49
The task is to implement `debounce` decorator.
50
50
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 :)
Copy file name to clipboardExpand all lines: 1-js/06-advanced-functions/09-call-apply-decorators/04-throttle/task.md
+2
Original file line number
Diff line number
Diff line change
@@ -12,6 +12,8 @@ The difference with debounce is that it's completely different decorator:
12
12
-`debounce` runs the function once after the "cooldown" period. Good for processing the final result.
13
13
-`throttle` runs it not more often than given `ms` time. Good for regular updates that shouldn't be very often.
14
14
15
+
In other words, `throttle` is like a secretary that accepts phone calls, but bothers the boss (calls the actual `f`) not more often than once per `ms` milliseconds.
16
+
15
17
Let's check the real-life application to better understand that requirement and to see where it comes from.
16
18
17
19
**For instance, we want to track mouse movements.**
Copy file name to clipboardExpand all lines: 9-regular-expressions/03-regexp-unicode/article.md
-6
Original file line number
Diff line number
Diff line change
@@ -33,12 +33,6 @@ Unlike strings, regular expressions have flag `pattern:u` that fixes such proble
33
33
34
34
## Unicode properties \p{...}
35
35
36
-
```warn header="Not supported in Firefox and Edge"
37
-
Despite being a part of the standard since 2018, unicode properties are not supported in Firefox ([bug](https://bugzilla.mozilla.org/show_bug.cgi?id=1361876)) and Edge ([bug](https://github.com/Microsoft/ChakraCore/issues/2969)).
38
-
39
-
There's [XRegExp](http://xregexp.com) library that provides "extended" regular expressions with cross-browser support for unicode properties.
40
-
```
41
-
42
36
Every character in Unicode has a lot of properties. They describe what "category" the character belongs to, contain miscellaneous information about it.
43
37
44
38
For instance, if a character has `Letter` property, it means that the character belongs to an alphabet (of any language). And `Number` property means that it's a digit: maybe Arabic or Chinese, and so on.
0 commit comments