-
Notifications
You must be signed in to change notification settings - Fork 388
refactor: simplify the code #91
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
Conversation
I think it's just Evan's style maybe, you can find a lot similar code in vue as well. |
const s = document.currentScript | ||
if (s && s.hasAttribute('init')) { | ||
createApp().mount() | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const s = document.currentScript | |
if (s && s.hasAttribute('init')) { | |
createApp().mount() | |
} | |
document.currentScript?.hasAttribute('init') && createApp().mount() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Elegant code! But do we really need the question mark after the document?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe -- I'm replicating the logic. if s = document.currentScript
and then on line 8, we have s && ...
I imagine document.currentScript
could be undefined. Don't have any experience using this property however.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But then we only need document.currentScript?.someMethod
as document
will always be defined in this context.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revised
|
But I just thought the readability is also part of the enhancement right? 😂 |
It seems strange to write assignment in the if statement, and to use the
let
token instead ofconst
to define a variable that you will never change. I just started reading the source code of this project recently, so I tried to simplify the code to make some refinements on the entry file.