From 858e2a6392c3010c3f8d2238e21df744ea6082ec Mon Sep 17 00:00:00 2001 From: Alexey Velikiy Date: Mon, 1 Nov 2021 03:30:45 +0300 Subject: [PATCH] status vs sttore --- client/src/store/index.ts | 33 +++++++++++++++++++++++++++++---- client/src/views/Home.vue | 3 --- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/client/src/store/index.ts b/client/src/store/index.ts index bc2391a..e2564fe 100644 --- a/client/src/store/index.ts +++ b/client/src/store/index.ts @@ -2,19 +2,40 @@ import { auth } from "./auth.module"; import { createStore } from 'vuex' import { getStatusGenerator } from "@/services/analytics.service"; -const SET_ANALYTICS_STATUS = 'setAnalyticsStatus'; +// import { notify } from "@kyvg/vue3-notification"; -export default createStore({ + +const SET_ANALYTICS_STATUS = 'SET_ANALYTICS_STATUS'; +const _SET_STATUS_GENERATOR = '_SET_STATUS_GENERATOR'; + +type State = { + analyticStatus: string, + _statusGenerator: AsyncIterableIterator +} + +const store = createStore({ state: { - analyticStatus: 'loading...' + analyticStatus: 'loading...', + _statusGenerator: null }, mutations: { [SET_ANALYTICS_STATUS](state, status: string) { state.analyticStatus = status; + }, + + [_SET_STATUS_GENERATOR](state, generator: AsyncIterableIterator) { + this._statusGenerator = generator; } }, actions: { - async runStatusGenerator({commit}) { + async _runStatusGenerator({commit, state}) { + // notify({ + // title: "Authorization", + // text: "You have been logged in!", + // }); + if(state._statusGenerator !== null) { + return; + } const g = getStatusGenerator(); for await (const data of g) { // this.status = data.toLowerCase(); @@ -26,3 +47,7 @@ export default createStore({ auth } }) + +store.dispatch('_runStatusGenerator'); + +export default store; diff --git a/client/src/views/Home.vue b/client/src/views/Home.vue index f12802f..2d74f2a 100644 --- a/client/src/views/Home.vue +++ b/client/src/views/Home.vue @@ -32,9 +32,6 @@ export default defineComponent({ clearAllLabeling() { this.$refs.graph.rerender(); } - }, - mounted: function name() { - this.$store.dispatch('runStatusGenerator'); } });