Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Log)!: Convert Log class to module #814

Merged
merged 1 commit into from
Nov 22, 2024
Merged

Conversation

absidue
Copy link
Collaborator

@absidue absidue commented Nov 21, 2024

This pull request converts the logger from a class to a module, as all methods and properties in the logger class were static, there was no real reason to keep it as a class. In FreeTube this shaved 889 bytes off the bundle, I know it's not much but it is something. It also meant that terser was able to inline the number values from the Level object to where they are used, which avoid having to look them up in the object at runtime.

I've marked this as a breaking change just in case someone was using the Log class as a type, but any code to use the logger outside of YouTube.js e.g. to set the log level can stay the same. If you feel like this doesn't warrant being a breaking change, I am happy to adjust the commit message and pull request title to remove the !.

If you are used to writing Java code where everything needs to be a class you might try to do the same in JavaScript but for web apps using classes when they are not needed is considered an anti-pattern as most mimifiers can't optimise classes, so they end up in the output almost identical as in the source code. The only mimifier that can handle classes is the Google Closure Compiler but that requires writing code specifically for it, including special comments on all classes, properties and methods.

@absidue absidue requested a review from LuanRT November 21, 2024 22:15
@absidue absidue changed the title feat!: Convert Log class to module feat(Log)!: Convert Log class to module Nov 21, 2024
@LuanRT LuanRT merged commit fc55716 into LuanRT:main Nov 22, 2024
4 checks passed
@absidue absidue deleted the log-module branch November 22, 2024 06:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants