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

feat(canvas): add the renderer extension capability #718

Merged
merged 6 commits into from
Sep 9, 2024

Conversation

hexqi
Copy link
Collaborator

@hexqi hexqi commented Jul 30, 2024

English | 简体中文

PR

PR Checklist

Please check if your PR fulfills the following requirements:

  • The commit message follows our Commit Message Guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)
  • Built its own designer, fully self-validated

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

Background and solution

特性

  • 画布create增加lifeCycles配置,添加beforeAppCreate与appCreated钩子
  • 画布添加getRender/setRender API

What is the current behavior?

Issue Number: N/A

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Introduced conditional rendering for the SaveNewBlock component based on block presence.
    • Added a new function, addMaterials, for batch operations on materials.
    • Enhanced rendering logic with new functions for customization and lifecycle management.
  • Bug Fixes

    • Improved error handling in the ProgressBar component to prevent runtime errors when retrieving getEditBlock.

Copy link
Contributor

coderabbitai bot commented Jul 30, 2024

Warning

Rate limit exceeded

@hexqi has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 18 minutes and 40 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

Commits

Files that changed from the base of the PR and between b726107 and f396562.

Walkthrough

The recent changes encompass updates to several components and modules, enhancing functionality and control flow. Key modifications include conditional rendering in the CanvasMenu.vue, improved computed getter processing in RenderMain.js, lifecycle management in runner.js, robustness in ProgressBar.vue, and the addition of a new function for batch material handling in useMaterial.js. These adjustments collectively aim to improve the application's responsiveness and maintainability.

Changes

Files Change Summary
packages/canvas/container/src/components/CanvasMenu.vue Conditional rendering of SaveNewBlock based on hasBlock property, which is now reactive and derived from getMetaApi(META_SERVICE.Block).
packages/canvas/render/src/RenderMain.js Replaced dynamic getter evaluation with parseData, introduced defaultRenderer, getRenderer, setRenderer, and setRendererMounted for enhanced rendering logic.
packages/canvas/render/src/runner.js Updated create function to be asynchronous, allowing lifecycle hooks for beforeAppCreate and appCreated to be executed during the rendering process.
packages/common/component/ProgressBar.vue Safeguarded retrieval of getEditBlock from getMetaApi, preventing runtime errors by checking for truthiness before destructuring.
packages/plugins/materials/src/composable/useMaterial.js Introduced addMaterials function for batch addition of materials, expanding the module's capabilities without altering existing functions.

Possibly related PRs

Suggested labels

ospp-2024

Poem

🐰 In the meadow, changes bloom,
With menus that now find more room.
Blocks appear with a gentle grace,
As materials dance in their place.
A rabbit hops with joy so bright,
Celebrating code in morning light! 🌼


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 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.

@hexqi hexqi marked this pull request as ready for review September 3, 2024 07:52
@github-actions github-actions bot added the refactor-main refactor/develop branch feature label Sep 3, 2024
Copy link
Contributor

@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 3b20b8b and 92e6c30.

Files selected for processing (5)
  • packages/canvas/container/src/components/CanvasMenu.vue (2 hunks)
  • packages/canvas/render/src/RenderMain.js (5 hunks)
  • packages/canvas/render/src/runner.js (3 hunks)
  • packages/common/component/ProgressBar.vue (1 hunks)
  • packages/plugins/materials/src/composable/useMaterial.js (1 hunks)
Additional context used
Biome
packages/canvas/render/src/runner.js

[error] 131-133: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

Additional comments not posted (13)
packages/common/component/ProgressBar.vue (1)

24-25: LGTM!

The code changes enhance the robustness of the component by introducing a safeguard to handle the case when getMetaApi returns null or undefined. This prevents potential runtime errors that could occur if getEditBlock were called when it is not defined.

packages/canvas/render/src/runner.js (3)

112-112: LGTM!

The changes to the create function signature are approved:

  • Making the function async allows using await and returning a promise, enabling asynchronous operations.
  • Accepting a config parameter allows passing configuration options to the function, such as lifecycle hooks.

113-116: LGTM!

The addition of the beforeAppCreate lifecycle hook is approved:

  • It allows executing custom logic before the application is unmounted and recreated.
  • Invoking it with Vue, canvasWin, and api provides access to necessary dependencies and APIs.
  • Awaiting its completion ensures that any asynchronous operations are completed before proceeding.

130-132: LGTM!

