Skip to content

refactor: hoist constructor-assigned properties to class fields in src/core and src/platform/input#8635

Merged
willeastcott merged 1 commit into
mainfrom
refactor/class-fields-input
Apr 22, 2026
Merged

refactor: hoist constructor-assigned properties to class fields in src/core and src/platform/input#8635
willeastcott merged 1 commit into
mainfrom
refactor/class-fields-input

Conversation

@willeastcott
Copy link
Copy Markdown
Contributor

@willeastcott willeastcott commented Apr 22, 2026

Summary

  • Aligns src/core/tags.js and every class in src/platform/input/ with the class-fields convention in AGENTS.md §15. All properties previously assigned only via this.x = ... in a constructor now have explicit class-field declarations with @type JSDoc blocks.
  • Removes a couple of redundant constructor assignments that duplicated class-field initializers (GamePads.current / GamePads._previous and TouchDevice._element).
  • Tightens the JSDoc return type of getTouchTargetCoords in src/platform/input/touch-event.js from the generic object to {x: number, y: number}.

Hoisted fields by class:

  • Tags: _parent
  • MouseEvent: buttons
  • Mouse: _upHandler, _downHandler, _moveHandler, _wheelHandler, _contextMenuHandler
  • Keyboard: _keyDownHandler, _keyUpHandler, _keyPressHandler, _visibilityChangeHandler, _windowBlurHandler, preventDefault, stopPropagation
  • TouchDevice: _element, _startHandler, _endHandler, _moveHandler, _cancelHandler
  • GamePad: id, index, _buttons, _axes, _previousAxes, mapping, map, hand, pad (existing inline JSDoc preserved)
  • GamePads: gamepadsSupported, current, _previous, _ongamepadconnectedHandler, _ongamepaddisconnectedHandler

No behavior changes.

Test plan

  • npx eslint src/platform/input/ passes
  • npm run build:types succeeds
  • npm run test:types succeeds
  • CI green

Aligns `src/core/tags.js` and all classes in `src/platform/input/` with the
class-fields convention in AGENTS.md §15: every property assigned via
`this.x = ...` now has a corresponding class-field declaration with a
`@type` JSDoc block.

- `Tags._parent` hoisted.
- `MouseEvent.buttons` hoisted.
- `Mouse` bound event handlers (`_upHandler`, `_downHandler`, `_moveHandler`,
  `_wheelHandler`, `_contextMenuHandler`) hoisted.
- `Keyboard` bound event handlers (`_keyDownHandler`, `_keyUpHandler`,
  `_keyPressHandler`, `_visibilityChangeHandler`, `_windowBlurHandler`) plus
  `preventDefault` / `stopPropagation` hoisted.
- `TouchDevice._element` and bound handlers hoisted; redundant
  `this._element = null` removed from the constructor.
- `GamePad` (id, index, _buttons, _axes, _previousAxes, mapping, map, hand,
  pad) hoisted, preserving existing JSDoc.
- `GamePads` (gamepadsSupported, current, _previous, and the two connect
  handlers) hoisted; `current` / `_previous` now initialized directly via
  field initializers, removing redundant constructor assignments.

Also tightens the return type of `getTouchTargetCoords` in
`src/platform/input/touch-event.js` from `object` to `{x: number, y: number}`.

No behavior changes. Verified with `npx eslint src/platform/input/`,
`npm run build:types`, and `npm run test:types`.

Made-with: Cursor
@willeastcott willeastcott requested a review from Copilot April 22, 2026 13:58
@willeastcott willeastcott self-assigned this Apr 22, 2026
@willeastcott willeastcott added area: input Input related issue enhancement Request for a new feature labels Apr 22, 2026
@willeastcott willeastcott merged commit 70063c4 into main Apr 22, 2026
10 checks passed
@willeastcott willeastcott deleted the refactor/class-fields-input branch April 22, 2026 14:00
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Refactors core/input classes to follow the repository’s class-fields convention by hoisting constructor-assigned properties into explicit class field declarations and tightening a touch helper return type.

Changes:

  • Hoists constructor-assigned properties to class fields across src/core/tags.js and src/platform/input/* classes.
  • Removes redundant constructor assignments that duplicate class-field initializers (e.g. GamePads.current, GamePads._previous, TouchDevice._element).
  • Narrows getTouchTargetCoords JSDoc return type to {x: number, y: number}.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/platform/input/touch-event.js Tightens JSDoc return type for getTouchTargetCoords.
src/platform/input/touch-device.js Hoists _element and handler properties to class fields; removes redundant ctor assignment.
src/platform/input/mouse.js Hoists bound handler properties to class fields.
src/platform/input/mouse-event.js Adds buttons as an explicit class field with JSDoc.
src/platform/input/keyboard.js Hoists bound handler properties and options flags to class fields with JSDoc.
src/platform/input/game-pads.js Hoists GamePad/GamePads constructor-assigned properties to class fields; removes redundant ctor array initializations.
src/core/tags.js Hoists _parent to an explicit class field with JSDoc.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/core/tags.js
_list = [];

/**
* @type {object}
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

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

_parent is declared as @type {object}, but constructor(parent) accepts parent as optional, so _parent can be undefined. Update the field JSDoc (and/or add an initializer) to reflect the actual possible values (e.g. object|undefined or initialize to null and type object|null) so generated types/docs are accurate.

Suggested change
* @type {object}
* @type {object|undefined}

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: input Input related issue enhancement Request for a new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants