From 0dc3becdbd772dd94665a621c5f73daad0d1ec28 Mon Sep 17 00:00:00 2001 From: VladBrok Date: Sun, 12 Nov 2023 02:22:48 +0300 Subject: [PATCH] fix(store): collect state from modules if state is a function --- store/index.js | 3 ++- store/index.test.ts | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/store/index.js b/store/index.js index 1963310..4fefd6b 100644 --- a/store/index.js +++ b/store/index.js @@ -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) => { diff --git a/store/index.test.ts b/store/index.test.ts index 53883ee..b426682 100644 --- a/store/index.test.ts +++ b/store/index.test.ts @@ -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 }