wikijs-fork/client/store/index.js

57 lines
1.2 KiB
JavaScript
Raw Normal View History

import _ from 'lodash'
import Vue from 'vue'
import Vuex from 'vuex'
2018-07-22 04:29:39 +00:00
import pathify from 'vuex-pathify' // eslint-disable-line import/no-duplicates
import { make } from 'vuex-pathify' // eslint-disable-line import/no-duplicates
2018-10-29 02:09:58 +00:00
import page from './page'
2018-08-04 21:27:55 +00:00
import site from './site'
Vue.use(Vuex)
2018-07-22 04:29:39 +00:00
const state = {
loadingStack: [],
notification: {
message: '',
style: 'primary',
icon: 'cached',
isActive: false
}
}
export default new Vuex.Store({
2018-06-10 00:11:00 +00:00
strict: process.env.NODE_ENV !== 'production',
2018-07-15 23:16:19 +00:00
plugins: [
pathify.plugin
],
2018-07-22 04:29:39 +00:00
state,
getters: {
isLoading: state => { return state.loadingStack.length > 0 }
},
mutations: {
2018-07-22 04:29:39 +00:00
...make.mutations(state),
loadingStart (state, stackName) {
state.loadingStack = _.union(state.loadingStack, [stackName])
},
loadingStop (state, stackName) {
state.loadingStack = _.without(state.loadingStack, stackName)
},
showNotification (state, opts) {
state.notification = _.defaults(opts, {
message: '',
style: 'primary',
icon: 'cached',
isActive: true
})
},
updateNotificationState (state, newState) {
state.notification.isActive = newState
}
},
actions: { },
2018-08-04 21:27:55 +00:00
modules: {
2018-10-29 02:09:58 +00:00
page,
2018-08-04 21:27:55 +00:00
site
}
})