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.

32 lines
671 B

  1. 'use strict'
  2. import debounce from 'lodash/debounce'
  3. export default {
  4. state: {
  5. shown: false,
  6. style: 'green',
  7. icon: 'check',
  8. msg: ''
  9. },
  10. getters: {},
  11. mutations: {
  12. alertChange: (state, opts) => {
  13. state.shown = (opts.shown === true)
  14. state.style = opts.style || 'green'
  15. state.icon = opts.icon || 'check'
  16. state.msg = opts.msg || ''
  17. }
  18. },
  19. actions: {
  20. alert({ commit, dispatch }, opts) {
  21. opts.shown = true
  22. commit('alertChange', opts)
  23. dispatch('alertDismiss')
  24. },
  25. alertDismiss: debounce(({ commit }) => {
  26. let opts = { shown: false }
  27. commit('alertChange', opts)
  28. }, 3000)
  29. }
  30. }