Created
August 9, 2021 18:59
-
-
Save Ebazhanov/30ce06b55e8d9b4aea5169ab6ab4a3af to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://learn.javascript.ru/promise-chaining | |
// Запрашиваем user.json | |
fetch('/article/promise-chaining/user.json') | |
// Загружаем данные в формате json | |
.then(response => response.json()) | |
// Делаем запрос к GitHub | |
.then(user => fetch(`https://api.github.com/users/${user.name}`)) | |
// Загружаем ответ в формате json | |
.then(response => response.json()) | |
// Показываем аватар (githubUser.avatar_url) в течение 3 секунд (возможно, с анимацией) | |
.then(githubUser => { | |
let img = document.createElement('img'); | |
img.src = githubUser.avatar_url; | |
img.className = "promise-avatar-example"; | |
document.body.append(img); | |
setTimeout(() => img.remove(), 3000); // (*) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment