import Vue from 'vue'
import Vuex from 'vuex'
import getters from './getters'
// import { closeWebSocket } from '@/utils/WebSocketUtil'

Vue.use(Vuex)

// 动态加载modules
const loadModules = () => {
  const context = require.context('./modules', true, /\.js$/)
  const modules = context.keys().reduce((modules, modulePath) => {
    const moduleName = modulePath.replace(/^\.\/(.*)\.\w+$/, '$1')
    const value = context(modulePath)
    modules[moduleName] = value.default
    return modules
  }, {})
  return { modules, context }
}
const { modules } = loadModules()
// 创建store
const store = new Vuex.Store({
  modules,
  getters
})

export default store
