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

Consolidating options #10

Open Pycea opened 1 month ago

Pycea commented 1 month ago

Right now, there's two places for options: the options framework, and the ones passed to replaceComments. It seems like it would be a good idea to consolidate those and clean up some globals while we're at it. For reference, the globals I added are OPTIONS, STYLES,optionShadow, and commentListRoot.

Since we can't really have modules in an extension, the best I can think of is to have some sort of option controller object which holds the first three and has commentListRoot injected when it's created. Moving all the replaceComment options in here would also allow options to have access to stuff like the current comment api and collapse depth. The only thing is, I don't think there's really a way to separate out something like STYLES into a separate file without more globals.

Let me know if you have any thoughts.

maksverver commented 1 month ago

I agree that there is some duplication of functionality there, and if nothing else, the naming is unfortunate because right now we have two types of "options".

I'm okay with the idea of refactoring this somehow, but I'd suggest waiting until most of the functionality has been committed, and then refactoring afterwards. The benefit of this approach is that if the features are implemented, their requirements are known, while refactoring beforehand might lead to a solution that is either overly general or not general enough to support the desired use cases.

Do you have a concrete idea which features you would like to port over, or is it more open-ended?

For a bit of background, the idea behind replaceComments() was that it generates a DOM tree deterministically from a combination of comments.json + options object, and if either changes, then replaceComments() could be called again to re-render the comments (currently, this never happens for real, but that's what demo.html does when you change an option). The downside of this approach compared to your options API is that recreating the comments from scratch destroys any state (like collapsed threads, open reply editors, etc.) but the thinking was that people don't change options that often, so it might not matter.