Newer
Older
import Vue from 'vue'
import Vuex from 'vuex'
import createPersistedState from 'vuex-persistedstate'
import favorites from './favorites'
import queue from './queue'
import radios from './radios'
import player from './player'
Vue.use(Vuex)
export default new Vuex.Store({
modules: {
queue,
radios,
player
},
plugins: [
createPersistedState({
key: 'auth',
paths: ['auth'],
filter: (mutation) => {
return mutation.type.startsWith('auth/')
}
}),
createPersistedState({
key: 'instance',
paths: ['instance.events']
}),
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
createPersistedState({
key: 'radios',
paths: ['radios'],
filter: (mutation) => {
return mutation.type.startsWith('radios/')
}
}),
createPersistedState({
key: 'player',
paths: [
'player.looping',
'player.volume',
'player.duration',
'player.errored'],
filter: (mutation) => {
return mutation.type.startsWith('player/') && mutation.type !== 'player/currentTime'
}
}),
createPersistedState({
key: 'queue',
filter: (mutation) => {
return mutation.type.startsWith('queue/')
},
reducer: (state) => {
return {
queue: {
currentIndex: state.queue.currentIndex,
tracks: state.queue.tracks.map(track => {
// we keep only valuable fields to make the cache lighter and avoid
// cyclic value serialization errors
let artist = {
id: track.artist.id,
mbid: track.artist.mbid,
name: track.artist.name
}
return {
id: track.id,
title: track.title,
mbid: track.mbid,
album: {
id: track.album.id,
title: track.album.title,
mbid: track.album.mbid,
cover: track.album.cover,
artist: artist
},
artist: artist,
files: track.files
}
})
}
}
}
})
]