feat: 优化全局状态管理机制
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?
- [x] Bugfix
- [x] 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?
调整了全局路由的管理方式,统一到一个module中,管理和使用更加简单
Issue Number: N/A
What is the new behavior?
- 重构全局状态管理,将多个独立 store 合并为单一 globalState
- 在 schema 中添加 globalState 引用,指向 stores 以支持全局状态访问
- 修改变量配置器中的状态引用路径从 this.stores 改为 this.globalState
- 更新页面生成器,在上下文中添加 globalState 支持
- 优化 genGlobalState 插件,生成统一的全局状态管理文件
- 在 lowcode.js 中集成 globalState 并暴露给组件使用
Does this PR introduce a breaking change?
- [ ] Yes
- [x] No
Other information
Summary by CodeRabbit
-
New Features
- Introduced a unified global state management feature that improves state consistency and ensures seamless data flow across app components, enhancing overall user experience.
-
Refactor
- Simplified application state handling by consolidating previously separate state streams into a single, robust global store, contributing to improved performance, easier maintenance, and smoother configuration.
Walkthrough
This pull request integrates a consolidated global state management approach across multiple modules. A new globalState parameter is added to the useSchema function context, and various components have been updated to reference the global state instead of a local store. Changes include constant updates, modifications to context arrays, and the introduction of a unified global state store using Pinia, along with its proper export and initialization in low-code configurations.
Changes
| File(s) | Change Summary |
|---|---|
packages/canvas/.../schema.tspackages/vue-generator/src/generator/page.js |
Added a globalState parameter to the context (and injection) to support global state management. |
packages/configurator/src/variable-configurator/VariableConfigurator.vue |
Updated the STORE constant from 'this.stores.' to 'this.globalState.' to shift the reference from a local to a global state. |
packages/vue-generator/src/plugins/genGlobalState.js |
Consolidated individual state stores into a single global state store using Pinia; added exports for globalState and useGlobalState. |
packages/vue-generator/src/templates/vue-template/.../lowcodeConfig/lowcode.js |
Imported useGlobalState and initialized a new globalState in the low-code configuration, integrating it with other context properties. |
Sequence Diagram(s)
sequenceDiagram
participant C as Vue Component
participant S as useSchema
participant G as GlobalState Store
participant V as Vue Generator (page.js)
participant L as Lowcode Config
C->>S: Invoke useSchema(context with globalState)
Note right of S: globalState is now part of the context
V->>G: Retrieve global state via useGlobalState()
L->>G: Import global state for configuration
Poem
Hoppity code in fields so wide,
Global state now walks beside.
From schema to config, every line's bright,
A single store makes our app feel light.
With each new hop in this refined ride,
The rabbit sings in pure delight!
🐇✨
[!TIP]
⚡💬 Agentic Chat (Pro Plan, General Availability)
- We're introducing multi-step agentic chat in review comments and issue comments, within and outside of PR's. This feature enhances review and issue discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments and add commits to existing pull requests.
✨ 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 planto trigger planning for file edits and PR creation.@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.