Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: initialize root state as an empty object if state function returns no value #927

Merged
merged 3 commits into from
Oct 11, 2017

Conversation

n7olkachev
Copy link
Contributor

@n7olkachev n7olkachev commented Aug 31, 2017

Just a moment ago I had hard time debugging this code:

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.

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.
@ktsn
Copy link
Member

ktsn commented Sep 1, 2017

Thank you for your contribution. However, I think providing an empty object as a default value is more appropriate here because modules' state actually behaves so.
https://github.com/vuejs/vuex/blob/dev/src/module/module.js#L9

@n7olkachev
Copy link
Contributor Author

Is it ok now?

@ktsn ktsn changed the title assert state to be an object fix: initialize root state as an empty object if state function returns no value Sep 1, 2017
Copy link
Member

@ktsn ktsn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@yyx990803 yyx990803 merged commit 0e9756b into vuejs:dev Oct 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants