-
Notifications
You must be signed in to change notification settings - Fork 340
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: state & globalState getter #930
fix: state & globalState getter #930
Conversation
1. 修复 state getter、setter 无法保存、修改的bug 2. 修复 globalState getter 在画布计算不正确的 bug
WalkthroughThe pull request introduces modifications to two primary files: Changes
Possibly related PRs
Suggested labels
Suggested reviewers
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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 (2)
packages/plugins/state/src/CreateVariable.vue (2)
260-273
: Improve accessor object creation logicThe changes improve the handling of getter/setter functions, but the accessor object creation could be optimized further.
Consider this more concise implementation:
const defaultValue = getDefaultValue() const getter = getterEditor.value.getEditor().getValue() const setter = setterEditor.value.getEditor().getValue() if (!getter && !setter) return defaultValue - const result = { defaultValue } - - if (getter && getter !== DEFAULT_GETTER) { - result.accessor = { ...result.accessor, getter: { type: 'JSFunction', value: getter } } - } - - if (setter && setter !== DEFAULT_SETTER) { - result.accessor = { ...result.accessor, setter: { type: 'JSFunction', value: setter } } - } - - // 没有设置 getter setter,需要直接返回 defaultValue - if (!result.accessor) { - return defaultValue - } - - return result + const accessor = {} + if (getter && getter !== DEFAULT_GETTER) { + accessor.getter = { type: 'JSFunction', value: getter } + } + if (setter && setter !== DEFAULT_SETTER) { + accessor.setter = { type: 'JSFunction', value: setter } + } + return Object.keys(accessor).length ? { defaultValue, accessor } : defaultValueThis implementation:
- Creates the accessor object only when needed
- Avoids unnecessary spread operations
- Simplifies the return logic
Line range hint
277-292
: Consider using local error state in validationThe current implementation uses shared state for error messages, which could lead to race conditions if multiple validations occur simultaneously.
Consider this approach:
const validateName = (rule, name, callback) => { - state.errorMessage = '' + let errorMessage = '' if (!name) { - state.errorMessage = 'state 属性名称未定义' + errorMessage = 'state 属性名称未定义' } else if (!verifyJsVarName(name)) { - state.errorMessage = ' state 属性名称只能以字母或下划线开头且仅包含数字字母及下划线' + errorMessage = ' state 属性名称只能以字母或下划线开头且仅包含数字字母及下划线' } else if ( Object.keys(props.dataSource).includes(name) && (props.flag !== 'update' || name !== props.updateKey) ) { - state.errorMessage = '已存在同名 state 属性' + errorMessage = '已存在同名 state 属性' } - state.errorMessage ? callback(new Error(state.errorMessage)) : callback() + state.errorMessage = errorMessage + errorMessage ? callback(new Error(errorMessage)) : callback() }This change:
- Uses local state for error handling
- Updates shared state only after validation
- Reduces the risk of race conditions
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (1)
packages/plugins/state/src/CreateVariable.vue
(1 hunks)
🔇 Additional comments (1)
packages/plugins/state/src/CreateVariable.vue (1)
Line range hint 260-292
: Changes effectively address the state management issues
The modifications successfully improve the state getter/setter functionality by:
- Properly handling accessor objects in getFormData
- Ensuring valid state names through enhanced validation
- Maintaining backward compatibility
The implementation aligns well with the PR objectives of fixing state getter/setter saving issues.
English | 简体中文
PR
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
Background and solution
【问题描述】
状态管理 -> 页面状态 -> 编辑 setter 或者 getter -> 保存
问题:编辑之后的 setter 或者 getter 没有保存成功
预期: setter 或者 getter 保存成功
状态管理 -> 应用状态 -> 添加计算的 getter -> 保存 -> 绑定到Text 组件的文本属性测试显示
问题:画布中文本属性显示了函数原声明
预期:显示函数调用之后计算出来的值
【问题分析】
getFormData
没有进行更新适配parseData
函数进行解析,但是没有发起调用执行【解决方案】
What is the current behavior?
Issue Number: N/A
What is the new behavior?
Does this PR introduce a breaking change?
Other information
Summary by CodeRabbit
Summary by CodeRabbit
New Features
Bug Fixes
Documentation