Skip to content

Commit 1c32bf0

Browse files
refactor(assets): use createSharedComposable for useModelTypes
Wrap composable with createSharedComposable from VueUse to: - Fix HMR compatibility (state no longer lost on hot reload) - Remove import side effects from module-scoped variables - Create state lazily on first use while maintaining shared singleton behavior 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent fdf9da8 commit 1c32bf0

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/platform/assets/composables/useModelTypes.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { ref } from 'vue'
2+
import { createSharedComposable } from '@vueuse/core'
23

3-
import { assetService } from '@/platform/assets/services/assetService'
4+
import { api } from '@/scripts/api'
45

56
/**
67
* Format folder name to display name
@@ -37,17 +38,16 @@ interface ModelTypeOption {
3738
value: string // Actual tag value
3839
}
3940

40-
// Shared state across all instances
41-
const modelTypes = ref<ModelTypeOption[]>([])
42-
const isLoading = ref(false)
43-
const error = ref<string | null>(null)
44-
let fetchPromise: Promise<void> | null = null
45-
4641
/**
4742
* Composable for fetching and managing model types from the API
4843
* Uses shared state to ensure data is only fetched once
4944
*/
50-
export function useModelTypes() {
45+
export const useModelTypes = createSharedComposable(() => {
46+
const modelTypes = ref<ModelTypeOption[]>([])
47+
const isLoading = ref(false)
48+
const error = ref<string | null>(null)
49+
let fetchPromise: Promise<void> | null = null
50+
5151
/**
5252
* Fetch model types from the API (only fetches once, subsequent calls reuse the same promise)
5353
*/
@@ -67,7 +67,7 @@ export function useModelTypes() {
6767

6868
fetchPromise = (async () => {
6969
try {
70-
const response = await assetService.getModelTypes()
70+
const response = await api.getModelFolders()
7171
modelTypes.value = response.map((folder) => ({
7272
name: formatDisplayName(folder.name),
7373
value: folder.name
@@ -91,4 +91,4 @@ export function useModelTypes() {
9191
error,
9292
fetchModelTypes
9393
}
94-
}
94+
})

0 commit comments

Comments
 (0)