refactor: migrate ComponentData classes to class fields#8668
Merged
Conversation
Convert all `*ComponentData` classes in `src/framework/components/*/data.js` from constructor-based initialization to ES2022 public class field declarations, matching the style already used by `scroll-view` and `scrollbar`. Nullable `@type` annotations are updated to include `|null` where fields are initialized to `null`. Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors framework component data containers to use ES2022 public class fields instead of constructor-based initialization, aligning the remaining *ComponentData classes with the style already used elsewhere in the component system. In the broader codebase, these classes are instantiated by ComponentSystem.addComponent() as default data holders, so the change is primarily about syntax and typing clarity rather than behavior.
Changes:
- Replaced trivial constructors in many
*ComponentDataclasses with a singleenabled = trueclass field. - Converted the richer
ButtonComponentData,CollisionComponentData, andParticleSystemComponentDataclasses from constructor assignments to field declarations while preserving defaults and comments. - Updated nullable JSDoc annotations on class fields where properties are initialized to
null, improving type-checking consistency.
Reviewed changes
Copilot reviewed 21 out of 21 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/framework/components/zone/data.js | Replaces constructor default with class field for enabled. |
| src/framework/components/sprite/data.js | Replaces constructor default with class field for enabled. |
| src/framework/components/sound/data.js | Replaces constructor default with class field for enabled. |
| src/framework/components/script/data.js | Replaces constructor default with class field for enabled. |
| src/framework/components/screen/data.js | Replaces constructor default with class field for enabled. |
| src/framework/components/rigid-body/data.js | Replaces constructor default with class field for enabled. |
| src/framework/components/render/data.js | Replaces constructor default with class field for enabled. |
| src/framework/components/particle-system/data.js | Converts all particle-system defaults and nullable JSDoc annotations to class fields. |
| src/framework/components/model/data.js | Replaces constructor default with class field for enabled. |
| src/framework/components/light/data.js | Replaces constructor default with class field for enabled. |
| src/framework/components/layout-group/data.js | Replaces constructor default with class field for enabled. |
| src/framework/components/layout-child/data.js | Replaces constructor default with class field for enabled. |
| src/framework/components/joint/data.js | Replaces constructor default with class field for enabled. |
| src/framework/components/gsplat/data.js | Replaces constructor default with class field for enabled. |
| src/framework/components/element/data.js | Replaces constructor default with class field for enabled. |
| src/framework/components/collision/data.js | Converts collision defaults and nullable asset/model typings to class fields. |
| src/framework/components/camera/data.js | Replaces constructor default with class field for enabled. |
| src/framework/components/button/data.js | Converts button defaults and nullable asset/entity typings to class fields. |
| src/framework/components/audio-listener/data.js | Moves serialized enabled default to a class field while preserving comment intent. |
| src/framework/components/animation/data.js | Replaces constructor default with class field for enabled. |
| src/framework/components/anim/data.js | Replaces constructor default with class field for enabled. |
💡 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
Converts all
*ComponentDataclasses insrc/framework/components/*/data.jsfrom constructor-based initialization to ES2022 public class field declarations, matching the style already used byscroll-viewandscrollbar.enabled = true) collapsed to a single class field.ButtonComponentData,CollisionComponentDataandParticleSystemComponentDataconverted while preserving inline comments, section comments and JSDoc@typeannotations.@typeannotations are updated to include|nullwhere the field is initialized tonull, so TypeScript validation passes with class-field semantics.This is a pure internal refactor — no behavioral changes, no public API changes, no renames.
Test plan
npm run lint— passes (0 errors; the single pre-existing warning inutils/rollup-build-target.mjsis unrelated).npm test— 1672 tests passing.