Skip to content

Commit 53a0e79

Browse files
remove defineStore
1 parent fe04d82 commit 53a0e79

File tree

5 files changed

+23
-29
lines changed

5 files changed

+23
-29
lines changed

stores/cloud.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
import { defineStore } from 'pinia'
21
import { useStorage } from '@vueuse/core'
32

43
export const use_cloud_store = defineStore('cloud', {
54
state: () => ({
65
ID: useStorage('ID', ''),
76
is_captcha_validated: false,
8-
is_cloud_running: false,
97
is_connexion_launched: false,
108
}),
119
getters: {
@@ -26,20 +24,20 @@ export const use_cloud_store = defineStore('cloud', {
2624
viewer_url = viewer_url + '/ws'
2725
return viewer_url
2826
},
29-
is_cloud_running: (state) => {
30-
const geode_store = use_geode_store()
31-
const websocket_store = use_websocket_store()
32-
return state.is_cloud_running
27+
is_cloud_running: () => {
28+
return use_geode_store().is_client_created && use_websocket_store().is_client_created
3329
},
34-
is_cloud_busy: () => {
35-
const geode_store = use_geode_store()
36-
const websocket_store = use_websocket_store()
37-
return geode_store.api_busy() && websocket_store.websocket_busy()
30+
cloud_busy: () => {
31+
const api_busy = use_geode_store().api_busy
32+
const websocket_busy = use_geode_store().websocket_busy
33+
const cloud_busy = api_busy || websocket_busy
34+
return cloud_busy
3835
}
3936

4037
},
4138
actions: {
4239
async create_connexion () {
40+
const geode_store = use_geode_store()
4341
if (this.is_connexion_launched) { return }
4442
this.is_connexion_launched = true
4543
if (this.ID === '' || this.ID === null || typeof this.ID === 'undefined') {
@@ -48,22 +46,23 @@ export const use_cloud_store = defineStore('cloud', {
4846
const { data, error } = await useFetch(`${this.geode_url}/ping`, { method: 'POST' })
4947
console.log("error", error)
5048
if (data.value !== null) {
51-
this.is_cloud_running = true
49+
geode_store.is_client_created = true
5250
return this.ping_task()
5351
} else {
5452
return this.create_backend()
5553
}
5654
}
5755
},
5856
async create_backend () {
57+
const geode_store = use_geode_store()
5958
const errors_store = use_errors_store()
6059
const config = useRuntimeConfig()
6160
const public_runtime_config = config.public
6261
const { data, error } = await useFetch(`${public_runtime_config.GEODE_PROTOCOL}://${public_runtime_config.API_URL}:${public_runtime_config.GEODE_PORT}${public_runtime_config.SITE_BRANCH}/${public_runtime_config.PROJECT}/createbackend`, { method: 'POST' })
6362
if (data.value !== null) {
6463
this.ID = data.value.ID
6564
localStorage.setItem('ID', data.value.ID)
66-
this.is_cloud_running = true
65+
geode_store.is_client_created = true
6766
return this.ping_task()
6867
} else {
6968
console.log("error : ", error)
@@ -75,10 +74,11 @@ export const use_cloud_store = defineStore('cloud', {
7574
setInterval(() => this.do_ping(), 10 * 1000)
7675
},
7776
async do_ping () {
77+
const geode_store = use_geode_store()
7878
const errors_store = use_errors_store()
7979
const { data, error } = await useFetch(`${this.geode_url}/ping`, { method: 'POST' })
8080
if (data.value !== null) {
81-
this.is_cloud_running = true
81+
geode_store.is_client_created = true
8282
} else {
8383
errors_store.server_error = true
8484
console.log("error : ", error)

stores/errors.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { defineStore } from 'pinia'
2-
31
export const use_errors_store = defineStore('errors', {
42
state: () => ({
53
errors: [],
Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
1-
import { defineStore } from 'pinia'
2-
31
export const use_geode_store = defineStore('geode', {
42
state: () => ({
5-
request_counter: 0
3+
request_counter: 0,
4+
is_client_created: false
65
}),
76
getters: {
87
api_busy: (state) => {
98
return state.request_counter > 0
109
}
1110
},
1211
actions: {
13-
start_request (state) {
14-
state.request_counter++
12+
start_request () {
13+
this.request_counter++
1514
},
16-
stop_request (state) {
17-
state.request_counter--
15+
stop_request () {
16+
this.request_counter--
1817
}
1918
}
2019
})

stores/viewer.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { defineStore } from 'pinia'
2-
31
export const use_viewer_store = defineStore('viewer', {
42
state: () => ({
53
picking_mode: false,

stores/websocket.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { defineStore } from 'pinia'
21
import _ from 'lodash'
32

43
import vtkWSLinkClient from '@kitware/vtk.js/IO/Core/WSLinkClient'
@@ -96,10 +95,10 @@ export const use_websocket_store = defineStore('websocket', {
9695
}
9796
},
9897
},
99-
start_request (state) {
100-
state.request_counter++
98+
start_request () {
99+
this.request_counter++
101100
},
102-
stop_request (state) {
103-
state.request_counter--
101+
stop_request () {
102+
this.request_counter--
104103
}
105104
})

0 commit comments

Comments
 (0)