Last active
August 12, 2018 01:52
-
-
Save dance2die/053647daae0fc976d56b6c1b4a9775c7 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
async function* getContent( | |
url = `https://www.reddit.com/r/reactjs/.json?limit=2` | |
) { | |
let nextUrl = null; | |
while (true) { | |
nextUrl = nextUrl || url; | |
const json = await fetch(nextUrl).then(response => response.json()); | |
nextUrl = `${url}&after=${json.data.after}`; | |
yield json.data.children.map(_ => _.data); | |
} | |
} | |
export { getContent }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment