refactor: Simplify ADD action logic by removing unreachable code paths #206
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.
Description
This PR removes two pieces of dead code in the
ADDaction of the overlay reducer that can never be executed due to the control flow logic.Changes
Removed redundant
if (overlay == null || overlay.isOpen)checkSimplified the ternary operator for
overlayDataisExisted ? state.overlayData : { ...state.overlayData, [action.overlay.id]: action.overlay }{ ...state.overlayData, [action.overlay.id]: action.overlay }isExistedis true, the firstifblock already handles the reopen caseMotivation and Context
Both pieces of code represent unreachable paths:
Redundant null check: The outer
ifconditionstate.overlayData[action.overlay.id] != null && state.overlayData[action.overlay.id].isOpen === falsealready ensures the overlay exists and is closed, making the inner check impossible to trigger.Unreachable ternary branch: When execution reaches the final return statement:
overlayData[id]exists and is closed → handled by firstifblockoverlayData[id]exists and is open → throws erroroverlayData[id]doesn't exist → new overlay, must be added tooverlayDataTherefore,
isExistedcan only be true if there's data inconsistency betweenoverlayOrderListandoverlayData, which shouldn't happen in normal operation.Removing this dead code improves clarity and maintainability.
How Has This Been Tested?
packages/src/context/reducer.test.tspassScreenshots (if appropriate):
This change improved test coverage to 100%.
Types of changes
Checklist
Further Comments
This refactoring removes two pieces of unreachable code without changing any behavior. The control flow analysis shows that both the redundant null check and the
isExistedternary branch can never execute in practice, making them safe to remove.