Skip to content

Commit 5415d6c

Browse files
committed
merge
2 parents cb54730 + 6a4c419 commit 5415d6c

File tree

4 files changed

+24
-24
lines changed

4 files changed

+24
-24
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ promise.then(alert); // done! (выведется сразу)
276276

277277
Теперь, рассмотрим несколько практических примеров того, как промисы могут облегчить нам написание асинхронного кода.
278278

279-
## Пример: loadScript
279+
## Пример: loadScript [#loadscript]
280280

281281
У нас есть функция `loadScript` для загрузки скрипта из предыдущей главы.
282282

1-js/11-async/03-promise-chaining/article.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ Returning promises allows us to build chains of asynchronous actions.
146146

147147
## Example: loadScript
148148

149-
Let's use this feature with `loadScript` to load scripts one by one, in sequence:
149+
Let's use this feature with the promisified `loadScript`, defined in the [previous chapter](/promise-basics#loadscript), to load scripts one by one, in sequence:
150150

151151
```js run
152152
loadScript("/article/promise-chaining/one.js")
@@ -305,7 +305,7 @@ fetch('/article/promise-chaining/user.json')
305305
});
306306
```
307307

308-
The code works, see comments about the details, but it should be quite self-descriptive. Although, there's a potential problem in it, a typical error of those who begin to use promises.
308+
The code works, see comments about the details. Although, there's a potential problem in it, a typical error of those who begin to use promises.
309309

310310
Look at the line `(*)`: how can we do something *after* the avatar has finished showing and gets removed? For instance, we'd like to show a form for editing that user or something else. As of now, there's no way.
311311

1-js/12-generators-iterators/2-async-iterators-generators/article.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33

44
Asynchronous iterators allow to iterate over data that comes asynchronously, on-demand.
55

6-
For instance, when we download something chunk-by-chunk, or just expect events to come asynchronously and would like to iterate over them -- async iterators and generators may come in handy. Let's see a simple example first, to grasp the syntax, and then review a real-life use case.
6+
For instance, when we download something chunk-by-chunk, and expect data fragments to come asynchronously and would like to iterate over them -- async iterators and generators may come in handy. Let's see a simple example first, to grasp the syntax, and then review a real-life use case.
77

88
## Async iterators
99

10-
Asynchronous iterators are totally similar to regular iterators, with a few syntactic differences.
10+
Asynchronous iterators are similar to regular iterators, with a few syntactic differences.
1111

12-
"Regular" iterable object from the chapter <info:iterable> look like this:
12+
"Regular" iterable object, as described in the chapter <info:iterable>, look like this:
1313

1414
```js run
1515
let range = {
@@ -101,7 +101,7 @@ let range = {
101101
})()
102102
```
103103

104-
As we can see, the components are similar to regular iterators:
104+
As we can see, the structure is similar to regular iterators:
105105

106106
1. To make an object asynchronously iterable, it must have a method `Symbol.asyncIterator` `(1)`.
107107
2. It must return the object with `next()` method returning a promise `(2)`.
@@ -117,22 +117,22 @@ Here's a small cheatsheet:
117117
| to loop, use | `for..of` | `for await..of` |
118118

119119

120-
````warn header="The spread operator doesn't work asynchronously"
120+
````warn header="The spread operator ... doesn't work asynchronously"
121121
Features that require regular, synchronous iterators, don't work with asynchronous ones.
122122
123123
For instance, a spread operator won't work:
124124
```js
125125
alert( [...range] ); // Error, no Symbol.iterator
126126
```
127127
128-
That's natural, as it expects to find `Symbol.iterator`, same as `for..of` without `await`.
128+
That's natural, as it expects to find `Symbol.iterator`, same as `for..of` without `await`. Not `Symbol.asyncIterator`.
129129
````
130130

131131
## Async generators
132132

133-
JavaScript also provides generators, that are also iterable.
133+
As we already know, JavaScript also supprots generators, and they are iterable.
134134

135-
Let's recall a sequence generator from the chapter [](info:generators). It generates a sequence of values from `start` to `end` (could be anything else):
135+
Let's recall a sequence generator from the chapter [](info:generators). It generates a sequence of values from `start` to `end`:
136136

137137
```js run
138138
function* generateSequence(start, end) {
@@ -147,7 +147,7 @@ for(let value of generateSequence(1, 5)) {
147147
```
148148

149149

150-
Normally, we can't use `await` in generators. All values must come synchronously: there's no place for delay in `for..of`.
150+
Normally, we can't use `await` in generators. All values must come synchronously: there's no place for delay in `for..of`, it's a synchronous construct.
151151

152152
But what if we need to use `await` in the generator body? To perform network requests, for instance.
153153

@@ -184,15 +184,15 @@ It's indeed very simple. We add the `async` keyword, and the generator now can u
184184

185185
Technically, another the difference of an async generator is that its `generator.next()` method is now asynchronous also, it returns promises.
186186

187-
Instead of `result = generator.next()` for a regular, non-async generator, values can be obtained like this:
187+
In a regular generator we'd use `result = generator.next()` to get values. In an async generator, we should add `await`, like this:
188188

189189
```js
190190
result = await generator.next(); // result = {value: ..., done: true/false}
191191
```
192192

193193
## Iterables via async generators
194194

195-
When we'd like to make an object iterable, we should add `Symbol.iterator` to it.
195+
As we already know, to make an object iterable, we should add `Symbol.iterator` to it.
196196

197197
```js
198198
let range = {
@@ -270,7 +270,7 @@ The pattern is very common, it's not about users, but just about anything. For i
270270
- It responds with a JSON of 30 commits, and also provides a link to the next page in the `Link` header.
271271
- Then we can use that link for the next request, to get more commits, and so on.
272272

273-
What we'd like to have is an iterable source of commits, so that we could use it like this:
273+
What we'd like to have is a simpler API: an iterable object with commits, so that we could go over them like this:
274274

275275
```js
276276
let repo = 'javascript-tutorial/en.javascript.info'; // GitHub repository to get commits from
@@ -332,7 +332,7 @@ An example of use (shows commit authors in console):
332332
})();
333333
```
334334

335-
That's just what we wanted. The internal pagination mechanics is invisible from the outside. For us it's just an async generator that returns commits.
335+
That's just what we wanted. The internal mechanics of paginated requests is invisible from the outside. For us it's just an async generator that returns commits.
336336

337337
## Summary
338338

@@ -356,6 +356,6 @@ Syntax differences between async and regular generators:
356356

357357
In web-development we often meet streams of data, when it flows chunk-by-chunk. For instance, downloading or uploading a big file.
358358

359-
We could use async generators to process such data, but there's also another API called Streams, that may be more convenient, as it provides special interfaces to transform the data and to pass it from one stream to another (e.g. download from one place and immediately send elsewhere). But they are also more complex.
359+
We can use async generators to process such data, but it's worth to mention that there's also another API called Streams, that provides special interfaces to transform the data and to pass it from one stream to another (e.g. download from one place and immediately send elsewhere).
360360

361361
Streams API not a part of JavaScript language standard. Streams and async generators complement each other, both are great ways to handle async data flows.

6-data-storage/02-localstorage/article.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ localStorage.setItem('test', 1);
4242
alert( localStorage.getItem('test') ); // 1
4343
```
4444

45-
We only have to be on the same domain/port/protocol, the url path can be different.
45+
We only have to be on the same origin (domain/port/protocol), the url path can be different.
4646

47-
The `localStorage` is shared, so if we set the data in one window, the change becomes visible in the other one.
47+
The `localStorage` is shared between all windows with the same origin, so if we set the data in one window, the change becomes visible in another one.
4848

4949
## Object-like access
5050

@@ -73,7 +73,7 @@ That's allowed for historical reasons, and mostly works, but generally not recom
7373

7474
## Looping over keys
7575

76-
As we've seen, the methods provide get/set/remove functionality. But how to get all saved values or keys?
76+
As we've seen, the methods provide "get/set/remove by key" functionality. But how to get all saved values or keys?
7777
7878
Unfortunately, storage objects are not iterable.
7979
@@ -198,7 +198,7 @@ Imagine, you have two windows with the same site in each. So `localStorage` is s
198198
You might want to open this page in two browser windows to test the code below.
199199
```
200200

201-
Now if both windows are listening for `window.onstorage`, then each one will react on updates that happened in the other one.
201+
If both windows are listening for `window.onstorage`, then each one will react on updates that happened in the other one.
202202

203203
```js run
204204
// triggers on updates made to the same storage from other documents
@@ -229,18 +229,18 @@ Web storage objects `localStorage` and `sessionStorage` allow to store key/value
229229
| `localStorage` | `sessionStorage` |
230230
|----------------|------------------|
231231
| Shared between all tabs and windows with the same origin | Visible within a browser tab, including iframes from the same origin |
232-
| Survives browser restart | Dies on tab close |
232+
| Survives browser restart | Survives page refresh (but not tab close) |
233233

234234
API:
235235

236236
- `setItem(key, value)` -- store key/value pair.
237237
- `getItem(key)` -- get the value by key.
238238
- `removeItem(key)` -- remove the key with its value.
239239
- `clear()` -- delete everything.
240-
- `key(index)` -- get the key on a given position.
240+
- `key(index)` -- get the key number `index`.
241241
- `length` -- the number of stored items.
242242
- Use `Object.keys` to get all keys.
243-
- Can use the keys as object properties, in that case `storage` event isn't triggered.
243+
- We access keys as object properties, in that case `storage` event isn't triggered.
244244
245245
Storage event:
246246

0 commit comments

Comments
 (0)