Skip to content

refactor(focus): split propagateKeyPress into phase helpers#19

Merged
chiefcll merged 1 commit into
mainfrom
refactor/propagate-key-press
May 21, 2026
Merged

refactor(focus): split propagateKeyPress into phase helpers#19
chiefcll merged 1 commit into
mainfrom
refactor/propagate-key-press

Conversation

@chiefcll
Copy link
Copy Markdown
Contributor

Summary

propagateKeyPress had grown to 135 lines with two near-identical throttle checks (one per loop) and two distinct sub-algorithms inlined. Pull them apart:

  • isElementThrottled(elm, sameKey, currentTime) — single source of truth for per-element rate-limiting. Previously copy-pasted across the capture and bubble loops as a 9-line if (elm.throttleInput) { if (sameKey && ...) return true; } block.
  • runCapturePhase(...) — root→leaf walk, returns whether propagation should stop.
  • runBubblePhase(...) — leaf→root walk, returns { handled, lastHandlerSeen } so the debug log keeps its "which element had a handler but didn't claim" output without a function-scope mutable.

propagateKeyPress is now a flat orchestrator: global throttle → history record → capture → bubble → debug log. The orchestrator body drops from ~135 lines to ~50.

Behavior

Unchanged. Same handler-firing order, same throttle semantics, same debug-log messages (just with the message body interpolated once instead of twice). All 120 tests pass.

Test plan

  • npm run tsc — clean
  • npm test — 120/120 pass
  • npm run lint — 0 errors

🤖 Generated with Claude Code

The function had grown to 135 lines with two near-identical 9-line throttle
checks (once in the capture loop, once in the bubble loop) and two distinct
sub-algorithms inlined. Pull them apart:

- `isElementThrottled(elm, sameKey, currentTime)` — single source of truth
  for per-element rate-limiting; previously copy-pasted across the two loops.
- `runCapturePhase(...)` — root→leaf walk, returns whether to stop.
- `runBubblePhase(...)` — leaf→root walk, returns `{ handled, lastHandlerSeen }`
  so the debug log keeps its "which element had a handler but didn't claim"
  output without a function-scope mutable.

`propagateKeyPress` is now a flat orchestrator: global throttle → history
record → capture → bubble → debug log. Behavior is unchanged; the LoC goes
up slightly (helpers carry signatures and one short doc comment each) but
the orchestrator body drops from ~135 to ~50 lines.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@chiefcll chiefcll merged commit 9b1db78 into main May 21, 2026
1 check passed
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.

1 participant