-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: using typescript in store directory
- Loading branch information
1 parent
8a7700e
commit 3cdd947
Showing
2 changed files
with
45 additions
and
35 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { GetterTree, Store, MutationTree } from 'vuex' | ||
|
||
export const state = () => ({ | ||
show: false, | ||
content: '', | ||
theme: 'info', | ||
iconHTML: '', | ||
autoDismiss: true, | ||
timeout: 5000, | ||
}) | ||
let timeoutId: NodeJS.Timeout | ||
|
||
export type ToastState = ReturnType<typeof state> | ||
|
||
export const getters: GetterTree<ToastState, ToastState> = { | ||
show: (state) => state.show, | ||
content: (state) => state.content, | ||
theme: (state) => state.theme, | ||
iconHTML: (state) => state.iconHTML, | ||
autoDismiss: (state) => state.autoDismiss, | ||
timeout: (state) => state.timeout, | ||
} | ||
|
||
export const mutations: MutationTree<ToastState> = { | ||
show(state, { show, content, iconHTML, theme }: ToastState) { | ||
if (!show) { | ||
state.show = show | ||
return | ||
} | ||
const isAlreadyShowing = state.show | ||
state.content = content | ||
state.theme = theme || 'info' | ||
state.iconHTML = iconHTML | ||
state.show = !!content && show | ||
if (isAlreadyShowing && state.show && timeoutId) { | ||
clearTimeout(timeoutId) | ||
} | ||
if (state.show) { | ||
timeoutId = setTimeout(() => { | ||
const store = this as unknown as Store<ToastState> | ||
store.commit('toast/show', { show: false }) | ||
}, 5000) | ||
} | ||
}, | ||
} |
3cdd947
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: