Last active
June 18, 2019 18:05
-
-
Save Gaafar/de1266d2338ba2393e5bada866178067 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
const makeRequest = () => { | |
return getJSON() | |
.then(data => { | |
if (data.needsAnotherRequest) { | |
return makeAnotherRequest(data) | |
.then(moreData => { | |
console.log(moreData) | |
return moreData | |
}) | |
} else { | |
console.log(data) | |
return data | |
} | |
}) | |
} |
@sanyatuning +1
Nice @sanyatuning +1 ... I'd shorten it up a little more:
const makeRequest = () => {
return getJSON()
.then(data => data.needsAnotherRequest
? makeAnotherRequest(data)
: data)
.then(data => console.log(data) || data)
}
+1 for both of you
Removing one label of nesting of nesting
const makeRequest = () => {
return getJSON()
.then(data => {
if (data.needsAnotherRequest) {
return makeAnotherRequest(data)
}else {
return data
}
})
.then(moreData => {
return moreData
})
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
const makeRequest = () => {
return getJSON()
.then(data => {
if (data.needsAnotherRequest) {
return makeAnotherRequest(data)
} else {
return data
}
}).then(data => {
console.log(data)
})
}