-
-
Notifications
You must be signed in to change notification settings - Fork 362
doc(FooterCounter): improve performance for ssr mode #6607
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
Changes from all commits
5f0c397
d808607
6690482
459a140
6fb15d0
0db7fe8
d72359d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| import Data from "../../_content/BootstrapBlazor/modules/data.js" | ||
|
|
||
| export function init(id, totalSeconds) { | ||
| const el = document.getElementById(id); | ||
| if (el === null) { | ||
| return; | ||
| } | ||
|
|
||
| const tick = () => { | ||
| const counter = Data.get(id); | ||
|
|
||
| counter.totalSeconds = (counter.totalSeconds || 0) + 1; | ||
| const now = Math.round(counter.totalSeconds, 0); | ||
|
|
||
| const days = Math.floor(now / (24 * 3600)); | ||
| const hours = Math.floor((now % (24 * 3600)) / 3600); | ||
| const minutes = Math.floor((now % 3600) / 60); | ||
| const seconds = now % 60; | ||
|
|
||
| const pad = num => num.toString().padStart(2, '0'); | ||
| el.innerHTML = `Run ${pad(days)}.${pad(hours)}:${pad(minutes)}:${pad(seconds)}`; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. security (javascript.browser.security.insecure-document-method): User controlled data in methods like Source: opengrep
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. security (javascript.browser.security.insecure-innerhtml): User controlled data in a Source: opengrep |
||
| } | ||
|
|
||
| const handler = setInterval(tick, 1000); | ||
| Data.set(id, { | ||
| el, | ||
| handler, | ||
| totalSeconds | ||
| }); | ||
| } | ||
|
|
||
| export function updateFooterCounter(id, totalSeconds) { | ||
| const counter = Data.get(id); | ||
| if (counter) { | ||
| counter.totalSeconds = totalSeconds; | ||
| console.log(`FooterCounter updated: ${id}, totalSeconds: ${totalSeconds}`); | ||
| } | ||
| } | ||
|
|
||
| export function dispose(id) { | ||
| const counter = Data.get(id); | ||
| if (counter) { | ||
| clearInterval(counter.handler); | ||
| Data.remove(id); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,3 +20,7 @@ | |
| .db-progress ::deep .progress { | ||
| flex: 1; | ||
| } | ||
|
|
||
| .progress-item:not(:last-child) { | ||
| margin-block-end: 1rem; | ||
| } | ||
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.
issue: Math.round does not accept a second argument.
Remove the second argument from Math.round, as it is ignored. If you need to round to a specific decimal place, consider using a different method.