Skip to content

perf: refactor Keyborg classes to closure-based factories#144

Open
layershifter wants to merge 1 commit intomicrosoft:mainfrom
layershifter:perf/closure-refactor
Open

perf: refactor Keyborg classes to closure-based factories#144
layershifter wants to merge 1 commit intomicrosoft:mainfrom
layershifter:perf/closure-refactor

Conversation

@layershifter
Copy link
Copy Markdown
Member

@layershifter layershifter commented Apr 22, 2026

Summary

  • Rewrites src/Keyborg.mts to use factory functions instead of classes. Per-instance state lives in closure variables, which the minifier can mangle; class property names like this._triggerKeys cannot be mangled.
  • Public API unchanged. Keyborg becomes an exported interface (it was already only re-exported as a type from index.mts). createKeyborg, disposeKeyborg, and the KeyborgCallback type are unchanged.
  • WindowWithKeyborg.__keyborg retains its outer { core, refs } shape for any external consumer (e.g., Tabster) that reads it. The internal core handle shape changes: it is now { dispose, getNavigating, setNavigating } instead of a KeyborgCore class instance with a getter/setter for isNavigatingWithKeyboard.

Notes for reviewers

  • The internal core.isNavigatingWithKeyboard getter/setter is gone. If any consumer reads window.__keyborg.core.isNavigatingWithKeyboard directly, that is an undocumented leak and would break here — please flag if aware of any such consumer.
  • The _id values assigned to instances no longer interleave with core counters. This only shows up in the dev-mode "Keyborg instance <id> is being disposed incorrectly" console.error string.

🤖 Generated with Claude Code

@layershifter layershifter requested review from a team and mshoho as code owners April 22, 2026 18:26
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 22, 2026

📊 Bundle size report

Package & Exports Baseline (minified/GZIP) PR Change
keyborg
All exports
6.606 kB
1.957 kB
4.893 kB
1.746 kB
-1.713 kB
-211 B
keyborg
createKeyborg() & disposeKeyborg()
6.37 kB
1.904 kB
4.657 kB
1.693 kB
-1.713 kB
-211 B
Unchanged fixtures
Package & Exports Size (minified/GZIP)
keyborg
KEYBORG_FOCUSIN constant
64 B
80 B
🤖 This report was generated against f823bc9619ff7df43dc54c92e66889aa3bed90bf

Replaces class KeyborgCore and class Keyborg with factory functions.
Per-instance state moves from this._x fields (which minifiers cannot
mangle at target: "es2019") to closure locals (which they can). Public
API unchanged: createKeyborg, disposeKeyborg, and the Keyborg type
(now an interface) keep the same shape. WindowWithKeyborg.__keyborg
retains its outer { core, refs } shape.

Bundle-size deltas vs post-PR-1 baseline:
- All exports:                        -1.693 kB min / -212 B gz
- createKeyborg + disposeKeyborg:     -1.693 kB min / -211 B gz
- KEYBORG_FOCUSIN constant:           no change

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@layershifter layershifter force-pushed the perf/closure-refactor branch from 2b875cd to ed3d2cb Compare April 23, 2026 11:53
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