Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -505,15 +505,6 @@ export default {
const stores = useResource().appSchemaState.globalState
stores.forEach(({ id, state: _storeState = {}, _getters = {} }) => {
state.variables[id] = id

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

【bug 场景】:
当全局应用状态设置为数组时,绑定变量弹窗处分割的状态不正确。
截屏2025-03-17 14 18 53
截屏2025-03-17 14 20 53

【origin 状态分割的场景】
应用的状态可能有很多的字段,为了方便用户快速绑定对应的字段,这里做了优化。
比如一个应用状态可能是 object,有很多的字段,可能还有 getter:

截屏2025-03-17 14 24 50
截屏2025-03-17 14 26 26

所以这里仅特殊处理一下数组的场景会好一点?

// fix: store 列表错误渲染成子属性列表
// store 值处理迁移到 global-state.ts 进行处理
// const loadProp = (prop) => {
// const propBinding = `${id}.${prop}`
// state.variables[propBinding] = propBinding
// }

// Object.keys(storeState).forEach(loadProp)
// Object.keys(getters).forEach(loadProp)
})
} else if (item.id === 'loop') {
state.bindPrefix = ''
Expand Down

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

原代码中,直接赋值为 store(),出码后,变量的值变成了 store 实例,而不是所需的变量值

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const useStores = () => {
const stores = {}

Object.values({ ...useDefinedStores }).forEach((store) => {
stores[store.$id] = store()
stores[store.$id] = store().$state

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

请问这里改成 $state 是有什么 bug 场景不满足吗?

这里应该不仅仅只赋值 store 的 state。
因为我们要允许用户从 this.stores.storeName 读取 state 或者是 action 或者是 gettter state。
比如:

  • this.stores.test.name 读取 state
  • this.stores.test.fullName 读取 getterState
  • this.stores.test.setName 拿到 stores 的 action

})

return stores
Expand Down