diff --git a/src/store/albums.js b/src/store/albums.js index 82341e01..c7edbfdd 100644 --- a/src/store/albums.js +++ b/src/store/albums.js @@ -12,7 +12,6 @@ import { compareAlbumsByReleaseFirst, compareAlbumsByTitleFirst, } from "../comparators"; -import store from "./store"; export default { namespaced: true, @@ -108,7 +107,7 @@ export default { async index({ commit, rootState }) { const generator = index(rootState.auth); try { - await store.albumsRestored; + await this.restored; await fetchAll(commit, generator, "setAlbums"); return true; } catch (error) { @@ -129,7 +128,7 @@ export default { async read({ commit, rootState }, id) { try { const result = await read(rootState.auth, id); - await store.albumsRestored; + await this.restored; commit("setAlbum", { id, album: result }); return result.id; } catch (error) { diff --git a/src/store/artists.js b/src/store/artists.js index c57a621c..119d84cd 100644 --- a/src/store/artists.js +++ b/src/store/artists.js @@ -10,7 +10,6 @@ import { } from "../api/artists"; import { fetchAll } from "./actions"; import { compareStrings } from "../comparators"; -import store from "./store"; export default { namespaced: true, @@ -58,7 +57,7 @@ export default { async index({ commit, rootState }) { const generator = index(rootState.auth); try { - await store.artistsRestored; + await this.restored; await fetchAll(commit, generator, "setArtists"); return true; } catch (error) { @@ -79,7 +78,7 @@ export default { async read({ commit, rootState }, id) { try { const result = await read(rootState.auth, id); - await store.artistsRestored; + await this.restored; commit("setArtist", { id, artist: result }); return result.id; } catch (error) { diff --git a/src/store/genres.js b/src/store/genres.js index c3d3e0bb..a7ae62cf 100644 --- a/src/store/genres.js +++ b/src/store/genres.js @@ -10,7 +10,6 @@ import { } from "../api/genres"; import { fetchAll } from "./actions"; import { compareStrings } from "../comparators"; -import store from "./store"; export default { namespaced: true, @@ -58,7 +57,7 @@ export default { async index({ commit, rootState }) { const generator = index(rootState.auth); try { - await store.genresRestored; + await this.restored; await fetchAll(commit, generator, "setGenres"); return true; } catch (error) { @@ -79,7 +78,7 @@ export default { async read({ commit, rootState }, id) { try { const result = await read(rootState.auth, id); - await store.genresRestored; + await this.restored; commit("setGenre", { id, genre: result }); return result.id; } catch (error) { diff --git a/src/store/labels.js b/src/store/labels.js index 9133526d..2a30a718 100644 --- a/src/store/labels.js +++ b/src/store/labels.js @@ -10,7 +10,6 @@ import { } from "../api/labels"; import { fetchAll } from "./actions"; import { compareStrings } from "../comparators"; -import store from "./store"; export default { namespaced: true, @@ -58,7 +57,7 @@ export default { async index({ commit, rootState }) { const generator = index(rootState.auth); try { - await store.labelsRestored; + await this.restored; await fetchAll(commit, generator, "setLabels"); return true; } catch (error) { @@ -79,7 +78,7 @@ export default { async read({ commit, rootState }, id) { try { const result = await read(rootState.auth, id); - await store.labelsRestored; + await this.restored; commit("setLabel", { id, label: result }); return result.id; } catch (error) { diff --git a/src/store/persistence.js b/src/store/persistence.js index 7a3e1b65..ba5eca64 100644 --- a/src/store/persistence.js +++ b/src/store/persistence.js @@ -45,21 +45,18 @@ class VuexPersistentModule extends VuexPersistence { // Overwrite plugin to use replaceState and set a custom restored prop for each module this.plugin = (store) => { - store[`${module}Restored`] = this.replaceState( - this.key, - this.storage, - store - ).then(() => { - // The subscriber is the same as in VuexPersistence, but we have to add it ourselves since we overwrite the plugin method - this.subscriber(store)((mutation, state) => { - if (this.filter(mutation)) { - this._mutex.enqueue( - this.saveState(this.key, this.reducer(state), this.storage) - ); - } + store._modules.root._children[module]._rawModule.restored = + this.replaceState(this.key, this.storage, store).then(() => { + // The subscriber is the same as in VuexPersistence, but we have to add it ourselves since we overwrite the plugin method + this.subscriber(store)((mutation, state) => { + if (this.filter(mutation)) { + this._mutex.enqueue( + this.saveState(this.key, this.reducer(state), this.storage) + ); + } + }); + this.subscribed = true; }); - this.subscribed = true; - }); }; } } diff --git a/src/store/plays.js b/src/store/plays.js index 2fa2bf3c..4ab1949e 100644 --- a/src/store/plays.js +++ b/src/store/plays.js @@ -1,6 +1,5 @@ import { index, create } from "../api/plays"; import { fetchAll } from "./actions"; -import store from "./store"; export default { namespaced: true, @@ -45,7 +44,7 @@ export default { async index({ commit, rootState }) { const generator = index(rootState.auth); try { - await store.playsRestored; + await this.restored; await fetchAll(commit, generator, "setPlays"); return true; } catch (error) { diff --git a/src/store/tracks.js b/src/store/tracks.js index fbbe0d3d..4aa545db 100644 --- a/src/store/tracks.js +++ b/src/store/tracks.js @@ -2,7 +2,6 @@ import Vue from "vue"; import { index, create, destroy, update, read, merge } from "../api/tracks"; import { fetchAll } from "./actions"; import { compareTracks } from "../comparators"; -import store from "./store"; export default { namespaced: true, @@ -101,7 +100,7 @@ export default { async index({ commit, rootState }) { const generator = index(rootState.auth); try { - await store.tracksRestored; + await this.restored; await fetchAll(commit, generator, "setTracks"); return true; } catch (error) { @@ -122,7 +121,7 @@ export default { async read({ commit, rootState }, id) { try { const track = await read(rootState.auth, id); - await store.tracksRestored; + await this.restored; commit("setTrack", { id, track }); return true; } catch (error) {