refactor(sprite): migrate SpriteComponent state to class fields#8672
Merged
Conversation
Co-authored-by: Cursor <cursoragent@cursor.com>
Contributor
There was a problem hiding this comment.
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
SpriteComponentto 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Migrates the constructor-initialised instance state of
SpriteComponentto ES2022 public class field declarations, continuing the refactor pass previously applied to several other components._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).this.system.foo/.bind(this)in class field initialisers):_material = system.defaultMaterial(references thesystemparameter)_model.graph / entity.addChild / _model._entitywiring (side effects on external objects)_updateAabbFunc = this._updateAabb.bind(this)_defaultClip = new SpriteAnimationClip(this, { name: this.entity.name, ... })(passesthisand readsthis.entity.name)_currentClip = this._defaultClip_clipsand_currentClippreserved;_defaultClipnow 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.