@@ -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} ) 
0 commit comments