fileoverview import { Module } from 'vuex' ; import { RootState } from '@/store' ; const DEFAULT_MESSAGE_DURATION = 5000 ; /** Minimum duration between two consecutive messages */ const MESSAGE_INTERVAL = 100 ; interface MessageState { text : string ; class : string ; timeout : NodeJS . Timer | null ; } export interface MessageOptions { text : string ; class ? : string ; duration ? : number ; } const initialState = { text : '' , class : '' , timeout : null } ; const mutations = { /**
     * [text and background colors of message classes]
     * - none: black/white
     * - warn: dark yellow/yellow
     * - error: dark red/red
     */ showMessage : ( state , payload ) => { const display = ( ) => { if ( state . timeout ) { clearTimeout ( state . timeout ) ; state . timeout = null ; } state . text = payload . text ; state . class = payload . class || '' ; const duration = payload . duration || DEFAULT_MESSAGE_DURATION ; if ( state . class !== 'error' ) { state . timeout = setTimeout ( ( ) => state . text = '' , duration ) ; } } ; if ( state . text !== '' ) { state . text = '' ; setTimeout ( display , MESSAGE_INTERVAL ) ; } else { display ( ) ; } } , closeMessage : ( state ) => { state . text = '' ; } } ; const message = { namespaced : true , state : initialState , mutations } ; export default message ;