Skip to content

Commit

Permalink
fix: state & globalState getter (#930)
Browse files Browse the repository at this point in the history
* fix: state & globalState getter

1. 修复 state getter、setter 无法保存、修改的bug
2. 修复 globalState getter 在画布计算不正确的 bug

* fix: del useless variable
  • Loading branch information
chilingling authored Dec 10, 2024
1 parent 1dc492a commit d45eb4b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/canvas/render/src/RenderMain.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ watchEffect(() => {
const computedGetters = Object.keys(getters).reduce(
(acc, key) => ({
...acc,
[key]: parseData(getters[key], state, acc)
[key]: parseData(getters[key], null, acc)?.call?.(acc, state)
}),
{}
)
Expand Down
10 changes: 7 additions & 3 deletions packages/plugins/state/src/CreateVariable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ export default {
errorMessage: '',
activeName: ['initValue', 'getter', 'setter'],
createData: getPropsCreateData(),
hasAccessor: isAccessorData(props.createData?.variable),
variableType: getVarType(),
getterEditorValue: props.createData.variable?.accessor?.getter?.value || DEFAULT_GETTER,
setterEditorValue: props.createData.variable?.accessor?.setter?.value || DEFAULT_SETTER,
Expand Down Expand Up @@ -199,7 +198,6 @@ export default {
() => props.createData.variable,
() => {
state.errorMessage = ''
state.hasAccessor = isAccessorData(props.createData?.variable)
state.getterEditorValue = props.createData.variable?.accessor?.getter?.value || DEFAULT_GETTER
state.setterEditorValue = props.createData.variable?.accessor?.setter?.value || DEFAULT_SETTER
state.variableType = getVarType()
Expand Down Expand Up @@ -253,20 +251,26 @@ export default {
const getFormData = () => {
const defaultValue = getDefaultValue()
if (!state.hasAccessor) return defaultValue
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
}
Expand Down

0 comments on commit d45eb4b

Please sign in to comment.