-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Refactor global init code and add more comments #33755
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
95000ee
to
0b0ff57
Compare
0b0ff57
to
c8b753e
Compare
c8b753e
to
2e42865
Compare
I'm not sure I like the "global" name used here. It seems superflous. Why is it named like that? |
I think the meaning is accurate. Because there are "global" event handlers and init function callers (they affect all elements), and it matches If you have better and accurate names, please advise. And since these names are unique, even we keep them, we could always be able to easily change them by a search&replace in the future. |
621bd65
to
47244e9
Compare
47244e9
to
9208f4f
Compare
web_src/js/modules/init.ts
Outdated
for (let i = 0; i < 20 && i < this.results.length; i++) { | ||
// eslint-disable-next-line no-console | ||
console.log(`performance trace: ${this.results[i].name} ${this.results[i].dur.toFixed(3)}`); | ||
} |
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.
for (let i = 0; i < 20 && i < this.results.length; i++) { | |
// eslint-disable-next-line no-console | |
console.log(`performance trace: ${this.results[i].name} ${this.results[i].dur.toFixed(3)}`); | |
} | |
for (const [index, {name, dur}] of this.results.entries()) { | |
if (index >= 20) break; | |
console.info(`performance trace: ${name} ${dur.toFixed(3)}`); | |
} |
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.
I do not think it is performant, by the for ( let ...; i < len; ...)
loop, we do not need to create new "entries" object or extra if
check
if (perfTracer) { | ||
for (const func of functions) perfTracer.recordCall(func.name, func); | ||
} else { | ||
for (const func of functions) func(); | ||
} |
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.
if (perfTracer) { | |
for (const func of functions) perfTracer.recordCall(func.name, func); | |
} else { | |
for (const func of functions) func(); | |
} | |
for (const func of functions) { | |
perfTracer?.recordCall(func.name, func) ?? func(); | |
} |
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.
I do not think it is performant.
By using the if
, we do not need to check perfTracer
anymore in the loop
* giteaofficial/main: Disable `vet` as part of `go test` (go-gitea#33662) Refactor error system (go-gitea#33771) Add migrations and doctor fixes (go-gitea#33556) Refactor mail code (go-gitea#33768) Refactor global init code and add more comments (go-gitea#33755)
Follow up #33748 (refactor a lot and let's forget the old code: https://github.com/go-gitea/gitea/pull/33755/files?diff=split&w=0)
Now there are 3 "global" functions:
.ui.dropdown
data-global-init="initInputAutoFocusEnd"
data-global-click="onCommentReactionButtonClick"
And introduce
initGlobalInput
to replace oldinitAutoFocusEnd
andattachDirAuto
, usedata-global-init
to replace fragile.js-autofocus-end
selector.Another benefit is that by the new approach, no matter how many times
registerGlobalInitFunc
is called, we only need to do one "querySelectorAll" in the last step, it could slightly improve the performance.