Skip to content
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

fix: type build #307

Merged
merged 2 commits into from
Oct 24, 2024
Merged

fix: type build #307

merged 2 commits into from
Oct 24, 2024

Conversation

ponderingdemocritus
Copy link
Contributor

@ponderingdemocritus ponderingdemocritus commented Oct 24, 2024

  • fixes build error

Summary by CodeRabbit

  • New Features

    • The BurnerProviderProps interface is now publicly accessible for use in other modules.
    • Enhanced entity subscription in the app to include player positions alongside movement capabilities.
  • Bug Fixes

    • Simplified movement logic, removing unnecessary boundary checks for movement actions.
  • Documentation

    • Updated the world address in the "Running The Examples" section of the README to ensure correct connectivity to the Dojo environment.

Copy link

coderabbitai bot commented Oct 24, 2024

Walkthrough

The changes in this pull request involve modifications to several files. The BurnerProviderProps interface in the burnerProvider.tsx file has been made publicly accessible by adding the export keyword. The readme.md file has been updated to reflect a new world address for the Torii indexer command in the "Running The Examples" section. Additionally, enhancements have been made to the App component's entity subscription logic, and the updateEntity method in the zustand.ts file has been refined for better entity management.

Changes

File Path Change Summary
packages/create-burner/src/context/burnerProvider.tsx Added export keyword to BurnerProviderProps interface, making it publicly accessible.
readme.md Updated world address for the Torii indexer command in the "Running The Examples" section.
examples/example-vite-react-sdk/src/App.tsx Enhanced entity subscription by adding Position entity and simplified movement logic.
packages/sdk/src/state/zustand.ts Updated updateEntity method for better entity merging and type safety in GameState interface.

Possibly related PRs

  • feat: subscription clauses #235: The changes in packages/state/src/recs/index.ts involve modifications to entity synchronization functions, which may relate to the public accessibility of the BurnerProviderProps interface in the main PR, as both involve managing entities and their properties.
  • fix: types #304: The updates to the getEntities function in packages/sdk/src/getEntities.ts include a new required parameter and adjustments to how entities are fetched, which could connect to the changes in the BurnerProviderProps interface by enhancing the overall entity management system.
  • fix: tests, improvements #302: The modifications in packages/state/src/recs/index.ts regarding the handling of entity synchronization and logging improvements may relate to the changes in the main PR, as both involve enhancing the management of entities within the application.
  • fix: recs tests #301: The changes in the test suite for the convertValues function may indirectly relate to the main PR's focus on entity management, as both involve ensuring the integrity and functionality of entity-related operations.
  • feat: optimistic example #293: The addition of an optimistic example in examples/example-vite-react-sdk/src/App.tsx may relate to the main PR's changes to the BurnerProviderProps interface, as both involve enhancing user interactions with entities in the application.

Poem

In the garden where code does bloom,
A provider's props now have room.
With a new address, the examples run,
Hopping through changes, oh what fun!
Let's celebrate with a joyful cheer,
For every update brings us near! 🐇✨


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?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a 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

🧹 Outside diff range and nitpick comments (2)
examples/example-vite-react-sdk/src/App.tsx (1)

69-70: Consider removing or conditionally enabling debug logging.

While the entity update logic is good, consider removing the console.log or making it conditional based on a debug flag.

-console.log("subscribed", response.data[0]);
+if (process.env.NODE_ENV === 'development') {
+  console.log("subscribed", response.data[0]);
+}
packages/sdk/src/state/zustand.ts (1)

93-95: Avoid using any in type assertions

Using as any at line 95 bypasses TypeScript's type checking and may introduce bugs. Consider defining a more specific type instead of using any.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 4820410 and 2b25408.

📒 Files selected for processing (2)
  • examples/example-vite-react-sdk/src/App.tsx (3 hunks)
  • packages/sdk/src/state/zustand.ts (1 hunks)
🔇 Additional comments (3)
examples/example-vite-react-sdk/src/App.tsx (2)

46-56: LGTM: Well-structured Position entity subscription.

The Position entity subscription follows the established query pattern and properly handles address padding.


227-230: Verify server-side movement validation.

The client-side boundary checks have been removed. Please verify that proper server-side validation exists to prevent invalid movements.

packages/sdk/src/state/zustand.ts (1)

77-78: ⚠️ Potential issue

Handle updates when entity.models is not provided

Currently, the updateEntity function only updates the entity if entity.models is present. This means updates to other properties of the entity will be ignored if entity.models is undefined. Consider adjusting the condition to allow updates even when entity.models is not provided.

Apply this diff to modify the condition:

- if (entity.entityId && state.entities[entity.entityId] && entity.models) {
+ if (entity.entityId && state.entities[entity.entityId]) {

Likely invalid or redundant comment.

Comment on lines +84 to +107
const mergedModels: typeof existingEntity.models =
Object.assign({}, existingEntity.models);

// Iterate through each namespace in the new models
Object.entries(entity.models).forEach(
([namespace, namespaceModels]) => {
const typedNamespace =
namespace as keyof ParsedEntity<T>["models"];
if (!(typedNamespace in mergedModels)) {
mergedModels[
typedNamespace as keyof typeof mergedModels
] = {} as any;
}

mergedModels[
typedNamespace as keyof typeof mergedModels
] = Object.assign(
{},
mergedModels[
typedNamespace as keyof typeof mergedModels
],
namespaceModels
);
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Simplify the models merging logic for readability

The current implementation for merging models is complex and may be difficult to maintain. Consider simplifying the code using a utility function or a recursive merge to enhance readability.

For example, you could use a deep merge utility:

- // Existing models merging code
- const mergedModels: typeof existingEntity.models = Object.assign({}, existingEntity.models);
- Object.entries(entity.models).forEach(([namespace, namespaceModels]) => {
-   const typedNamespace = namespace as keyof ParsedEntity<T>["models"];
-   if (!(typedNamespace in mergedModels)) {
-     mergedModels[typedNamespace as keyof typeof mergedModels] = {} as any;
-   }
-   mergedModels[typedNamespace as keyof typeof mergedModels] = Object.assign(
-     {},
-     mergedModels[typedNamespace as keyof typeof mergedModels],
-     namespaceModels
-   );
- });
+ const mergedModels = { ...existingEntity.models, ...entity.models };

If a deep merge is required to merge nested objects, you can implement a helper function like this:

function deepMerge(target: any, source: any): any {
  for (const key of Object.keys(source)) {
    if (
      source[key] instanceof Object &&
      key in target &&
      target[key] instanceof Object
    ) {
      Object.assign(source[key], deepMerge(target[key], source[key]));
    }
  }
  return { ...target, ...source };
}

And then use it in your code:

const mergedModels = deepMerge(existingEntity.models, entity.models);

@ponderingdemocritus ponderingdemocritus merged commit 87afb34 into main Oct 24, 2024
3 checks passed
@ponderingdemocritus ponderingdemocritus deleted the burner-props branch October 24, 2024 06:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant