Skip to content

Commit

Permalink
Merge pull request #11062 from rak-phillip/chore/refactor-store-modules
Browse files Browse the repository at this point in the history
Chore/refactor store modules
  • Loading branch information
rak-phillip committed May 21, 2024
2 parents be1bad5 + 0af9528 commit 48c5b25
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 14 deletions.
1 change: 1 addition & 0 deletions shell/pages/diagnostic.vue
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ export default {
'digitalocean',
'linode',
'targetRoute', // contains circular references, isn't useful (added later to store)
'$router', // also contains a circular reference to $store, not useful for diagnostics
];
const clearListsKeys = [
Expand Down
6 changes: 4 additions & 2 deletions shell/store/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,9 @@ export const actions = {
}
},

async logout({ dispatch, commit, getters }, options = {}) {
async logout({
dispatch, commit, getters, rootState
}, options = {}) {
// So, we only do this check if auth has been initialized.
//
// It's possible to be logged in and visit auth/logout directly instead
Expand All @@ -362,7 +364,7 @@ export const actions = {
}

// Unload plugins - we will load again on login
await this.$plugin.logout();
await rootState.$plugin.logout();

try {
await dispatch('rancher/request', {
Expand Down
31 changes: 19 additions & 12 deletions shell/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,9 @@ export const state = () => {
isRancherInHarvester: false,
targetRoute: null,
rootProduct: undefined,
$router: undefined,
$route: undefined,
$plugin: undefined,
};
};

Expand Down Expand Up @@ -722,6 +725,18 @@ export const mutations = {

targetRoute(state, route) {
state.targetRoute = route;
},

setRouter(state, router) {
state.$router = router;
},

setRoute(state, route) {
state.$route = route;
},

setPlugin(state, pluginDefinition) {
state.$plugin = pluginDefinition;
}
};

Expand Down Expand Up @@ -1128,18 +1143,10 @@ export const actions = {
}
},

nuxtServerInit({ dispatch, rootState }, nuxt) {
// Models in SSR server mode have no way to get to the route or router, so hack one in...
Object.defineProperty(rootState, '$router', { value: nuxt.app.router });
Object.defineProperty(rootState, '$route', { value: nuxt.route });
dispatch('prefs/loadCookies');
},

nuxtClientInit({ dispatch, rootState }, nuxt) {
Object.defineProperty(rootState, '$router', { value: nuxt.app.router });
Object.defineProperty(rootState, '$route', { value: nuxt.route });
Object.defineProperty(rootState, '$plugin', { value: nuxt.app.$plugin });
Object.defineProperty(this, '$plugin', { value: nuxt.app.$plugin });
nuxtClientInit({ dispatch, commit, rootState }, nuxt) {
commit('setRouter', nuxt.app.router);
commit('setRoute', nuxt.route);
commit('setPlugin', nuxt.app.$plugin);

dispatch('management/rehydrateSubscribe');
dispatch('cluster/rehydrateSubscribe');
Expand Down

0 comments on commit 48c5b25

Please sign in to comment.