Last active
October 28, 2017 19:31
-
-
Save ktilcu/f9d528751aee54bfe40f09e111e5abcd 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
| // Imperative A/A | |
| const makeRequest = async () => { | |
| const data = await getJSON() | |
| if (data.needsAnotherRequest) { | |
| const moreData = await makeAnotherRequest(data); | |
| console.log(moreData) | |
| return data.concat(moreData); // added this | |
| } else { | |
| console.log(data) | |
| return data | |
| } | |
| } | |
| // Promises | |
| const another = (data) => makeAnotherRequest(data).then(more=>data.concat(more)); | |
| const makeRequest = () => getJSON() | |
| .then(data => data.needsAnotherRequest ? another(data) : data) | |
| // Promises and Ramda | |
| const another = (data) => makeAnotherRequest(data).then(R.concat(data)); | |
| const makeRequest = () => getJSON() | |
| .then( | |
| R.ifElse( | |
| R.prop('needsAnotherRequest'), // if | |
| another, // then | |
| R.identity // else | |
| ) | |
| ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment