Skip to content

Commit a93225c

Browse files
committed
importStore & exportStore refacto
1 parent bb9d02d commit a93225c

File tree

6 files changed

+38
-46
lines changed

6 files changed

+38
-46
lines changed

plugins/project_manager.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export default defineNuxtPlugin(() => {
66
const appStore = useAppStore()
77

88
async function exportProject() {
9-
const snapshot = appStore.save()
9+
const snapshot = appStore.exportStore()
1010
const blob = new Blob([JSON.stringify(snapshot)], {
1111
type: "application/json",
1212
})
@@ -22,7 +22,7 @@ export default defineNuxtPlugin(() => {
2222
const snapshot = JSON.parse(await file.text())
2323
await useInfraStore().create_connection()
2424
viewer_call({})
25-
await appStore.load(snapshot)
25+
await appStore.importStore(snapshot)
2626
}
2727

2828
return {

stores/app.js

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,79 +5,71 @@ export const useAppStore = defineStore("app", () => {
55
const isAlreadyRegistered = stores.some(
66
(registeredStore) => registeredStore.$id === store.$id,
77
)
8-
98
if (isAlreadyRegistered) {
109
console.log(
1110
`[AppStore] Store "${store.$id}" already registered, skipping`,
1211
)
1312
return
1413
}
15-
1614
console.log("[AppStore] Registering store", store.$id)
1715
stores.push(store)
1816
}
1917

20-
function save() {
18+
19+
function exportStore() {
2120
const snapshot = {}
22-
let savedCount = 0
21+
let exportCount = 0
2322

2423
for (const store of stores) {
25-
if (!store.save) {
24+
if (!store.exportStore) {
2625
continue
2726
}
2827
const storeId = store.$id
2928
try {
30-
snapshot[storeId] = store.save()
31-
savedCount++
29+
snapshot[storeId] = store.exportStore()
30+
exportCount++
3231
} catch (error) {
33-
console.error(`[AppStore] Error saving store "${storeId}":`, error)
32+
console.error(`[AppStore] Error exporting store "${storeId}":`, error)
3433
}
3534
}
36-
37-
console.log(`[AppStore] Saved ${savedCount} stores`)
35+
console.log(`[AppStore] Exported ${exportCount} stores`)
3836
return snapshot
3937
}
4038

41-
async function load(snapshot) {
39+
40+
async function importStore(snapshot) {
4241
if (!snapshot) {
43-
console.warn("[AppStore] load called with invalid snapshot")
42+
console.warn("[AppStore] import called with invalid snapshot")
4443
return
4544
}
46-
47-
let loadedCount = 0
45+
let importedCount = 0
4846
const notFoundStores = []
49-
5047
for (const store of stores) {
51-
if (!store.load) continue
52-
48+
if (!store.importStore) continue
5349
const storeId = store.$id
54-
5550
if (!snapshot[storeId]) {
5651
notFoundStores.push(storeId)
5752
continue
5853
}
59-
6054
try {
61-
await store.load(snapshot[storeId])
62-
loadedCount++
55+
await store.importStore(snapshot[storeId])
56+
importedCount++
6357
} catch (error) {
64-
console.error(`[AppStore] Error loading store "${storeId}":`, error)
58+
console.error(`[AppStore] Error importing store "${storeId}":`, error)
6559
}
6660
}
67-
6861
if (notFoundStores.length > 0) {
6962
console.warn(
7063
`[AppStore] Stores not found in snapshot: ${notFoundStores.join(", ")}`,
7164
)
7265
}
73-
74-
console.log(`[AppStore] Loaded ${loadedCount} stores`)
66+
console.log(`[AppStore] Imported ${importedCount} stores`)
7567
}
7668

7769
return {
7870
stores,
7971
registerStore,
80-
save,
81-
load,
72+
exportStore,
73+
importStore,
8274
}
8375
})

stores/data_base.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,11 @@ export const useDataBaseStore = defineStore("dataBase", () => {
135135
return flat_indexes.filter((index) => index !== null)
136136
}
137137

138-
function save() {
138+
function exportStore() {
139139
return { db: JSON.parse(JSON.stringify(db)) }
140140
}
141141

142-
async function load(snapshot) {
142+
async function importStore(snapshot) {
143143
const entries = snapshot?.db || {}
144144
const hybrid_store = useHybridViewerStore()
145145
await hybrid_store.initHybridViewer()
@@ -164,7 +164,7 @@ export const useDataBaseStore = defineStore("dataBase", () => {
164164
getSurfacesUuids,
165165
getBlocksUuids,
166166
getFlatIndexes,
167-
save,
168-
load,
167+
exportStore,
168+
importStore,
169169
}
170170
})

stores/data_style.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ export const useDataStyleStore = defineStore("dataStyle", () => {
4646
return modelStyleStore.modelMeshComponentVisibility(id, "Edge", null)
4747
}
4848

49-
function save() {
49+
function exportStore() {
5050
return { styles: dataStyleState.styles }
5151
}
5252

53-
async function load(snapshot) {
53+
async function importStore(snapshot) {
5454
dataStyleState.styles = snapshot?.styles || {}
5555
}
5656

@@ -60,8 +60,8 @@ export const useDataStyleStore = defineStore("dataStyle", () => {
6060
setVisibility,
6161
setModelEdgesVisibility,
6262
modelEdgesVisibility,
63-
save,
64-
load,
63+
exportStore,
64+
importStore,
6565
...meshStyleStore,
6666
...modelStyleStore,
6767
}

stores/hybrid_viewer.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,11 +192,11 @@ export const useHybridViewerStore = defineStore("hybridViewer", () => {
192192
Object.keys(db).forEach((id) => delete db[id])
193193
}
194194

195-
function save() {
195+
function exportStore() {
196196
return { zScale: zScale.value }
197197
}
198198

199-
async function load(snapshot) {
199+
async function importStore(snapshot) {
200200
const z_scale = snapshot?.zScale
201201
if (z_scale != null) {
202202
await setZScaling(z_scale)
@@ -215,7 +215,7 @@ export const useHybridViewerStore = defineStore("hybridViewer", () => {
215215
setContainer,
216216
zScale,
217217
clear,
218-
save,
219-
load,
218+
exportStore,
219+
importStore,
220220
}
221221
})

stores/treeview.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,18 @@ export const useTreeviewStore = defineStore("treeview", () => {
5353
panelWidth.value = width
5454
}
5555

56-
function save() {
56+
function exportStore() {
5757
return {
5858
isAdditionnalTreeDisplayed: isAdditionnalTreeDisplayed.value,
5959
panelWidth: panelWidth.value,
6060
model_id: model_id.value,
6161
isTreeCollection: isTreeCollection.value,
6262
selectedTree: selectedTree.value,
63-
selection: selection.value, // Keep for UX ?
63+
selection: selection.value,
6464
}
6565
}
6666

67-
function load(snapshot) {
67+
async function importStore(snapshot) {
6868
selection.value = snapshot?.selection || []
6969
isAdditionnalTreeDisplayed.value =
7070
snapshot?.isAdditionnalTreeDisplayed || false
@@ -87,7 +87,7 @@ export const useTreeviewStore = defineStore("treeview", () => {
8787
displayFileTree,
8888
toggleTreeView,
8989
setPanelWidth,
90-
save,
91-
load,
90+
exportStore,
91+
importStore,
9292
}
9393
})

0 commit comments

Comments
 (0)