Created
September 9, 2017 14:44
-
-
Save anotherxx/52d39426a94a74346f3c5eed97cece4d 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
httpGetUser('http://localhost:3000/users') | |
.then(response => | |
{ | |
console.log('First resolve callback'); | |
console.log('~~~~~~~~~~'); | |
var user = JSON.parse(response); | |
user = user.find((user) => user.name == 'Nerhbest'); | |
return user.name; | |
}).then(user => | |
{ | |
console.log('second callback'); | |
console.log(user); | |
return httpGetUser(`https://api.github.com/users/${user}`); //Ecли resovle callback возвращает promise то все оставшиеся callbacks ждут выполнения запроса , и в след коллбек передастся результат вызова api | |
}).then(githubUser => | |
{ | |
console.log(githubUser); | |
let gituser = JSON.parse(githubUser); | |
console.log(gituser); | |
let img = new Image(); | |
img.src = gituser.avatar_url; | |
document.body.appendChild(img); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment