fix: 优化全局状态处理和资源加载逻辑
- 重构 global-state.ts 中的状态处理,支持数组和对象类型的状态计算
- 修改 VariableConfigurator.vue 中的变量加载方式
- 更新 useResource 中的应用状态获取逻辑,兼容 mock、java 两种方式
English | 简体中文
PR
PR Checklist
Please check if your PR fulfills the following requirements:
- [x] The commit message follows our Commit Message Guidelines
- [x] Tests for the changes have been added (for bug fixes / features)
- [ ] Docs have been added / updated (for bug fixes / features)
- [x] Built its own designer, fully self-validated
PR Type
What kind of change does this PR introduce?
- [x] 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
What is the current behavior?
Issue Number: N/A
What is the new behavior?
Does this PR introduce a breaking change?
- [ ] Yes
- [x] No
Other information
Summary by CodeRabbit
- Refactor
- Enhanced state management with improved error handling for different data formats.
- Streamlined variable configuration for a more direct mapping of store identifiers.
- Updated metadata processing with flexible fallbacks to ensure consistent application behavior.
Walkthrough
This pull request refines state management across multiple components. In the global state module, the useGlobalState function now discriminates between array and object states while using try–catch for executing getter functions. The variable configurator component has been simplified to directly assign store identifiers, removing the previously used helper function and loops. Additionally, the fetchAppState function in the resource module now employs fallback logic for assigning metadata properties using both camelCase and snake_case naming. No modifications to public entity declarations were made.
Changes
| File(s) | Change Summary |
|---|---|
packages/canvas/…/global-state.tspackages/plugins/materials/…/useResource.js |
Updated state management logic. In useGlobalState, state is checked for array vs. object structure with getter functions executed safely using try–catch. In fetchAppState, fallback assignments ensure both camelCase and snake_case metadata properties are correctly handled. |
packages/configurator/…/VariableConfigurator.vue |
Simplified variable population by directly assigning store IDs, removing the previous helper function and loops used to bind properties. |
Sequence Diagram(s)
sequenceDiagram
participant Caller as Caller
participant GS as useGlobalState Function
Caller->>GS: Invoke useGlobalState(state, getters)
GS->>GS: Check if state is an array
alt State is array
GS->>GS: If no getters, copy state directly
alt Getters exist
GS->>GS: Iterate over getter keys with try–catch
GS->>GS: Build arrayWithGetters
end
GS->>GS: Assign result to stores[id]
else
GS->>GS: Check if state is a valid object
alt Valid Object
GS->>GS: If no getters, merge state directly
alt Getters exist
GS->>GS: Compute getters with try–catch and merge with state
end
else
GS->>GS: Assign state directly to stores[id]
end
end
GS-->>Caller: Return updated store
sequenceDiagram
participant F as fetchAppState Function
participant Schema as appSchemaState Object
F->>F: Retrieve appData.meta
alt Using camelCase for isDemo
F->>Schema: Set isDemo from appData.meta.isDemo
else
F->>Schema: Set isDemo from appData.meta.is_demo
end
alt Using camelCase for globalState
F->>Schema: Set globalState from appData.meta.globalState
else
F->>Schema: Set globalState from appData.meta.global_state
end
Possibly related PRs
- opentiny/tiny-engine#930: Modifications in the
watchEffectfunction for computed getters relate directly to these state management adjustments.
Suggested labels
bug, refactor-main
Suggested reviewers
- hexqi
- chilingling
- rhlin
Poem
I'm a little rabbit, hopping with a grin,
Through lines of code, where changes now begin.
State and getters, all in neat array,
Errors caught gently along the way.
Happy hops and clean commits lift our day!
🐇💻
[!WARNING] There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.
🔧 ESLint
If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.
packages/canvas/render/src/application-function/global-state.ts
Oops! Something went wrong! :(
ESLint: 8.57.1
ESLint couldn't find the plugin "@typescript-eslint/eslint-plugin".
(The package "@typescript-eslint/eslint-plugin" was not found when loaded as a Node module from the directory "/packages/canvas".)
It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:
npm install @typescript-eslint/eslint-plugin@latest --save-devThe plugin "@typescript-eslint/eslint-plugin" was referenced from the config file in "packages/canvas/.eslintrc.cjs » @vue/eslint-config-typescript".
If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.
✨ Finishing Touches
- [ ] 📝 Generate Docstrings
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
🪧 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
@coderabbitaiin 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
@coderabbitaiin 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 pauseto pause the reviews on a PR.@coderabbitai resumeto resume the paused reviews.@coderabbitai reviewto trigger an incremental review. This is useful when automatic reviews are disabled for the repository.@coderabbitai full reviewto do a full review from scratch and review all the files again.@coderabbitai summaryto regenerate the summary of the PR.@coderabbitai generate docstringsto generate docstrings for this PR.@coderabbitai resolveresolve all the CodeRabbit review comments.@coderabbitai configurationto show the current CodeRabbit configuration for the repository.@coderabbitai helpto get help.
Other keywords and placeholders
- Add
@coderabbitai ignoreanywhere in the PR description to prevent this PR from being reviewed. - Add
@coderabbitai summaryto generate the high-level summary at a specific location in the PR description. - Add
@coderabbitaianywhere in the PR title to generate the title automatically.
CodeRabbit Configuration File (.coderabbit.yaml)
- You can programmatically configure CodeRabbit by adding a
.coderabbit.yamlfile 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.