Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reset Vuex state when returning to game selection to free up memory #1385

Merged
merged 6 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/pages/GameSelectionScreen.vue
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,8 @@ export default class GameSelectionScreen extends Vue {
await this.$store.dispatch('checkMigrations');
this.runningMigration = false;

await this.$store.dispatch('resetLocalState');

this.settings = await ManagerSettings.getSingleton(GameManager.defaultGame);
const globalSettings = this.settings.getContext().global;
this.favourites = globalSettings.favouriteGames || [];
Expand Down
10 changes: 9 additions & 1 deletion src/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,15 @@ export const store = {
const settings = await ManagerSettings.getSingleton(game);
commit('setSettings', settings);
return settings;
}
},

async resetLocalState({commit, dispatch}: Context) {
commit('profile/reset');
commit('profiles/reset');
commit('tsMods/reset');
commit('modFilters/reset');
await dispatch('resetActiveGame');
},
},
mutations: {
setActiveGame(state: State, game: Game) {
Expand Down
2 changes: 1 addition & 1 deletion src/store/modules/ModFilterModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ interface State {
}

/**
* State for OnlineModList, i.e. list for all the mods available on Thunderstore.
* State for ModFilter, i.e. filters for mod listings.
*/
export default {
namespaced: true,
Expand Down
9 changes: 9 additions & 0 deletions src/store/modules/ProfileModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,15 @@ export default {
},

mutations: {
reset(state: State) {
state.modList = [];
state.order = undefined;
state.direction = undefined;
state.disabledPosition = undefined;
state.searchQuery = '';
state.dismissedUpdateAll = false;
},

dismissUpdateAll(state: State) {
state.dismissedUpdateAll = true;
},
Expand Down
3 changes: 3 additions & 0 deletions src/store/modules/ProfilesModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ export const ProfilesModule = {
setProfileList(state: State, profileList: string[]) {
state.profileList = profileList;
},
reset(state: State) {
state.profileList = ['Default'];
},
},
actions: <ActionTree<State, RootState>>{
async addProfile({rootGetters, state, dispatch}, name: string) {
Expand Down
8 changes: 8 additions & 0 deletions src/store/modules/TsModsModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,14 @@ export const TsModsModule = {
},

mutations: <MutationTree<State>>{
reset(state: State) {
state.cache = new Map<string, CachedMod>();
state.connectionError = '';
state.deprecated = new Map<string, boolean>();
state.exclusions = [];
state.mods = [];
state.modsLastUpdated = undefined;
},
clearModCache(state) {
state.cache.clear();
},
Expand Down
Loading