Skip to content

Commit

Permalink
fix(store): collect state from modules if state is a function
Browse files Browse the repository at this point in the history
  • Loading branch information
VladBrok committed Nov 11, 2023
1 parent 4b783c0 commit 0dc3bec
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,8 @@ function collectState(store) {
let state = store.state || {}
function collectModuleState(module, moduleName, moduleState) {
if (moduleName) {
moduleState[moduleName] = module.state
moduleState[moduleName] =
typeof module.state === 'function' ? module.state() : module.state
}
if (module.modules) {
forEachValue(module.modules, (childModule, childModuleName) => {
Expand Down
2 changes: 1 addition & 1 deletion store/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -870,7 +870,7 @@ it('applies old actions from store in modules', async () => {
{
user: {
namespaced: false,
state: { value: 0 },
state: () => ({ value: 0 }),
mutations: {
'user/historyLine': historyLine
}
Expand Down

0 comments on commit 0dc3bec

Please sign in to comment.