maksverver / astral-codex-eleven

A Chrome browser extension to speed up loading of posts on https://www.astralcodexten.com/ by replacing the comments widget.
MIT License
3 stars 2 forks source link

Clean up legacy options #20

Open Pycea opened 1 month ago

Pycea commented 1 month ago
maksverver commented 1 month ago

I think these changes should be separated out, and I'm not sure I'm really supportive of any of them.

  1. Moving the API class into a separate file: I don't want to create too many small files, because there is no postprocessor to merge files, and we don't have modules to manage interdependencies. Given that, I would prefer to keep the number of files small, to simplify maintaining the inclusion order. (Originally there was only astral-codex-eleven.js and ext-comments.js and the reason for having two files was that the former needed to run in the context of the main page — also it made implementing the demo page easier).

  2. Removing the REPLACE_COMMENTS_DEFAULT_OPTIONS constant: I agree it doesn't provide many useful defaults anymore, but the declaration also serves as a form of documentation (similar like your templateOption which is not strictly used at all). We could move that to a comment but I'm not sure that's much better. Keeping the default also has the benefit that we can add options to it and call sites will continue to work correctly (though I admit this isn't all that important; we can also just update the call sites in that case).

  3. Changing the reverseSelf() implementation: do you have evidence that the new implementation is significantly faster? From the code, it's not clear to me that it would be (though sometimes browsers work in mysterious ways, so I don't want to rule it out), and the original implementation seems somewhat shorter and more clear about its intent. Yes, there is an array creation in there, but I think the cost of this is negligible typically.

(I think if we need to optimize this, we could start by checking if childNodes.length > 1; mathematically, the number of comments with 2 or more replies must be less than 50%.)