Store state should always be a method now

This commit is contained in:
Sébastien Chopin 2017-05-21 15:45:21 +02:00
parent 8350dbfdbc
commit c3355e1467
8 changed files with 22 additions and 29 deletions

View File

@ -1,5 +0,0 @@
module.exports = {
generate: {
minify: false
}
}

View File

@ -1,10 +1,10 @@
export const state = {
export const state = () => ({
list: [
'Lorem ipsum',
'dolor sit amet',
'consetetur sadipscing elitr'
]
}
})
export const mutations = {
add (state, title) {

View File

@ -1,10 +1,10 @@
export const state = {
export const state = () => ({
list: [
'Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.',
'Lorem ipsum dolor sit amet, consetetur sadipscing elit.',
'Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.'
]
}
})
export const mutations = {
add (state, title) {

View File

@ -1,4 +1,6 @@
export const state = { counter: 0 }
export const state = () => ({
counter: 0
})
export const mutations = {
increment (state) {

View File

@ -1,6 +1,6 @@
export const state = {
export const state = () => ({
list: []
}
})
export const mutations = {
add (state, { text }) {

View File

@ -13,7 +13,7 @@ let storeData = {}
// Check if store/index.js exists
const indexFilename = filenames.find((filename) => filename.includes('./index.'))
if (indexFilename) {
storeData = getModule(indexFilename, true)
storeData = getModule(indexFilename)
}
// If store is not an exported method = modules store
@ -41,19 +41,19 @@ if (typeof storeData !== 'function') {
// createStore
export const createStore = storeData instanceof Function ? storeData : () => {
return new Vuex.Store(Object.assign({}, storeData, {
// state: storeData.state instanceof Function ? storeData.state() : {}
state: storeData.state instanceof Function ? storeData.state() : {}
}))
}
// Dynamically require module
function getModule (filename, root) {
function getModule (filename) {
const file = files(filename)
const module = file.default || file
// if (root && module.state && typeof module.state !== 'function') {
// throw new Error('[nuxt] root store state should be a function.')
// }
if (module.commit) {
throw new Error('[nuxt] store should export raw store options instead of an instance.')
throw new Error('[nuxt] store/' + filename.replace('./', '') + ' should export a method which returns a Vuex instance.')
}
if (module.state && typeof module.state !== 'function') {
throw new Error('[nuxt] state should be a function in store/' + filename.replace('./', ''))
}
return module
}

View File

@ -1,8 +1,6 @@
export const state = () => {
return {
baz: 'Vuex Nested Modules'
}
}
export const state = () => ({
baz: 'Vuex Nested Modules'
})
export const getters = {
baz (state) {

View File

@ -3,11 +3,9 @@ import Vuex from 'vuex'
Vue.use(Vuex)
export const state = () => {
return {
counter: 1
}
}
export const state = () => ({
counter: 1
})
export const mutations = {
increment (state) {