Skip to content

Conversation

@jiji-hoon96
Copy link
Contributor

@jiji-hoon96 jiji-hoon96 commented May 12, 2025

Description

Refactors the duplicated logic for determining the current overlay ID into a separate utility function. This change improves code maintainability and reduces the risk of inconsistent behavior between the 'CLOSE' and 'REMOVE' operations.

Changes

  • Extracted duplicated logic for determining the current overlay ID into a determineCurrentOverlayId function
  • Updated the reducer to use this function in both 'CLOSE' and 'REMOVE' cases
  • Added unit tests for the extracted function to ensure correctness
스크린샷 2025-05-12 오후 11 23 00

Motivation and Context

While reviewing the code, I noticed that the same complex logic for determining which overlay should be active after closing or removing an overlay was duplicated in two places. This duplication makes it harder to maintain the code and increases the risk of inconsistent behavior if one implementation is updated but not the other.

How Has This Been Tested?

  • Added dedicated unit tests for the extracted function covering key scenarios
    • Closing the last overlay
    • Closing an intermediate overlay
    • Handling closed overlays in the calculation
    • Handling the case of closing the only open overlay
  • Ran existing tests to verify that the behavior remains unchanged
  • Manually tested with the example applications to confirm correct functionality

Types of changes

  • Refactoring (code improvement with no functionality changes)

Checklist

  • I have performed a self-review of my own code
  • My code is commented, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my refactoring is effective
  • New and existing unit tests pass locally with my changes

Note to Maintainers

I considered a few options for where to place the extracted utility function

  1. Current implementation: Placed in a new overlay-utils.ts file in the context directory since it's closely related to overlay state management
  2. Alternative: Could be placed within reducer.ts as a private function (but would limit reusability)
  3. Alternative: Could be moved to the general utils directory if it might be used more broadly in the future

I'm open to suggestions if you prefer a different location or naming convention for this utility function.

This commit extracts the duplicated logic for determining the current overlay ID
into a separate utility function. The same logic was previously duplicated in
both 'CLOSE' and 'REMOVE' reducer cases. This refactoring improves code
maintainability and reduces the risk of inconsistent behavior between these
operations.

- Create overlay-utils.ts with determineCurrentOverlayId function
- Update reducer.ts to use the new utility function
- Add unit tests for the extracted function
@jiji-hoon96 jiji-hoon96 requested a review from jungpaeng as a code owner May 12, 2025 14:26
@changeset-bot
Copy link

changeset-bot bot commented May 12, 2025

🦋 Changeset detected

Latest commit: 2847229

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
overlay-kit Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link

vercel bot commented May 12, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
overlay-kit ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 11, 2025 2:34am

@codecov-commenter
Copy link

codecov-commenter commented May 12, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.15%. Comparing base (a6e2f15) to head (2847229).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #167      +/-   ##
==========================================
+ Coverage   93.87%   94.15%   +0.27%     
==========================================
  Files          12       12              
  Lines         343      342       -1     
  Branches       85       83       -2     
==========================================
  Hits          322      322              
+ Misses         20       19       -1     
  Partials        1        1              
Components Coverage Δ
overlay-kit 94.15% <100.00%> (+0.27%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Member

@jungpaeng jungpaeng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the suggestion.

Currently, the determineCurrentOverlayId function is only being used inside the reducer, and it doesn’t seem likely that it will be used outside of it. Could you move it to the reducer.ts file?

@jiji-hoon96
Copy link
Contributor Author

I made the change as requested.
Thank you!

Copy link
Member

@jungpaeng jungpaeng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@jungpaeng jungpaeng merged commit b19f2c6 into toss:main Jun 11, 2025
9 of 10 checks passed
@github-actions github-actions bot mentioned this pull request Jun 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants