Skip to content

refactor(sprite): migrate SpriteComponent state to class fields#8672

Merged
willeastcott merged 1 commit into
mainfrom
refactor/sprite-class-fields
May 3, 2026
Merged

refactor(sprite): migrate SpriteComponent state to class fields#8672
willeastcott merged 1 commit into
mainfrom
refactor/sprite-class-fields

Conversation

@willeastcott

Copy link
Copy Markdown
Contributor

Summary

Migrates the constructor-initialised instance state of SpriteComponent to ES2022 public class field declarations, continuing the refactor pass previously applied to several other components.

  • ~24 pure literal / no-arg-constructor fields moved out of the constructor (e.g. _type, _color, _colorUniform, _speed, _flipX, _flipY, _width, _height, _drawOrder, _layers, 9-slicing state, batch-group state, _node, _model, _clips, etc.).
  • /** @private */ tags added to the new class fields, matching the convention used elsewhere (e.g. button/component.js, scroll-view/component.js).
  • Complex initialisation stays in the constructor, matching codebase convention (no precedent for this.system.foo / .bind(this) in class field initialisers):
    • _material = system.defaultMaterial (references the system parameter)
    • _model.graph / entity.addChild / _model._entity wiring (side effects on external objects)
    • _updateAabbFunc = this._updateAabb.bind(this)
    • _defaultClip = new SpriteAnimationClip(this, { name: this.entity.name, ... }) (passes this and reads this.entity.name)
    • _currentClip = this._defaultClip
  • Pre-existing JSDoc on _clips and _currentClip preserved; _defaultClip now has a JSDoc @type {SpriteAnimationClip|null} block where previously there was none.

Pure internal refactor. No behavioural change, no public API change.

Test plan

  • npm run lint — clean.
  • npm test — 1672 tests passing.

Co-authored-by: Cursor <cursoragent@cursor.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors SpriteComponent to use ES2022 public class fields for its internal default state, aligning it with similar component refactors elsewhere in the framework while preserving the existing runtime behavior and API surface.

Changes:

  • Moves the simple constructor-initialized internal state in SpriteComponent to class field declarations.
  • Keeps constructor-only setup for values that depend on constructor arguments, side effects, or bound functions.
  • Preserves and slightly improves private JSDoc annotations for internal sprite clip state.

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

@willeastcott willeastcott merged commit 14dee6e into main May 3, 2026
12 checks passed
@willeastcott willeastcott deleted the refactor/sprite-class-fields branch May 3, 2026 16:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Request for a new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants