Skip to content

Commit 378953a

Browse files
Merge #155
Fetch
2 parents 986cf62 + 2f47a94 commit 378953a

File tree

5 files changed

+110
-110
lines changed

5 files changed

+110
-110
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11

22
async function getUsers(names) {
3-
/* your code */
3+
/* codul tău */
44
}

5-network/01-fetch/01-fetch-users/_js.view/test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
describe("getUsers", function() {
22

3-
it("gets users from GitHub", async function() {
4-
let users = await getUsers(['iliakan', 'remy', 'no.such.users']);
3+
it("obține utilizatorii din GitHub", async function() {
4+
let users = await getUsers(['iliakan', 'remy', 'nici.un.astfel.de.utilizator']);
55
assert.equal(users[0].login, 'iliakan');
66
assert.equal(users[1].login, 'remy');
77
assert.equal(users[2], null);

5-network/01-fetch/01-fetch-users/solution.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11

2-
To fetch a user we need: `fetch('https://api.github.com/users/USERNAME')`.
2+
Pentru a prelua un utilizator avem nevoie de: `fetch('https://api.github.com/users/USERNAME')`.
33

4-
If the response has status `200`, call `.json()` to read the JS object.
4+
Dacă răspunsul are status `200`, apelați `.json()` pentru a citi obiectul JS.
55

6-
Otherwise, if a `fetch` fails, or the response has non-200 status, we just return `null` in the resulting array.
6+
În caz contrar, dacă un `fetch` eșuează, sau dacă răspunsul nu are status 200, returnăm doar `null` în array-ul rezultat.
77

8-
So here's the code:
8+
Iată deci codul:
99

1010
```js demo
1111
async function getUsers(names) {
@@ -33,8 +33,8 @@ async function getUsers(names) {
3333
}
3434
```
3535

36-
Please note: `.then` call is attached directly to `fetch`, so that when we have the response, it doesn't wait for other fetches, but starts to read `.json()` immediately.
36+
Vă rugăm să notați că: apelul `.then` este atașat direct la `fetch`, astfel încât atunci când avem răspunsul, acesta nu așteaptă alte preluări, ci începe să citească imediat `.json()`.
3737

38-
If we used `await Promise.all(names.map(name => fetch(...)))`, and call `.json()` on the results, then it would wait for all fetches to respond. By adding `.json()` directly to each `fetch`, we ensure that individual fetches start reading data as JSON without waiting for each other.
38+
Dacă am folosi `await Promise.all(names.map(name => fetch(...)))`, și am apela `.json()` către rezultate, atunci am aștepta ca toate preluările să răspundă. Adăugând `.json()` direct la fiecare `fetch`, ne asigurăm că fiecare fetch individual începe să citească datele ca JSON fără să se aștepte unul pe celălalt.
3939

40-
That's an example of how low-level Promise API can still be useful even if we mainly use `async/await`.
40+
Acesta este un exemplu despre cum low-level Promise API poate fi totuși util chiar dacă folosim în principal `async/await`.
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
# Fetch users from GitHub
1+
# Preia utilizatorii din GitHub
22

3-
Create an async function `getUsers(names)`, that gets an array of GitHub logins, fetches the users from GitHub and returns an array of GitHub users.
3+
Creați o funcție async `getUsers(names)`, care obține un array de autentificări GitHub, preia utilizatorii de pe GitHub și returnează un array de utilizatori GitHub.
44

5-
The GitHub url with user information for the given `USERNAME` is: `https://api.github.com/users/USERNAME`.
5+
URL-ul GitHub cu informații despre utilizator pentru `USERNAME` dat este: `https://api.github.com/users/USERNAME`.
66

7-
There's a test example in the sandbox.
7+
Există un exemplu de testare în sandbox.
88

9-
Important details:
9+
Detalii importante:
1010

11-
1. There should be one `fetch` request per user.
12-
2. Requests shouldn't wait for each other. So that the data arrives as soon as possible.
13-
3. If any request fails, or if there's no such user, the function should return `null` in the resulting array.
11+
1. Trebuie să existe o singură cerere `fetch` pentru fiecare utilizator.
12+
2. Solicitările nu ar trebui să se aștepte una pe alta. Astfel încât datele să ajungă cât mai repede posibil.
13+
3. În cazul în care o cerere eșuează, sau dacă nu există un astfel de utilizator, funcția ar trebui să returneze `null` în array-ul rezultat.

0 commit comments

Comments
 (0)