-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathindex.ts
73 lines (66 loc) · 1.46 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import Vue from 'vue'
import Vuex from 'vuex'
interface StateI {
isStaff: boolean
isSbcStaff: boolean
roles: string[]
}
export function getVuexStore () {
Vue.use(Vuex)
const store = new Vuex.Store<any>({
state,
getters,
mutations,
actions
})
return store
}
export function state (): StateI {
return {
isStaff: null,
isSbcStaff: null,
roles: [],
}
}
// Use "commit" to call a mutation, eg:
// this.$store.commit('setStaff', true)
// or use vuex mapMutations() helper.
export const mutations = {
setStaff (state: StateI, val: boolean) {
state.isStaff = val
},
setSbcStaff (state: StateI, val: boolean) {
state.isSbcStaff = val
},
setRoles (state: StateI, val: string[]) {
state.roles = val
},
}
// Use "dispatch" to call an action, eg:
// this.$store.dispatch('setStaff', true)
// or use vuex "mapActions" helper.
export const actions = {
setStaff ({ commit }, val: boolean) {
commit('setStaff', val)
},
setSbcStaff ({ commit }, val: boolean) {
commit('setSbcStaff', val)
},
setRoles ({ commit }, val: string[]) {
commit('setRoles', val)
},
}
// Use "getters" to call a getter, eg:
// this.$store.getters.isStaff
// or use vuex mapGetters() helper.
export const getters = {
isStaff (state: StateI): boolean {
return state.isStaff
},
isSbcStaff (state: StateI): boolean {
return state.isSbcStaff
},
getRoles (state: StateI): string[] {
return state.roles
},
}