diff --git a/store/index.js b/store/index.js index 1963310..7332184 100644 --- a/store/index.js +++ b/store/index.js @@ -433,10 +433,14 @@ function unifyCommitArgs(type, payload = {}, options = {}) { } function collectState(store) { - let state = store.state || {} + let state = + store.state && typeof store.state === 'function' + ? store.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 b3298f9..beeb941 100644 --- a/store/index.test.ts +++ b/store/index.test.ts @@ -869,7 +869,7 @@ it('applies old actions from store in modules', async () => { { user: { namespaced: false, - state: { value: 0 }, + state: () => ({ value: 0 }), mutations: { 'user/historyLine': historyLine } @@ -1033,7 +1033,7 @@ it('applies old actions from store in nested modules', async () => { } let store2 = _createStore2({ - state: { value: 0 }, + state: () => ({ value: 0 }), mutations: { historyLine }, modules: { a: { @@ -1047,7 +1047,7 @@ it('applies old actions from store in nested modules', async () => { modules: { c: { namespaced: true, - state: { value: 0 }, + state: () => ({ value: 0 }), mutations: { historyLine }, modules: { d: {