| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- import Vue from 'vue'
- import Vuex from 'vuex'
- Vue.use(Vuex)
- let store = {};
- (function updateModules () {
- store = normalizeRoot(require('../store/index.js'), 'store/index.js')
- // If store is an exported method = classic mode (deprecated)
- // Enforce store modules
- store.modules = store.modules || {}
- // If the environment supports hot reloading...
- })()
- // createStore
- export const createStore = store instanceof Function ? store : () => {
- return new Vuex.Store(Object.assign({
- strict: (process.env.NODE_ENV !== 'production')
- }, store))
- }
- function normalizeRoot (moduleData, filePath) {
- moduleData = moduleData.default || moduleData
- if (moduleData.commit) {
- throw new Error(`[nuxt] ${filePath} should export a method that returns a Vuex instance.`)
- }
- if (typeof moduleData !== 'function') {
- // Avoid TypeError: setting a property that has only a getter when overwriting top level keys
- moduleData = Object.assign({}, moduleData)
- }
- return normalizeModule(moduleData, filePath)
- }
- function normalizeModule (moduleData, filePath) {
- if (moduleData.state && typeof moduleData.state !== 'function') {
- console.warn(`'state' should be a method that returns an object in ${filePath}`)
- const state = Object.assign({}, moduleData.state)
- // Avoid TypeError: setting a property that has only a getter when overwriting top level keys
- moduleData = Object.assign({}, moduleData, { state: () => state })
- }
- return moduleData
- }
|