Skip to content

Instantly share code, notes, and snippets.

@dance2die
Last active August 12, 2018 01:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dance2die/053647daae0fc976d56b6c1b4a9775c7 to your computer and use it in GitHub Desktop.
Save dance2die/053647daae0fc976d56b6c1b4a9775c7 to your computer and use it in GitHub Desktop.
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