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

Support parameter passing in component constructor #2158

Merged
merged 3 commits into from
Jul 3, 2024

Conversation

cptbtptpbcptdtptp
Copy link
Collaborator

@cptbtptpbcptdtptp cptbtptpbcptdtptp commented Jul 2, 2024

You can:

class TestA extends Script {
    constructor(entity:Entity, a: number) {
        super(entity);
    }
}

entity.addComponent(TestA, 1);

image

Summary by CodeRabbit

  • New Features
    • Enhanced the addComponent method in the Entity class for improved flexibility in component creation.
    • Updated the addFeature method in the XRManagerExtended class to return more specific instance types, enhancing type safety and usability.

Copy link

coderabbitai bot commented Jul 2, 2024

Walkthrough

The recent updates enhance the flexibility of component creation within the Entity and XRManagerExtended classes. The addComponent method in the Entity class now supports additional arguments for component instantiation, allowing more dynamic and flexible component creation. Similarly, the addFeature method in XRManagerExtended now returns a more specific instance type, improving type safety and clarity.

Changes

File Change Summary
packages/core/src/Entity.ts Updated the addComponent method to accept additional arguments for component instantiation, enhancing flexibility in component creation.
packages/xr/src/XRManagerExtended.ts Updated the addFeature method to return InstanceType<T> instead of XRFeature, improving type safety and specificity.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Entity
    participant Component
    User->>Entity: addComponent(ComponentType, ...args)
    Entity->>Component: new ComponentType(Entity, ...args)
    Component-->>Entity: Component instance
    Entity-->>User: Component instance
Loading
sequenceDiagram
    participant User
    participant XRManagerExtended
    participant XRFeature
    User->>XRManagerExtended: addFeature(FeatureType)
    XRManagerExtended->>XRFeature: new FeatureType()
    XRFeature-->>XRManagerExtended: Feature instance
    XRManagerExtended-->>User: Feature instance
Loading

Poem

In the land of Entity and XR's domain,
Flexibility and type safety reign.
Components tailored, features bright,
Each line of code now feels just right.
With every method clear and true,
Here's to the changes—cheers from me to you! 🐰✨

Tip

AI model upgrade

gpt-4o model for reviews and chat is now live

OpenAI claims that this model is better at understanding and generating code than the previous models. Please join our Discord Community to provide any feedback or to report any issues.


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 5669ab9 and 54349aa.

Files selected for processing (1)
  • packages/core/src/Entity.ts (2 hunks)
Additional comments not posted (2)
packages/core/src/Entity.ts (2)

758-763: LGTM!

The new type alias ComponentArguments is correctly implemented.


208-213: LGTM! But verify the function usage in the codebase.

The code changes are approved.

However, ensure that all function calls to addComponent match the new signature.

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 54349aa and 6545e23.

Files selected for processing (1)
  • packages/core/src/Entity.ts (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • packages/core/src/Entity.ts

@GuoLei1990 GuoLei1990 added the enhancement New feature or request label Jul 3, 2024
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

Outside diff range and nitpick comments (1)
packages/xr/src/XRManagerExtended.ts (1)

Line range hint 82-89: Fix the logical error in the loop condition.

The loop condition should use i++ instead of i-- to iterate correctly.

-  for (let i = 0, n = features.length; i < n; i--) {
+  for (let i = 0, n = features.length; i < n; i++) {
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 6545e23 and 5e47911.

Files selected for processing (1)
  • packages/xr/src/XRManagerExtended.ts (2 hunks)
Additional comments not posted (3)
packages/xr/src/XRManagerExtended.ts (3)

Line range hint 78-78: LGTM!

The code is consistent with the changes made in addFeature.


Line range hint 94-94: LGTM!

The code is consistent with the changes made in addFeature.


62-63: LGTM! But verify the function usage in the codebase.

The code changes are approved.

However, ensure that all function calls to addFeature match the new signature.

Verification successful

No additional calls to addFeature found.

The search indicates that there are no other usages of the addFeature function in the codebase outside of its definition and override in XRManagerExtended.ts. Therefore, the function signature change does not impact other parts of the codebase.

  • packages/xr/src/XRManagerExtended.ts: lines 62-63
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify all function calls to `addFeature` match the new signature.

# Test: Search for the function usage. Expect: Only occurances of the new signature.
rg --type typescript $'addFeature'

Length of output: 68



Script:

#!/bin/bash
# Description: Verify all function calls to `addFeature` match the new signature.

# Test: Search for the function usage. Expect: Only occurrences of the new signature.
rg --type-add 'ts:*.ts' --type-add 'tsx:*.tsx' 'addFeature'

Length of output: 322



Script:

#!/bin/bash
# Description: Verify all function calls to `addFeature` match the new signature.

# Test: Search for the function usage in both TypeScript and JavaScript files. Expect: Only occurrences of the new signature.
rg --type-add 'ts:*.ts' --type-add 'tsx:*.tsx' --type-add 'js:*.js' --type-add 'jsx:*.jsx' 'addFeature'

Length of output: 366

@GuoLei1990 GuoLei1990 merged commit ae79e6c into galacean:main Jul 3, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants