Whether or not this listing can perform a fetch to get more data.
If this returns false
you can be sure that this listing will never cause
an api call. If this is true
it does not mean that there are more
unfetched items in the Listing, only that there might be.
true
if the listing could try to fetch more items, false
otherwise.
Execute a function on pages of the listing.
The function to execute on each page. If this returns or
resolves to false
the execution will be halted.
A promise that resolves when the listing has been exhausted.
Execute a function on each element of the listing.
The function to execute on each item in the listing. If this
returns or resolves to false
the execution will be halted.
A promise that resolves when the iteration is complete.
This is an enhanced version of the default Array.forEach. It allows for asynchronous callbacks and breaking.
async function slowAsync(post: Post): Promise<void> {
// do something slow
}
const posts = await client.subreddits.getNewPosts("funny");
await posts.forEach(post => slowAsync(post));
const posts = await client.subreddits.getNewPosts("funny");
await posts.forEach(post => {
console.log(post.title);
// Break if the post was more than 5 minutes old.
return post.createdUtc >= (Date.now() / 1000) - 5 * 60;
});
Determines whether the specified callback function returns true for any element of the listing.
The matcher to run on each element in the listing. If this
returns true
at any point the searching is stopped.
A promise that resolves to true
if handler
returned true
for
some element in the listing, or false
if it reached the end of the
listing without finding a match.
Generated using TypeDoc
A Listing of items.
Listings are probably the most common data type on Reddit. Snoots intentionally exposes as little as possible about the internal workings to minimize the amount of boilerplate needed to interact with them.
Note
Since Reddit's responses are paged, Listings only implement asyncIterator. This means that if you want to loop over it you have to use
for await
:Note
If you want to iterate using callbacks, you can use forEach:
Note
If you want to get an entire page at a time, use eachPage: