Skip to content

Commit 0873473

Browse files
committed
minor
1 parent 16e7d07 commit 0873473

File tree

7 files changed

+27
-24
lines changed

7 files changed

+27
-24
lines changed

1-js/11-async/02-promise-basics/article.md

+12-12
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Everyone is happy, because the people don't crowd you any more, and fans, becaus
88

99
This is a real-life analogy for things we often have in programming:
1010

11-
1. A "producing code" that does something and takes time. For instance, the code loads a remote script. That's a "singer".
11+
1. A "producing code" that does something and takes time. For instance, the code loads data over a network. That's a "singer".
1212
2. A "consuming code" that wants the result of the "producing code" once it's ready. Many functions may need that result. These are the "fans".
1313
3. A *promise* is a special JavaScript object that links the "producing code" and the "consuming code" together. In terms of our analogy: this is the "subscription list". The "producing code" takes whatever time it needs to produce the promised result, and the "promise" makes that result available to all of the subscribed code when it's ready.
1414

@@ -27,7 +27,7 @@ The function passed to `new Promise` is called the *executor*. When the promise
2727
The resulting `promise` object has internal properties:
2828

2929
- `state` — initially "pending", then changes to either "fulfilled" or "rejected",
30-
- `result` — an arbitrary value of your choosing, initially `undefined`.
30+
- `result` — an arbitrary value, initially `undefined`.
3131

3232
When the executor finishes the job, it should call one of the functions that it gets as arguments:
3333