The addition of the appCreated lifecycle hook is approved:

  • It allows executing custom logic after the application is created and mounted.
  • Invoking it with the App instance provides access to the application instance for customization.
  • Awaiting its completion ensures that any asynchronous operations are completed before proceeding.

The static analysis suggestion to use an optional chain is a false positive because the code already checks if appCreated is a function before invoking it.

packages/canvas/container/src/components/CanvasMenu.vue (3)

30-30: LGTM!

The conditional rendering of the SaveNewBlock component based on the hasBlock property is a good practice.


230-230: LGTM!

The hasBlock property is correctly defined using getMetaApi(META_SERVICE.Block) and used to conditionally render the SaveNewBlock component.


37-37: Verify the usage of the imported entities getMetaApi and META_SERVICE.

The imported entities are not used in the provided code segment. Ensure that they are used correctly to determine the hasBlock property.

Run the following script to verify the usage:

Verification successful

Verified Usage of getMetaApi and META_SERVICE

The imported entities getMetaApi and META_SERVICE are correctly used in the CanvasMenu.vue file to determine the hasBlock property. The usage aligns with the expected functionality. No issues found.

  • packages/canvas/container/src/components/CanvasMenu.vue: hasBlock: getMetaApi(META_SERVICE.Block)
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `getMetaApi` and `META_SERVICE` in the component.

# Test: Search for the usage of `getMetaApi`. Expect: Usage in the `setup` function.
rg --type vue $'getMetaApi' -g '!node_modules'

# Test: Search for the usage of `META_SERVICE`. Expect: Usage in the `setup` function.
rg --type vue $'META_SERVICE' -g '!node_modules'

Length of output: 149


Script:

#!/bin/bash
# Description: Verify the usage of `getMetaApi` and `META_SERVICE` in the component.

# Test: Search for the usage of `getMetaApi` across all files.
rg 'getMetaApi' -g '!node_modules'

# Test: Search for the usage of `META_SERVICE` across all files.
rg 'META_SERVICE' -g '!node_modules'

Length of output: 5605

packages/plugins/materials/src/composable/useMaterial.js (1)

Line range hint 354-362: LGTM!

The addMaterials function is well-implemented and follows a clear logic flow. It correctly handles the addition of components, snippets, and blocks to the respective state variables. The function ensures that there is at least one group in materialState.blocks to add the blocks to and properly handles the asynchronous nature of registerBlock using Promise.allSettled.

The code changes are approved.

packages/canvas/render/src/RenderMain.js (5)

18-18: LGTM!

The code change is approved.


46-47: LGTM!

The code change is approved. Using parseData instead of dynamically evaluating the getter expression using Function constructor enhances the clarity and safety of the code.


346-380: LGTM!

The code changes are approved. The new functions related to rendering provide flexibility in customizing the rendering behavior and enhance the component's extensibility. The changes are well-structured and follow the existing coding style and conventions.


413-413: LGTM!

The code change is approved. Using the getRenderer function to get the rendering function is consistent with the introduction of the new rendering-related functions.


443-448: LGTM!

The code changes are approved. The api object is correctly updated to include the new rendering-related functions, making them available for use in other parts of the application.

Copy link
Contributor

@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 92e6c30 and 81149be.

