import { defineStore, acceptHMRUpdate } from 'pinia' import { v4 as uuidv4 } from 'uuid' export const useNotifications = defineStore('notifications', { state: () => { return { /**@type {Map} */ notifications: new Map() } }, actions: { remove(id : string) : void { this.notifications.delete(id) }, add(type : string, text: string, timeout: number = 1000) : void { const id = uuidv4() this.notifications.set( id, { type:type, text:text, } ) if (timeout > -1) setTimeout(() => this.remove(id), timeout) } } }) if(import.meta.hot) { import.meta.hot.accept(acceptHMRUpdate(useNotifications, import.meta.hot)) }