فهرست منبع

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
Nikita Tolkachev 7 سال پیش
والد
کامیت
0e9756b93c
1فایلهای تغییر یافته به همراه1 افزوده شده و 1 حذف شده
  1. 1 1
      src/store.js

+ 1 - 1
src/store.js

@@ -29,7 +29,7 @@ export class Store {
       state = {}
     } = options
     if (typeof state === 'function') {
-      state = state()
+      state = state() || {}
     }
 
     // store internal state