Skip to content

Commit f7fa00d

Browse files
author
Balashov Nikita
committed
async
1 parent f0e7324 commit f7fa00d

File tree

3 files changed

+7
-13
lines changed

3 files changed

+7
-13
lines changed

phone-book/build/bundle.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

phone-book/src/components/users.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {Url} from '../url/url';
22

33
const serverSide = new Url();
4-
const users = JSON.parse(serverSide.obtainUsers());
4+
const users = serverSide.getUsersFromServer();
55

66
export {users};

phone-book/src/url/url.js

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,10 @@ class Url{
44
}
55

66
getUsersFromServer() {
7-
const xhr = new XMLHttpRequest();
8-
9-
xhr.onreadystatechange = () => {
10-
if(xhr.readyState === 4) {
11-
this.users = xhr.response
12-
}
13-
}
14-
15-
xhr.open('GET', this.url, false);
16-
xhr.send();
7+
return (async () => {
8+
const data = await fetch(this.url);
9+
return this.users = await data.json();
10+
})();
1711
}
1812

1913
obtainUsers() {

0 commit comments

Comments
 (0)