Skip to content

Commit 0e9756b

Browse files
n7olkachevyyx990803
authored andcommitted
fix: initialize root state as an empty object if state function returns no value (#927)
* assert state to be an object Just a moment ago had hard time debugging this code: ```js const state = () => {} ... new Vuex.Store({ state, modules, ... }) ``` If state is `undefined` and you use modules, Vuex can't create store. This small change will make it easier to find this error. * fix styling * provide default value for state as a function
1 parent 7e85915 commit 0e9756b

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/store.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export class Store {
2929
state = {}
3030
} = options
3131
if (typeof state === 'function') {
32-
state = state()
32+
state = state() || {}
3333
}
3434

3535
// store internal state

0 commit comments

Comments
 (0)