-
Notifications
You must be signed in to change notification settings - Fork 12
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
new-log-viewer: Avoid redundant loadPage
after loadFile
when loading a URL with a logEventNum
specified.
#55
Conversation
…EventNum` is specified in the URL.
@Henry8192 kindly help review this |
loadPage
after loadFile
when logEventNum
is specified in the URL.loadPage
after loadFile
when logEventNum
is specified in the URL.
if (STATE_DEFAULT.pageNum !== pageNumRef.current) { | ||
if (newPageNum === pageNumRef.current) { | ||
// Don't need to switch pages so just update `logEventNum` in the URL. | ||
updateLogEventNumInUrl(numEvents, logEventNumRef.current); | ||
} else { |
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 (STATE_DEFAULT.pageNum !== pageNumRef.current) { | |
if (newPageNum === pageNumRef.current) { | |
// Don't need to switch pages so just update `logEventNum` in the URL. | |
updateLogEventNumInUrl(numEvents, logEventNumRef.current); | |
} else { | |
if (STATE_DEFAULT.pageNum === pageNumRef.current) { | |
return; | |
} else if (newPageNum === pageNumRef.current) { | |
// Don't need to switch pages so just update `logEventNum` in the URL. | |
updateLogEventNumInUrl(numEvents, logEventNumRef.current); | |
} else { |
How about making this an early return? We can avoid if inside ifs
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.
Hmm... How about
if (STATE_DEFAULT.pageNum !== pageNumRef.current) { | |
if (newPageNum === pageNumRef.current) { | |
// Don't need to switch pages so just update `logEventNum` in the URL. | |
updateLogEventNumInUrl(numEvents, logEventNumRef.current); | |
} else { | |
if (STATE_DEFAULT.pageNum !== pageNumRef.current) { | |
pageNumRef.current = newPageNum; | |
return; | |
} else if (newPageNum === pageNumRef.current) { | |
// Don't need to switch pages so just update `logEventNum` in the URL. | |
updateLogEventNumInUrl(numEvents, logEventNumRef.current); | |
} else { |
? i.e. update pageNumRef.current
before returning.
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 was thinking about avoiding duplicated code when I attempted to add the early return. If we agree this style is better, I'm fine duplicating the line to update pageNumRef.current
.
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 changed the !==
to ===
, will that save pageNumRef.current = newPageNum;
?
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.
Makes sense. There's no update pageNumRef.current = newPageNum
if they're the same.
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.
Sorry for misreading the code. I think we still need the pageNumRef.current = newPageNum
update before returning, right? Say what if newPageNum !== STATE_DEFAULT.pageNum
?
Co-authored-by: Henry8192 <50559854+Henry8192@users.noreply.github.com>
This reverts commit d7de3c1.
For the PR title, how about: new-log-viewer: Avoid redundant |
loadPage
after loadFile
when logEventNum
is specified in the URL.loadPage
after loadFile
when loading a URL with a logEventNum
specified.
References
new-log-viewer series: #45 #46 #48 #51 #52 #53
#48
new-log-viewer: Add UrlContextProvider to provide URL parameters and use them in the StateContextProvider.
It was found that when
logEventNum
is specified in the web application URL, a redundantloadPage
request is sent to the main service worker after an initialloadFile
request.Debug prints which show a redundant
loadPage
request is sent afterloadFile
Description
loadPage
afterloadFile
whenlogEventNum
is specified in the URL.Validation performed
loadPage
request is sent afterloadFile
.Screenshot showing no
loadPage
request is sent afterloadFile