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: create store type differenciation #390

Merged
merged 1 commit into from
Feb 6, 2025
Merged

Conversation

MartianGreed
Copy link
Collaborator

@MartianGreed MartianGreed commented Feb 6, 2025

Closes #

Introduced changes

Checklist

  • Linked relevant issue
  • Updated relevant documentation
  • Added relevant tests
  • Add a dedicated CI job for new examples
  • Performed self-review of the code

Summary by CodeRabbit

  • Refactor
    • Enhanced type handling for the Zustand store, improving type safety and clarity.
    • Updated the createStore function to support both vanilla and React store implementations.
  • Chores
    • Updated multiple Dojo Engine packages for improved functionality and performance.

Copy link

coderabbitai bot commented Feb 6, 2025

Walkthrough

This pull request refines the Zustand store's type handling by introducing new imports from the "zustand" library and adjusting type assertions. The createDojoStore function in hooks.ts now explicitly returns a UseBoundStore<StoreApi<GameState<T>>>, which provides enhanced type safety for game state management. Additionally, zustand.ts receives an import for UseBoundStore. The underlying logic and functionality remain unchanged.

Changes

Files Change Details
packages/sdk/src/react/hooks.ts, packages/sdk/src/state/zustand.ts - Added imports for StoreApi and UseBoundStore from "zustand".
- Updated createDojoStore in hooks.ts to return UseBoundStore<StoreApi<GameState<T>>>.
.changeset/friendly-emus-beam.md - Multiple package updates for Dojo Engine packages.
- Fixed createStore function to support both vanilla and React store implementations.

Possibly related PRs

  • fix: Dojo store add entity #349: The changes in the main PR enhance type handling in the createDojoStore function, while the retrieved PR modifies the updateEntity method in the Zustand store, indicating that they are related through their involvement with the Zustand store's functionality.
  • feat: draft zustand state management system #280: The changes in the main PR enhance type handling for the Zustand store, specifically modifying the createDojoStore function, while the retrieved PR introduces a new Zustand store implementation that includes the createDojoStore function, indicating a direct relationship between the two.
  • fix: createDojoStore now have proper type #385: The changes in the main PR enhance type handling for the createDojoStore function, while the retrieved PR focuses on ensuring that the createDojoStore function has the correct type, indicating a direct relationship between the two.

Poem

I'm a rabbit hopping through the code,
With types so clear on every node,
Imports fresh and functions bright,
Leaping through logic with pure delight,
In fields of store and state I roam – oh, what a sight!
🐰✨

Tip

🌐 Web search-backed reviews and chat
  • We have enabled web search-based reviews and chat for all users. This feature allows CodeRabbit to access the latest documentation and information on the web.
  • You can disable this feature by setting web_search: false in the knowledge_base settings.
  • Please share any feedback in the Discord discussion.

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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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: 0

🧹 Nitpick comments (1)
packages/sdk/src/react/hooks.ts (1)

16-16: Consider improving the comment and tracking the technical debt.

The comment "hacktually" suggests this is a temporary solution. Consider:

  1. Using a more professional comment style
  2. Creating a TODO with more context about the proper solution
  3. Opening a follow-up issue to track this technical debt
-    // hacktually until I find a proper type input to createDojoStoreFactory
+    // TODO: Implement proper type input for createDojoStoreFactory
+    // This is a temporary type assertion until we can implement proper generic constraints
+    // Follow-up issue: <issue_url>
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 81b8de8 and e6406f2.

