P1B: Refactor (public/src/client/topic.js:157): Complex binary expression #241
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #236
Summary
Refactors
handleBookmarkinpublic/src/client/topic.jsto remove the complex binary expression at line 157 by introducing well-named boolean variables:hasBookmarkonFirstPageOrNoPaginationexceedsBookmarkThresholdThis preserves behavior and improves readability/maintainability.
What this file does
public/src/client/topic.jsinitializes and handles client-side behavior on topic pages (e.g., scrolling to posts, bookmarks, code block handlers, previews, etc.).handleBookmarkdecides where to scroll on page load and whether to show bookmark instructions.Scope of refactor
Only the conditional in
handleBookmarkgoverning the bookmark/instructions path (formerly at line 157). No logic changes elsewhere.Qlty evidence
Before:
public/src/client/topic.js
157 Complex binary expression
After:
public/src/client/topic.js
✅ The “Complex binary expression” at line 157 is no longer reported.
Manual runtime validation (UI)
console.log('P1B — VIVEK HANS — handleBookmark executed')inside the refactored block.hasBookmark && onFirstPageOrNoPagination && exceedsBookmarkThresholdis true, the code path executes and the log appears.console.logbefore committing.Lint & Test
npm run linthas no new errorsNODEBB_TEST_OFFLINE=1 DISABLE_PLUGIN_REGISTRY=1 npm run test→ passes locallyWhy this improves adaptability
The original compound condition obscured intent and made future changes risky. Naming sub-conditions documents the logic, makes diffs smaller, and isolates behavior changes to a single, readable line.
Alternatives considered
I considered extracting a helper
shouldShowBookmarkAlert(...), but opted to keep the logic inline with named booleans to minimize surface area and avoid extra indirection in a hot path.Risk/Impact
Low risk; refactor is a straight readability improvement with identical behavior.
Screenshot showing error on line 157 is gone now