@@ -56,7 +56,7 @@ let promise = new Promise(function(resolve, reject) {
5656
We can see two things by running the code above:
5757

5858
1. The executor is called automatically and immediately (by the `new Promise`).
59-
2. The executor receives two arguments: `resolve` and `reject` — these functions are pre-defined by the JavaScript engine. So we don't need to create them. Instead, we should write the executor to call them when ready.
59+
2. The executor receives two arguments: `resolve` and `reject` — these functions are pre-defined by the JavaScript engine. So we don't need to create them. We only should call one of them when ready.
6060

6161
After one second of "processing" the executor calls `resolve("done")` to produce the result:
6262

@@ -77,7 +77,7 @@ let promise = new Promise(function(resolve, reject) {
7777

7878
To summarize, the executor should do a job (something that takes time usually) and then call `resolve` or `reject` to change the state of the corresponding Promise object.
7979

80-
The Promise that is either resolved or rejected is called "settled", as opposed to a "pending" Promise.
80+
The Promise that is either resolved or rejected is called "settled", as opposed to a initially "pending" Promise.
8181

8282
````smart header="There can be only a single result or an error"
8383
The executor should call only one `resolve` or one `reject`. The promise's state change is final.
@@ -112,9 +112,9 @@ let promise = new Promise(function(resolve, reject) {
112112
});
113113
```
114114

115-
For instance, this might happen when we start to do a job but then see that everything has already been completed.
115+
For instance, this might happen when we start to do a job but then see that everything has already been completed and cached.
116116

117-
That's fine. We immediately have a resolved Promise, nothing wrong with that.
117+
That's fine. We immediately have a resolved promise.
118118
````
119119
120120
```smart header="The `state` and `result` are internal"
@@ -140,12 +140,12 @@ promise.then(
140140
141141
The first argument of `.then` is a function that:
142142
143-
1. runs when the Promise is resolved, and
143+
1. runs when the promise is resolved, and
144144
2. receives the result.
145145
146146
The second argument of `.then` is a function that:
147147
148-
1. runs when the Promise is rejected, and
148+
1. runs when the promise is rejected, and
149149
2. receives the error.
150150
151151
For instance, here's a reaction to a successfully resolved promise:
@@ -233,10 +233,10 @@ new Promise((resolve, reject) => {
233233
.then(result => show result, err => show error)
234234
```
235235
236-
It's not exactly an alias though. There are several important differences:
236+
It's not exactly an alias of `then(f,f)` though. There are several important differences:
237237
238238
1. A `finally` handler has no arguments. In `finally` we don't know whether the promise is successful or not. That's all right, as our task is usually to perform "general" finalizing procedures.
239-
2. Finally passes through results and errors to the next handler.
239+
2. A `finally` handler passes through results and errors to the next handler.
240240
241241
For instance, here the result is passed through `finally` to `then`:
242242
```js run
@@ -257,11 +257,11 @@ It's not exactly an alias though. There are several important differences:
257257
.catch(err => alert(err)); // <-- .catch handles the error object
258258
```
259259
260-
That's very convenient, because finally is not meant to process promise results. So it passes them through.
260+
That's very convenient, because `finally` is not meant to process a promise result. So it passes it through.
261261
262262
We'll talk more about promise chaining and result-passing between handlers in the next chapter.
263263
264-
3. Last, but not least, `.finally(f)` is a more convenient syntax than `.then(f, f)`: no need to duplicate the function.
264+
3. Last, but not least, `.finally(f)` is a more convenient syntax than `.then(f, f)`: no need to duplicate the function `f`.
265265
266266
````smart header="On settled promises handlers runs immediately"
267267
If a promise is pending, `.then/catch/finally` handlers wait for the result. Otherwise, if a promise has already settled, they execute immediately:

2-ui/3-event-details/3-mousemove-mouseover-mouseout-mouseenter-mouseleave/1-behavior-nested-tooltip/solution.view/index.html

+4-3
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,13 @@
7878
}
7979

8080
document.onmouseout = function() {
81-
// it is possible that mouseout triggered, but we're still inside the element (cause of bubbling)
81+
// it is possible that mouseout triggered, but we're still inside the element
82+
// (its target was inside, and it bubbled)
8283
// but in this case we'll have an immediate mouseover,
8384
// so the tooltip will be destroyed and shown again
8485
//
85-
// that's an overhead, but here it's not visible
86-
// can be fixed with additional checks
86+
// luckily, the "blinking" won't be visible,
87+
// as both events happen almost at the same time
8788
if (tooltip) {
8889
tooltip.remove();
8990
tooltip = false;

2-ui/3-event-details/3-mousemove-mouseover-mouseout-mouseenter-mouseleave/2-hoverintent/source.view/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!doctype html>
2-
<html lang="en">
2+
<html>
33

44
<head>
55
<meta charset="UTF-8">

2-ui/3-event-details/3-mousemove-mouseover-mouseout-mouseenter-mouseleave/2-hoverintent/task.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Technically, we can measure the mouse speed over the element, and if it's slow t
1313
Make a universal object `new HoverIntent(options)` for it. With `options`:
1414

1515
- `elem` -- element to track.
16-
- `over` -- a function to call if the mouse is slowly moving the element.
16+
- `over` -- a function to call if the mouse is slowly moving over the element.
1717
- `out` -- a function to call when the mouse leaves the element (if `over` was called).
1818

1919
An example of using such object for the tooltip:

2-ui/3-event-details/3-mousemove-mouseover-mouseout-mouseenter-mouseleave/article.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,17 @@ The `mouseover` event occurs when a mouse pointer comes over an element, and `mo
1010

1111
These events are special, because they have a `relatedTarget`.
1212

13+
This property complements `target`. When a mouse leaves one element for another, one of them becomes `target`, and the other one `relatedTarget`.
14+
1315
For `mouseover`:
1416

1517
- `event.target` -- is the element where the mouse came over.
16-
- `event.relatedTarget` -- is the element from which the mouse came.
18+
- `event.relatedTarget` -- is the element from which the mouse came (`relatedTarget` -> `target`).
1719

1820
For `mouseout` the reverse:
1921

2022
- `event.target` -- is the element that mouse left.
21-
- `event.relatedTarget` -- is the new under-the-pointer element (that mouse left for).
23+
- `event.relatedTarget` -- is the new under-the-pointer element, that mouse left for (`target` -> `relatedTarget`).
2224

2325
```online
2426
In the example below each face feature is an element. When you move the mouse, you can see mouse events in the text area.

2-ui/3-event-details/3-mousemove-mouseover-mouseout-mouseenter-mouseleave/mouseoverout-fast.view/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!doctype html>
2-
<html lang="en">
2+
<html>
33

44
<head>
55
<meta charset="UTF-8">

4-binary/04-file/article.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# File and FileReader
22

3-
A [File](https://www.w3.org/TR/FileAPI/#dfn-file) object inherits from `Blob`, but is extended with filesystem-related capabilities.
3+
A [File](https://www.w3.org/TR/FileAPI/#dfn-file) object inherits from `Blob` and is extended with filesystem-related capabilities.
44

55
There are two ways to obtain it.
66

@@ -38,9 +38,9 @@ The input may select multiple files, so `input.files` is an array-like object wi
3838

3939
## FileReader
4040

41-
[FileReader](https://www.w3.org/TR/FileAPI/#dfn-filereader) is an object with the sole purpose of reading from `Blob` (and hence `File` too) objects.
41+
[FileReader](https://www.w3.org/TR/FileAPI/#dfn-filereader) is an object with the sole purpose of reading data from `Blob` (and hence `File` too) objects.
4242

43-
It's event based, as reading from disk may take time.
43+
It delivers the data using events, as reading from disk may take time.
4444

4545
The constructor:
4646

@@ -109,7 +109,7 @@ For Web Workers, there also exists a synchronous variant of `FileReader`, called
109109
110110
Its reading methods `read*` do not generate events, but rather return a result, as regular functions do.
111111
112-
That's only inside a Web Worker though, because delays and hang-ups in Web Workers are less important, they do not affect the page.
112+
That's only inside a Web Worker though, because delays in synchronous calls, that are possible while reading from files, in Web Workers are less important. They do not affect the page.
113113
```
114114

115115
## Summary

0 commit comments

Comments
 (0)