redd
redd copied to clipboard
Simplify the process of dealing with MoreComments objects.
The Problem
When iterating through comments in a submission, users have to deal with a MoreComments, an object that represents comments that need to be expanded manually. Expanding them is also a pain because the object returns a flat listing of comments, forcing me to manually reconstruct the hierarchy locally.
The Solution
A custom CommentListing type that expands MoreComments as you iterate through it and caches the resulting data.
Architecture
Initialization
- A CommentListing is initialized by the Submission to represent the comments.
- Every subsequent comment also initializes the CommentListing with a reference to the main Submission.
Expanding
- If it hasn't been done before, a method is called on the Submission to traverse the comment tree and store references to all subcomments by their id. All unexpanded MoreComments are also stored separately.
- The MoreComments object uses this to check where to push expanded comments to.
- This also helps users fetch all comments in a submission.
This feature would be extremely useful. How are you currently constructing the hierarchy when expanding MoreComments?