alert.js 671 Bytes
Newer Older
1 2
'use strict'

3
import debounce from 'lodash/debounce'
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26

export default {
  state: {
    shown: false,
    style: 'green',
    icon: 'check',
    msg: ''
  },
  getters: {},
  mutations: {
    alertChange: (state, opts) => {
      state.shown = (opts.shown === true)
      state.style = opts.style || 'green'
      state.icon = opts.icon || 'check'
      state.msg = opts.msg || ''
    }
  },
  actions: {
    alert({ commit, dispatch }, opts) {
      opts.shown = true
      commit('alertChange', opts)
      dispatch('alertDismiss')
    },
27
    alertDismiss: debounce(({ commit }) => {
28 29 30 31 32
      let opts = { shown: false }
      commit('alertChange', opts)
    }, 3000)
  }
}