-
Notifications
You must be signed in to change notification settings - Fork 54
fix: recs setEntities now updates component if component exists #407
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughThis pull request adds a new changeset file documenting patch updates for various Dojo Engine packages and updates the component management logic in the Changes
Sequence Diagram(s)sequenceDiagram
participant E as Entity
participant S as setEntities
participant H as hasComponent
participant G as getComponentValue
participant U as updateComponent
participant C as setComponent
participant L as Logger
E->>S: Invoke setEntities(entities)
loop For each entity and componentName
S->>H: Check if component exists
alt Component exists
S->>G: Get current component value
S->>U: Update component with current value
S->>L: Log update details
else Component does not exist
S->>C: Set component for entity
end
end
Possibly related PRs
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms (2)
🔇 Additional comments (3)
✨ Finishing Touches
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
.changeset/chatty-kings-nail.md
(1 hunks)packages/state/src/recs/index.ts
(3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: build
- GitHub Check: check
🔇 Additional comments (3)
.changeset/chatty-kings-nail.md (1)
1-17
: LGTM! Clear and concise changeset entry.The changeset correctly documents that this is a patch update across multiple packages, with a clear description of the primary fix: "
setEntities
now updates component if component exists". This aligns with the code changes in the implementation file.packages/state/src/recs/index.ts (2)
5-10
: Good addition of required imports.You've correctly imported the necessary functions (
getComponentValue
,hasComponent
, andupdateComponent
) from the recs package that are used in the updated implementation ofsetEntities
.
411-416
: Improved variable declaration using const.Using
const
instead oflet
for loop variables is a good practice when the variables aren't being reassigned within the loop body.
packages/state/src/recs/index.ts
Outdated
if (hasComponent(recsComponent, key as Entity)) { | ||
updateComponent( | ||
recsComponent, | ||
key as Entity, | ||
convertedValue as Partial<ComponentValue>, | ||
getComponentValue(recsComponent, key as Entity) | ||
); | ||
if (logging) | ||
console.log( | ||
`Update component ${recsComponent.metadata?.name} on ${key}` | ||
); | ||
return; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix early return issue in component update logic.
The implementation correctly checks if a component exists and updates it instead of replacing it, which aligns with the PR's purpose. However, there's a critical issue: the return
statement on line 462 will exit the entire function after processing only the first component that needs an update, preventing other components and entities from being processed.
Apply this diff to fix the issue:
if (hasComponent(recsComponent, key as Entity)) {
updateComponent(
recsComponent,
key as Entity,
convertedValue as Partial<ComponentValue>,
getComponentValue(recsComponent, key as Entity)
);
if (logging)
console.log(
`Update component ${recsComponent.metadata?.name} on ${key}`
);
- return;
+ continue;
}
The continue
statement will skip to the next iteration rather than exiting the function completely.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
if (hasComponent(recsComponent, key as Entity)) { | |
updateComponent( | |
recsComponent, | |
key as Entity, | |
convertedValue as Partial<ComponentValue>, | |
getComponentValue(recsComponent, key as Entity) | |
); | |
if (logging) | |
console.log( | |
`Update component ${recsComponent.metadata?.name} on ${key}` | |
); | |
return; | |
} | |
if (hasComponent(recsComponent, key as Entity)) { | |
updateComponent( | |
recsComponent, | |
key as Entity, | |
convertedValue as Partial<ComponentValue>, | |
getComponentValue(recsComponent, key as Entity) | |
); | |
if (logging) | |
console.log( | |
`Update component ${recsComponent.metadata?.name} on ${key}` | |
); | |
continue; | |
} |
f003e04
to
d8a9b0d
Compare
Closes #
Introduced changes
Checklist
Summary by CodeRabbit
Chores
Bug Fixes
New Features
getComponentValue
,hasComponent
, andupdateComponent
.