-
Notifications
You must be signed in to change notification settings - Fork 5
/
store.js
63 lines (51 loc) · 1.12 KB
/
store.js
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
import Vue from 'vue'
import Vuex from 'vuex'
const VERSION = '1.4'
const VERSION_KEY = 'raVe-v'
const STORAGE_KEY = 'raVe'
Vue.use(Vuex)
let version = localStorage.getItem(VERSION_KEY)
let saved = localStorage.getItem(STORAGE_KEY)
if (version === VERSION && saved !== null) {
saved = JSON.parse(saved)
} else {
saved = null
localStorage.setItem(VERSION_KEY, VERSION)
}
const state = saved || {
settings: {
autoEnter: false,
autoQ: true,
scale: 1,
showFPS: false,
showDonate: true
}
}
const mutations = {
setAutoEnter(state, autoEnter) {
state.settings.autoEnter = autoEnter
},
setAutoQ(state, autoQ) {
state.settings.autoQ = autoQ
},
setScale(state, scale) {
state.settings.scale = scale
},
setShowFPS(state, show) {
state.settings.showFPS = show
},
stopShowingDonate(state) {
state.settings.showDonate = false
}
}
const localStoragePlugin = store => {
store.subscribe((mutation, state) => {
localStorage.setItem(STORAGE_KEY, JSON.stringify(state))
})
}
export default new Vuex.Store({
state,
mutations,
actions: {},
plugins: [localStoragePlugin]
})