📒 Files selected for processing (2)
  • packages/sdk/src/react/hooks.ts (2 hunks)
  • packages/sdk/src/state/zustand.ts (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • packages/sdk/src/state/zustand.ts
🔇 Additional comments (2)
packages/sdk/src/react/hooks.ts (2)

5-5: LGTM! Import changes align with type differentiation goals.

The added imports for StoreApi, UseBoundStore, and GameState provide the necessary type definitions for improved store type handling.

Also applies to: 7-7


17-19: Verify type compatibility between createDojoStoreFactory and UseBoundStore.

While the type assertion improves type safety for consumers, using unknown could hide potential type incompatibilities. Please verify that the actual return type of createDojoStoreFactory is compatible with UseBoundStore<StoreApi<GameState<T>>>.

✅ Verification successful

🏁 Script executed:

#!/bin/bash
# Search for createDojoStoreFactory implementation and its return type
ast-grep --pattern 'export function createDojoStoreFactory<$_>($_) {
  $$$
}'

Length of output: 12807


I'll now gather additional context on the underlying type of the storeCreatorFn parameter (i.e. CreateStore) to confirm that its return type matches the expected UseBoundStore<StoreApi<GameState<T>>>. We'll search for its definition within the repository.


🏁 Script executed:

#!/bin/bash
# Search for the definition of CreateStore type in the repository
rg "type CreateStore" -n .

Length of output: 88


I'll gather additional context for the CreateStore type and UseBoundStore definition to confirm type compatibility. Let's examine the surrounding lines of the CreateStore definition.


🏁 Script executed:

#!/bin/bash
# Display the context around the CreateStore definition.
sed -n '1,50p' packages/sdk/src/state/zustand.ts

Length of output: 1973


Type compatibility between createDojoStoreFactory and UseBoundStore is valid.

  • The function receives a store creator (i.e. Zustand's create) and calls it with the appropriate initializer.
  • The custom CreateStore type specifies a return of StoreApi<T>, but Zustand’s actual create returns a store hook that augments this with a call signature (i.e. a UseBoundStore<StoreApi<T>>).
  • Casting via as unknown as UseBoundStore<StoreApi<GameState<T>>> safely converts the narrower declared type into the actual type returned by Zustand’s create.
  • In short, provided that the underlying create follows Zustand’s implementation, the asserted type is compatible with the returned value.

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: 0

🧹 Nitpick comments (1)
.changeset/friendly-emus-beam.md (1)

16-17: Improve Commit Message Grammar

The commit message currently reads "fix: createStore now fit to either vanilla or react store". To ensure proper subject–verb agreement, consider changing "fit" to "fits". This small improvement enhances clarity and professionalism.

Suggested diff:

- fix: createStore now fit to either vanilla or react store
+ fix: createStore now fits to either vanilla or react store
🧰 Tools
🪛 LanguageTool

[uncategorized] ~16-~16: This verb does not appear to agree with the subject. Consider using a different form.
Context: ...-wasm": patch --- fix: createStore now fit to either vanilla or react store

(AI_EN_LECTOR_REPLACEMENT_VERB_AGREEMENT)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e6406f2 and 395e450.

📒 Files selected for processing (3)
  • .changeset/friendly-emus-beam.md (1 hunks)
  • packages/sdk/src/react/hooks.ts (2 hunks)
  • packages/sdk/src/state/zustand.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/sdk/src/state/zustand.ts
  • packages/sdk/src/react/hooks.ts
🧰 Additional context used
🪛 LanguageTool
.changeset/friendly-emus-beam.md

[uncategorized] ~16-~16: This verb does not appear to agree with the subject. Consider using a different form.
Context: ...-wasm": patch --- fix: createStore now fit to either vanilla or react store

(AI_EN_LECTOR_REPLACEMENT_VERB_AGREEMENT)

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: check
  • GitHub Check: build
🔇 Additional comments (1)
.changeset/friendly-emus-beam.md (1)

1-14: Approved Dependency Patch Updates

The list of dependency updates is clear and correctly formatted for patch level changes. Ensure that any related documentation or changelog entries are updated accordingly.

@MartianGreed MartianGreed merged commit 1a3eeef into main Feb 6, 2025
6 checks passed
@MartianGreed MartianGreed deleted the fix/create-store branch February 6, 2025 15:00
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