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/11-async/02-promise-basics/article.md
+12-12
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,7 @@ Everyone is happy, because the people don't crowd you any more, and fans, becaus
8
8
9
9
This is a real-life analogy for things we often have in programming:
10
10
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".
12
12
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".
13
13
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.
14
14
@@ -27,7 +27,7 @@ The function passed to `new Promise` is called the *executor*. When the promise
27
27
The resulting `promise` object has internal properties:
28
28
29
29
-`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`.
31
31
32
32
When the executor finishes the job, it should call one of the functions that it gets as arguments:
33
33
@@ -56,7 +56,7 @@ let promise = new Promise(function(resolve, reject) {
56
56
We can see two things by running the code above:
57
57
58
58
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.
60
60
61
61
After one second of "processing" the executor calls `resolve("done")` to produce the result:
62
62
@@ -77,7 +77,7 @@ let promise = new Promise(function(resolve, reject) {
77
77
78
78
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.
79
79
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.
81
81
82
82
````smart header="There can be only a single result or an error"
83
83
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) {
112
112
});
113
113
```
114
114
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.
116
116
117
-
That's fine. We immediately have a resolved Promise, nothing wrong with that.
117
+
That's fine. We immediately have a resolved promise.
118
118
````
119
119
120
120
```smart header="The `state` and `result` are internal"
@@ -140,12 +140,12 @@ promise.then(
140
140
141
141
The first argument of `.then` is a function that:
142
142
143
-
1. runs when the Promise is resolved, and
143
+
1. runs when the promise is resolved, and
144
144
2. receives the result.
145
145
146
146
The second argument of `.then` is a function that:
147
147
148
-
1. runs when the Promise is rejected, and
148
+
1. runs when the promise is rejected, and
149
149
2. receives the error.
150
150
151
151
For instance, here's a reaction to a successfully resolved promise:
@@ -233,10 +233,10 @@ new Promise((resolve, reject) => {
233
233
.then(result => show result, err => show error)
234
234
```
235
235
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:
237
237
238
238
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.
240
240
241
241
For instance, here the result is passed through `finally` to `then`:
242
242
```js run
@@ -257,11 +257,11 @@ It's not exactly an alias though. There are several important differences:
257
257
.catch(err => alert(err)); // <-- .catch handles the error object
258
258
```
259
259
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.
261
261
262
262
We'll talk more about promise chaining and result-passing between handlers in the next chapter.
263
263
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`.
Copy file name to clipboardExpand all lines: 2-ui/3-event-details/3-mousemove-mouseover-mouseout-mouseenter-mouseleave/1-behavior-nested-tooltip/solution.view/index.html
+4-3
Original file line number
Diff line number
Diff line change
@@ -78,12 +78,13 @@
78
78
}
79
79
80
80
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)
82
83
// but in this case we'll have an immediate mouseover,
83
84
// so the tooltip will be destroyed and shown again
Copy file name to clipboardExpand all lines: 2-ui/3-event-details/3-mousemove-mouseover-mouseout-mouseenter-mouseleave/2-hoverintent/source.view/index.html
Copy file name to clipboardExpand all lines: 2-ui/3-event-details/3-mousemove-mouseover-mouseout-mouseenter-mouseleave/mouseoverout-fast.view/index.html
Copy file name to clipboardExpand all lines: 4-binary/04-file/article.md
+4-4
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# File and FileReader
2
2
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.
4
4
5
5
There are two ways to obtain it.
6
6
@@ -38,9 +38,9 @@ The input may select multiple files, so `input.files` is an array-like object wi
38
38
39
39
## FileReader
40
40
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.
42
42
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.
44
44
45
45
The constructor:
46
46
@@ -109,7 +109,7 @@ For Web Workers, there also exists a synchronous variant of `FileReader`, called
109
109
110
110
Its reading methods `read*` do not generate events, but rather return a result, as regular functions do.
111
111
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.
0 commit comments