mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-14 01:53:55 +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: [
|
list: [
|
||||||
'Lorem ipsum',
|
'Lorem ipsum',
|
||||||
'dolor sit amet',
|
'dolor sit amet',
|
||||||
'consetetur sadipscing elitr'
|
'consetetur sadipscing elitr'
|
||||||
]
|
]
|
||||||
}
|
})
|
||||||
|
|
||||||
export const mutations = {
|
export const mutations = {
|
||||||
add (state, title) {
|
add (state, title) {
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
export const state = {
|
export const state = () => ({
|
||||||
list: [
|
list: [
|
||||||
'Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.',
|
'Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.',
|
||||||
'Lorem ipsum dolor sit amet, consetetur sadipscing elit.',
|
'Lorem ipsum dolor sit amet, consetetur sadipscing elit.',
|
||||||
'Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.'
|
'Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.'
|
||||||
]
|
]
|
||||||
}
|
})
|
||||||
|
|
||||||
export const mutations = {
|
export const mutations = {
|
||||||
add (state, title) {
|
add (state, title) {
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
export const state = { counter: 0 }
|
export const state = () => ({
|
||||||
|
counter: 0
|
||||||
|
})
|
||||||
|
|
||||||
export const mutations = {
|
export const mutations = {
|
||||||
increment (state) {
|
increment (state) {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
export const state = {
|
export const state = () => ({
|
||||||
list: []
|
list: []
|
||||||
}
|
})
|
||||||
|
|
||||||
export const mutations = {
|
export const mutations = {
|
||||||
add (state, { text }) {
|
add (state, { text }) {
|
||||||
|
@ -13,7 +13,7 @@ let storeData = {}
|
|||||||
// Check if store/index.js exists
|
// Check if store/index.js exists
|
||||||
const indexFilename = filenames.find((filename) => filename.includes('./index.'))
|
const indexFilename = filenames.find((filename) => filename.includes('./index.'))
|
||||||
if (indexFilename) {
|
if (indexFilename) {
|
||||||
storeData = getModule(indexFilename, true)
|
storeData = getModule(indexFilename)
|
||||||
}
|
}
|
||||||
|
|
||||||
// If store is not an exported method = modules store
|
// If store is not an exported method = modules store
|
||||||
@ -41,19 +41,19 @@ if (typeof storeData !== 'function') {
|
|||||||
// createStore
|
// createStore
|
||||||
export const createStore = storeData instanceof Function ? storeData : () => {
|
export const createStore = storeData instanceof Function ? storeData : () => {
|
||||||
return new Vuex.Store(Object.assign({}, 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
|
// Dynamically require module
|
||||||
function getModule (filename, root) {
|
function getModule (filename) {
|
||||||
const file = files(filename)
|
const file = files(filename)
|
||||||
const module = file.default || file
|
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) {
|
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
|
return module
|
||||||
}
|
}
|
||||||
|
6
test/fixtures/basic/store/foo/bar.js
vendored
6
test/fixtures/basic/store/foo/bar.js
vendored
@ -1,8 +1,6 @@
|
|||||||
export const state = () => {
|
export const state = () => ({
|
||||||
return {
|
|
||||||
baz: 'Vuex Nested Modules'
|
baz: 'Vuex Nested Modules'
|
||||||
}
|
})
|
||||||
}
|
|
||||||
|
|
||||||
export const getters = {
|
export const getters = {
|
||||||
baz (state) {
|
baz (state) {
|
||||||
|
6
test/fixtures/basic/store/index.js
vendored
6
test/fixtures/basic/store/index.js
vendored
@ -3,11 +3,9 @@ import Vuex from 'vuex'
|
|||||||
|
|
||||||
Vue.use(Vuex)
|
Vue.use(Vuex)
|
||||||
|
|
||||||
export const state = () => {
|
export const state = () => ({
|
||||||
return {
|
|
||||||
counter: 1
|
counter: 1
|
||||||
}
|
})
|
||||||
}
|
|
||||||
|
|
||||||
export const mutations = {
|
export const mutations = {
|
||||||
increment (state) {
|
increment (state) {
|
||||||
|
Loading…
Reference in New Issue
Block a user