-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathshowAvatar.js
More file actions
31 lines (27 loc) · 910 Bytes
/
showAvatar.js
File metadata and controls
31 lines (27 loc) · 910 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
function loadJson(url) {
return fetch(url)
.then(response => response.json());
}
function loadGithubUser(login) {
return fetch(`https://api.github.com/users/${login}`)
.then(response => response.json());
}
function showAvatar(githubUser) {
return new Promise(function (resolve, reject) {
console.log(githubUser)
let img = document.createElement('img');
img.src = githubUser.avatar_url;
img.className = "promise-avatar-example";
document.body.append(img);
setTimeout(() => {
img.remove();
resolve(githubUser);
}, 3000);
});
}
// Используем их:
// loadJson('/article/promise-chaining/user.json').then(user =>
// loadGithubUser('mikebars1995')
// .then(showAvatar)
// .then(githubUser => console.log(`Показ аватара ${githubUser.login} завершён`));
// ...