Skip to content

Commit

Permalink
fix(store): handle case when the root store is a function
Browse files Browse the repository at this point in the history
  • Loading branch information
VladBrok committed Nov 11, 2023
1 parent 0dc3bec commit cf756dd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 4 additions & 1 deletion store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,10 @@ 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] =
Expand Down
4 changes: 2 additions & 2 deletions store/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1034,7 +1034,7 @@ it('applies old actions from store in nested modules', async () => {
}

let store2 = _createStore2<Store2State>({
state: { value: 0 },
state: () => ({ value: 0 }),
mutations: { historyLine },
modules: {
a: {
Expand All @@ -1048,7 +1048,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: {
Expand Down

0 comments on commit cf756dd

Please sign in to comment.