3 ms·
> I learned the hard way long ago: more often than not, people don’t actually want (or need) trees, they just need the appearance of them. I've been noticing t
by aragonite 3y ago
> I learned the hard way long ago: more often than not, people don’t actually want (or need) trees, they just need the appearance of them.
I've been noticing that this is one way in which HN and Reddit differ. On HN, a child comment is a nextSibling of the parent comment, with indent set to parent's indent plus one to simulate the appearance of trees. On Reddit (or at least old.reddit.com, don't know about the new site), a child comment is actually nested inside the parent comment.
- pvg 3y agoYou mean in the HTML, not in the actual presentation, right? The way it looks on screen is more or less identical.
- hunter2_ 3y agoThat's definitely how I interpret it, as using the word nextSibling [0] in camel case is quite specific to DOM manipulation. While "the way it looks" might be all that matters to most users, perhaps there are cases where semantic markup is critical (screen readers? browser extension development?). [0] https://developer.mozilla.org/en-US/docs/Web/API/Node/nextSibling https://developer.mozilla.org/en-US/docs/Web/API/Node/nextSi...
- jprete 3y agoI can't imagine it's stored this way in the backend. Every operation on the data would be a complicated mess of inferring the tree structure then translating back to the implied tree format.
- sterlind 3y agohow does collapse work then?
- kijin 3y agoLoop over next siblings and hide them one by one, until you hit an entry with an indentation level that is less than or equal to that of the current entry?
- refset 3y agoTake a look at the kidvis function in hn.js
- archgoon 3y agoIt iterates across sibling comment elements, hides them, until it encounters one whose indent level is less than or equal to the initial indent level.
- sterlind 3y agothat makes sense. you're shadowbanned by the way, I had to vouch for your comment.