You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
1.2 KiB

6 years ago
6 years ago
6 years ago
6 years ago
  1. import _ from 'lodash'
  2. import Vue from 'vue'
  3. import Vuex from 'vuex'
  4. import pathify from 'vuex-pathify' // eslint-disable-line import/no-duplicates
  5. import { make } from 'vuex-pathify' // eslint-disable-line import/no-duplicates
  6. import page from './page'
  7. import site from './site'
  8. Vue.use(Vuex)
  9. const state = {
  10. loadingStack: [],
  11. notification: {
  12. message: '',
  13. style: 'primary',
  14. icon: 'cached',
  15. isActive: false
  16. }
  17. }
  18. export default new Vuex.Store({
  19. strict: process.env.NODE_ENV !== 'production',
  20. plugins: [
  21. pathify.plugin
  22. ],
  23. state,
  24. getters: {
  25. isLoading: state => { return state.loadingStack.length > 0 }
  26. },
  27. mutations: {
  28. ...make.mutations(state),
  29. loadingStart (state, stackName) {
  30. state.loadingStack = _.union(state.loadingStack, [stackName])
  31. },
  32. loadingStop (state, stackName) {
  33. state.loadingStack = _.without(state.loadingStack, stackName)
  34. },
  35. showNotification (state, opts) {
  36. state.notification = _.defaults(opts, {
  37. message: '',
  38. style: 'primary',
  39. icon: 'cached',
  40. isActive: true
  41. })
  42. },
  43. updateNotificationState (state, newState) {
  44. state.notification.isActive = newState
  45. }
  46. },
  47. actions: { },
  48. modules: {
  49. page,
  50. site
  51. }
  52. })