Skip to content

Commit

Permalink
chore: useApplicationStore should not reset refs
Browse files Browse the repository at this point in the history
  • Loading branch information
SteKoe committed Dec 16, 2022
1 parent eae2fed commit 8174e76
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,40 @@ import { ref } from 'vue';
import ApplicationStore from '../store.js';

let applicationStore;
const applications = ref([]);
const applicationsInitialized = ref(false);
const error = ref(null);

export function createApplicationStore() {
applicationStore = new ApplicationStore();
console.log('createApplicationStore');
return applicationStore;
}

export function useApplicationStore() {
const applications = ref([]);
const applicationsInitialized = ref(false);
const error = ref(null);

applicationStore.addEventListener('connected', () => {
console.log('connected');
applicationsInitialized.value = true;
error.value = null;
});

applicationStore.addEventListener('changed', (newApplications) => {
console.log('changed');
applicationsInitialized.value = true;
applications.value = newApplications;
error.value = null;
});

applicationStore.addEventListener('error', (errorResponse) => {
console.log('error');
applicationsInitialized.value = true;
error.value = errorResponse;
});

applicationStore.addEventListener('removed', () => {
console.log('removed');
applicationsInitialized.value = false;
});

return { applications, applicationsInitialized, error, applicationStore };
}
12 changes: 6 additions & 6 deletions spring-boot-admin-server-ui/src/main/frontend/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ const app = createApp({

onBeforeMount(() => {
applicationStore.start();
})
});

onBeforeUnmount(() => {
applicationStore.stop();
})
});

return () => h(sbaShell, props);
},
Expand All @@ -98,10 +98,10 @@ installables.forEach((view) => {
try {
view.configure
? view.configure({
vue,
i18n: vue.$i18n,
axios,
})
vue,
i18n: vue.$i18n,
axios,
})
: void 0;
} catch (e) {
console.error(`Error configuring view ${view}`, e);
Expand Down

0 comments on commit 8174e76

Please sign in to comment.