index.js 971 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import _ from 'lodash'
  2. import Vue from 'vue'
  3. import Vuex from 'vuex'
  4. Vue.use(Vuex)
  5. export default new Vuex.Store({
  6. strict: process.env.NODE_ENV !== 'production',
  7. state: {
  8. loadingStack: [],
  9. notification: {
  10. message: '',
  11. style: 'primary',
  12. icon: 'cached',
  13. isActive: false
  14. }
  15. },
  16. getters: {
  17. isLoading: state => { return state.loadingStack.length > 0 }
  18. },
  19. mutations: {
  20. loadingStart (state, stackName) {
  21. state.loadingStack = _.union(state.loadingStack, [stackName])
  22. },
  23. loadingStop (state, stackName) {
  24. state.loadingStack = _.without(state.loadingStack, stackName)
  25. },
  26. showNotification (state, opts) {
  27. state.notification = _.defaults(opts, {
  28. message: '',
  29. style: 'primary',
  30. icon: 'cached',
  31. isActive: true
  32. })
  33. },
  34. updateNotificationState (state, newState) {
  35. state.notification.isActive = newState
  36. }
  37. },
  38. actions: { },
  39. modules: { }
  40. })