feat(Log)!: Convert Log class to module #814
Merged
+59
−58
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.