perf: applied home cache technique to favorites and to settings
This commit is contained in:
@@ -1,10 +1,6 @@
|
||||
import Vuex from 'vuex'
|
||||
import Vue from 'vue'
|
||||
|
||||
import settings from '@/store/modules/settings'
|
||||
import defaultSettings from '@/store/modules/defaultSettings'
|
||||
import spotifyCredentials from '@/store/modules/spotifyCredentials'
|
||||
import favorites from '@/store/modules/favorites'
|
||||
import about from '@/store/modules/about'
|
||||
import login from '@/store/modules/login'
|
||||
import errors from '@/store/modules/errors'
|
||||
@@ -15,10 +11,6 @@ Vue.use(Vuex)
|
||||
// Create store
|
||||
export default new Vuex.Store({
|
||||
modules: {
|
||||
settings,
|
||||
defaultSettings,
|
||||
spotifyCredentials,
|
||||
favorites,
|
||||
about,
|
||||
login,
|
||||
errors
|
||||
|
||||
@@ -1,65 +0,0 @@
|
||||
import Vue from 'vue'
|
||||
|
||||
const state = {
|
||||
albums: [],
|
||||
artists: [],
|
||||
playlists: [],
|
||||
tracks: [],
|
||||
test: ''
|
||||
}
|
||||
|
||||
const actions = {
|
||||
setFavorites({ commit, dispatch }, payload) {
|
||||
payload.playlists.forEach((playlist, index) => {
|
||||
commit('SET_FAVORITES_PLAYLISTS', { index, data: playlist })
|
||||
})
|
||||
|
||||
payload.albums.forEach((album, index) => {
|
||||
commit('SET_FAVORITES_ALBUMS', { index, data: album })
|
||||
})
|
||||
|
||||
payload.artists.forEach((artist, index) => {
|
||||
commit('SET_FAVORITES_ARTISTS', { index, data: artist })
|
||||
})
|
||||
|
||||
dispatch('setFavoritesTracks', payload.tracks)
|
||||
},
|
||||
setFavoritesTracks({ commit }, payload) {
|
||||
commit('SET_FAVORITES_TRACKS', payload)
|
||||
}
|
||||
}
|
||||
|
||||
const getters = {
|
||||
getFavorites: state => state,
|
||||
getFavoritesAlbums: state => state.albums,
|
||||
getFavoritesArtists: state => state.artists,
|
||||
getFavoritesPlaylists: state => state.playlists,
|
||||
getFavoritesTracks: state => state.tracks
|
||||
}
|
||||
|
||||
const mutations = {
|
||||
SET_FAVORITES_ALBUMS: (state, payload) => {
|
||||
Vue.set(state.albums, payload.index, payload.data)
|
||||
},
|
||||
SET_FAVORITES_ARTISTS: (state, payload) => {
|
||||
Vue.set(state.artists, payload.index, payload.data)
|
||||
},
|
||||
SET_FAVORITES_PLAYLISTS: (state, payload) => {
|
||||
Vue.set(state.playlists, payload.index, payload.data)
|
||||
},
|
||||
SET_FAVORITES_TRACKS: (state, payload) => {
|
||||
if (typeof payload !== 'string') {
|
||||
console.error('[deemix] Not setting the favorites tracks because they are not in string format')
|
||||
return
|
||||
}
|
||||
|
||||
state.tracks = payload
|
||||
}
|
||||
}
|
||||
|
||||
export default {
|
||||
state,
|
||||
actions,
|
||||
getters,
|
||||
mutations
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
import Vue from 'vue'
|
||||
|
||||
const state = {}
|
||||
|
||||
const actions = {
|
||||
setSettings({ commit }, payload) {
|
||||
for (const settingName in payload) {
|
||||
if (!payload.hasOwnProperty(settingName)) return
|
||||
|
||||
const settingValue = payload[settingName]
|
||||
commit('SET_UNKNOWN_SETTING', { settingName, settingValue })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const getters = {
|
||||
getSettings: state => state
|
||||
}
|
||||
|
||||
const mutations = {
|
||||
SET_UNKNOWN_SETTING(state, payload) {
|
||||
Vue.set(state, payload.settingName, payload.settingValue)
|
||||
}
|
||||
}
|
||||
|
||||
export default {
|
||||
state,
|
||||
actions,
|
||||
getters,
|
||||
mutations
|
||||
}
|
||||
Reference in New Issue
Block a user