Last active
May 30, 2017 02:00
-
-
Save bdunn313/0abbf8784dad308d4a19ffc5d00b1115 to your computer and use it in GitHub Desktop.
modern-javascript-api-consumption
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
// Simulate a network request by using setTimeout | |
function fakeNetworkCall(url, callback) { | |
let returnData = { name: url }; | |
setTimeout(() => callback(returnData), 1500); | |
}; | |
// Make the first call | |
fakeNetworkCall('/api/endpoint/1/', (response1) => { | |
// When the call is done, the callback function | |
// is called, so we can work with the data here. | |
console.log(response1.name); | |
// Next Call! Hope I don't lose track of brackets... | |
fakeNetworkCall('/api/endpoint/2/', (response2) => { | |
// Hmm... where am I at? | |
console.log(response2.name); | |
// Oh boy - lets plunge another level deeper... | |
fakeNetworkCall('/api/endpoint/3/', (response3) => { | |
console.log(response3.name); | |
// etc... | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment