mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-11 08:33:53 +00:00
Store state should always be a method now
This commit is contained in:
parent
8350dbfdbc
commit
c3355e1467
@ -1,5 +0,0 @@
|
||||
module.exports = {
|
||||
generate: {
|
||||
minify: false
|
||||
}
|
||||
}
|
@ -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) {
|
||||
|
@ -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) {
|
||||
|
@ -1,4 +1,6 @@
|
||||
export const state = { counter: 0 }
|
||||
export const state = () => ({
|
||||
counter: 0
|
||||
})
|
||||
|
||||
export const mutations = {
|
||||
increment (state) {
|
||||
|
@ -1,6 +1,6 @@
|
||||
export const state = {
|
||||
export const state = () => ({
|
||||
list: []
|
||||
}
|
||||
})
|
||||
|
||||
export const mutations = {
|
||||
add (state, { text }) {
|
||||
|
@ -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
|
||||
}
|
||||
|
8
test/fixtures/basic/store/foo/bar.js
vendored
8
test/fixtures/basic/store/foo/bar.js
vendored
@ -1,8 +1,6 @@
|
||||
export const state = () => {
|
||||
return {
|
||||
baz: 'Vuex Nested Modules'
|
||||
}
|
||||
}
|
||||
export const state = () => ({
|
||||
baz: 'Vuex Nested Modules'
|
||||
})
|
||||
|
||||
export const getters = {
|
||||
baz (state) {
|
||||
|
8
test/fixtures/basic/store/index.js
vendored
8
test/fixtures/basic/store/index.js
vendored
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user