Files selected for processing (3)
  • packages/canvas/render/src/RenderMain.js (5 hunks)
  • packages/canvas/render/src/runner.js (4 hunks)
  • packages/plugins/materials/src/composable/useMaterial.js (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • packages/plugins/materials/src/composable/useMaterial.js
Additional comments not posted (10)
packages/canvas/render/src/runner.js (4)

49-50: LGTM!

The code changes are approved. The create function is updated to be asynchronous and accept a config parameter containing lifecycle hooks, which enhances the flexibility and control over the application lifecycle.


51-53: LGTM!

The code changes are approved. The beforeAppCreate lifecycle hook is invoked with the necessary dependencies, allowing custom logic to be executed before the application is unmounted and recreated.


67-70: LGTM!

The code changes are approved. The appCreated lifecycle hook is invoked with the newly created App instance, allowing custom logic to be executed after the application is created and mounted.


90-90: LGTM!

The code changes are approved. The create function invocation is updated to pass the config parameter, ensuring that the lifecycle hooks are utilized during the rendering process.

packages/canvas/render/src/RenderMain.js (6)

20-29: LGTM!

The code changes are approved.


57-57: LGTM!

The code changes are approved. Replacing the dynamic Function constructor with a call to parseData enhances code clarity and safety.


357-377: LGTM!

The code changes are approved. The defaultRenderer function improves consistency in rendering behavior by ensuring the canvas includes a root node.


379-383: LGTM!

The code changes are approved. The getRenderer and setRenderer functions enhance the component's extensibility by allowing users to customize rendering behavior dynamically.


385-391: LGTM!

The code changes are approved. The getRendererMounted and setRendererMounted functions further enhance the component's extensibility by allowing users to set custom mounted callbacks.


424-424: LGTM!

The code changes are approved. Modifying the render function to call the renderer returned by getRenderer() aligns with the new functionality introduced in the file.

Copy link
Contributor

@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: 2

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 81149be and 3a3029f.

Files selected for processing (2)
  • packages/canvas/render/src/RenderMain.js (5 hunks)
  • packages/canvas/render/src/runner.js (4 hunks)
Files skipped from review as they are similar to previous changes (1)
  • packages/canvas/render/src/runner.js
Additional comments not posted (2)
packages/canvas/render/src/RenderMain.js (2)

57-57: Security Improvement: Use of parseData in Computed Getters

Replacing dynamic function evaluation with parseData enhances security by avoiding eval-like behavior and improves code maintainability.


446-449: Export Section Updates

The export section has been appropriately updated to include new functions like getRenderer, setRenderer, and others, making them accessible throughout the application.

packages/canvas/render/src/RenderMain.js Show resolved Hide resolved
packages/canvas/render/src/RenderMain.js Show resolved Hide resolved
yy-wow
yy-wow previously approved these changes Sep 6, 2024
Copy link
Collaborator

@yy-wow yy-wow left a comment

Choose a reason for hiding this comment

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

LGTM

chilingling
chilingling previously approved these changes Sep 9, 2024
@hexqi hexqi dismissed stale reviews from chilingling and yy-wow via b726107 September 9, 2024 07:38
Copy link
Contributor

@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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 3a3029f and b726107.

Files selected for processing (2)
  • packages/canvas/render/src/RenderMain.js (5 hunks)
  • packages/canvas/render/src/runner.js (4 hunks)
Files skipped from review as they are similar to previous changes (1)
  • packages/canvas/render/src/runner.js
Additional comments not posted (4)
packages/canvas/render/src/RenderMain.js (4)

48-48: Refactor to enhance clarity and maintainability.

The refactoring of computed getters to use parseData instead of a dynamic Function constructor is a significant improvement in terms of security and maintainability. This change avoids the risks associated with eval-like behavior.


348-368: Review the implementation of defaultRenderer.

The defaultRenderer function is well-implemented, ensuring that the canvas rendering includes a root node. This alignment with code generation and previewing is crucial for consistency. The use of Vue's h function to create a virtual DOM is appropriate and follows Vue best practices.


437-440: Review the updated export structure.

The export section now includes several new functions (setNode, getRenderer, setRenderer, getRendererMounted, and setRendererMounted). This change enhances the module's extensibility by making these functions available for use in other parts of the application.


407-407: Verify the rendering function invocation.

The render method correctly invokes the renderer obtained from getRenderer. This ensures that the correct rendering logic is used based on the current configuration. It is important to verify that this method handles all edge cases and maintains the component's reactivity.

packages/canvas/render/src/RenderMain.js Show resolved Hide resolved
hexqi and others added 5 commits September 9, 2024 15:44
* feat: unibuy-render

* fix:eslint报错
* feat: unibuy-render

* fix:eslint报错

* fix:增加导出钩子函数
* feat: unibuy-render

* fix:eslint报错

* fix:增加导出钩子函数

* fix:getters处理优化
@chilingling chilingling merged commit 2a5f346 into opentiny:refactor/develop Sep 9, 2024
1 check passed
@hexqi hexqi deleted the adapt-to-unibuy branch September 9, 2024 08:00
This was referenced Sep 9, 2024
yy-wow pushed a commit to yy-wow/tiny-engine that referenced this pull request Oct 10, 2024
特性
画布create增加lifeCycles配置,添加beforeAppCreate与appCreated钩子
画布添加getRender/setRender API

---------

Co-authored-by: yaoyun8 <[email protected]>
@coderabbitai coderabbitai bot mentioned this pull request Oct 10, 2024
14 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactor-main refactor/develop branch feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants