-
-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
refactor: small readability improvements #5748
Conversation
@@ -128,7 +128,7 @@ function mapTransitions(Components, to, from) { | |||
|
|||
async function loadAsyncComponents(to, from, next) { | |||
// Check if route path changed (this._pathChanged), only if the page is not an error (for validate()) | |||
this._pathChanged = !!app.nuxt.err || from.path !== to.path | |||
this._pathChanged = Boolean(app.nuxt.err) || from.path !== to.path |
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.
neat: If we swipe conditions, we can prevent unnecessary Boolean cast where from.path !== to.path
this._pathChanged = Boolean(app.nuxt.err) || from.path !== to.path | |
this._pathChanged = from.path !== to.path || Boolean(app.nuxt.err) |
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.
Do you mean this?
this._pathChanged = Boolean(app.nuxt.err) || from.path !== to.path | |
this._pathChanged = from.path !== to.path || app.nuxt.err |
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.
Well actually it depends. || app.nuxt.err
can cause _pathChanged
to be instance of err
instead of Boolean (true/false). This is why we use !!
or Boolean
. If such type safety is not important we can omit Boolean
everywhere :)
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.
@manniL Good changes.
For Boolean
, I agree with using it in property assignment this.foo = Boolean(bar) || ...
.
For local variable or if statement, !!
may have some benefits.
if( !!this.app.err && a !== 'abc'){
console.log(1)
}
// after terser compression, !! will be removed, Boolean(..) won't
this.app.err&&"abc"!==a&&console.log(1)
The !!
is removed, the code size is smaller and there is no reference leak risk in these cases, so it should be fine.
@clarkdo Didn't know about the difference between The question is if it's worth the few bytes, but the trade-off is always present 🙈 |
Terser is only effective on |
I'd keep that PR as is and create new ones for larger changes |
@pi0 IMO no, I also use But if you disagree with that I'm happy to revert |
Codecov Report
@@ Coverage Diff @@
## dev #5748 +/- ##
=========================================
+ Coverage 95.6% 95.64% +0.03%
=========================================
Files 82 82
Lines 2662 2662
Branches 683 683
=========================================
+ Hits 2545 2546 +1
+ Misses 98 97 -1
Partials 19 19
Continue to review full report at Codecov.
|
@manniL No both array and obj destruction are nice things. I just meant about single value arrays. We can do it for consistency or keep |
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.
Changes
!!sth
toBoolean(sth)
{ abc: abc }
to{ abc }
const abc = someArray[0]
toconst [abc] = someArray