Skip to content

Commit

Permalink
fix: initialize root state as an empty object if state function retur…
Browse files Browse the repository at this point in the history
…ns 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
  • Loading branch information
n7olkachev authored and yyx990803 committed Oct 11, 2017
1 parent 7e85915 commit 0e9756b
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class Store {
state = {}
} = options
if (typeof state === 'function') {
state = state()
state = state() || {}
}

// store internal state
Expand Down

0 comments on commit 0e9756b

Please sign in to comment.