feat: added global caching for settings, default settings and credentials
This commit is contained in:
@@ -3,6 +3,8 @@ import Vue from 'vue'
|
||||
|
||||
import home from '@/store/modules/home'
|
||||
import settings from '@/store/modules/settings'
|
||||
import defaultSettings from '@/store/modules/defaultSettings'
|
||||
import spotifyCredentials from '@/store/modules/spotifyCredentials'
|
||||
|
||||
// Load Vuex
|
||||
Vue.use(Vuex)
|
||||
@@ -11,7 +13,9 @@ Vue.use(Vuex)
|
||||
export default new Vuex.Store({
|
||||
modules: {
|
||||
home,
|
||||
settings
|
||||
settings,
|
||||
defaultSettings,
|
||||
credentials: spotifyCredentials
|
||||
},
|
||||
strict: process.env.NODE_ENV !== 'production'
|
||||
})
|
||||
|
||||
31
src/store/modules/defaultSettings.js
Normal file
31
src/store/modules/defaultSettings.js
Normal file
@@ -0,0 +1,31 @@
|
||||
import Vue from 'vue'
|
||||
|
||||
const state = {}
|
||||
|
||||
const actions = {
|
||||
setDefaultSettings({ commit }, payload) {
|
||||
for (const settingName in payload) {
|
||||
if (!payload.hasOwnProperty(settingName)) return
|
||||
|
||||
const settingValue = payload[settingName]
|
||||
commit('SET_UNKNOWN_DEFAULT_SETTING', { settingName, settingValue })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const getters = {
|
||||
getDefaultSettings: state => state
|
||||
}
|
||||
|
||||
const mutations = {
|
||||
SET_UNKNOWN_DEFAULT_SETTING(state, payload) {
|
||||
Vue.set(state, payload.settingName, payload.settingValue)
|
||||
}
|
||||
}
|
||||
|
||||
export default {
|
||||
state,
|
||||
actions,
|
||||
getters,
|
||||
mutations
|
||||
}
|
||||
31
src/store/modules/spotifyCredentials.js
Normal file
31
src/store/modules/spotifyCredentials.js
Normal file
@@ -0,0 +1,31 @@
|
||||
const state = {
|
||||
clientId: '',
|
||||
clientSecret: ''
|
||||
}
|
||||
|
||||
const actions = {
|
||||
setCredentials({ commit }, payload) {
|
||||
commit('SET_CLIENT_ID', payload.clientId)
|
||||
commit('SET_CLIENT_SECRET', payload.clientSecret)
|
||||
}
|
||||
}
|
||||
|
||||
const getters = {
|
||||
getCredentials: state => state
|
||||
}
|
||||
|
||||
const mutations = {
|
||||
SET_CLIENT_ID(state, payload) {
|
||||
state.clientId = payload
|
||||
},
|
||||
SET_CLIENT_SECRET(state, payload) {
|
||||
state.clientSecret = payload
|
||||
}
|
||||
}
|
||||
|
||||
export default {
|
||||
state,
|
||||
getters,
|
||||
actions,
|
||||
mutations
|
||||
}
|
||||
Reference in New Issue
Block a user