mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-14 20:19:34 +01:00
Co-authored-by: Daniel Roe <daniel@roe.dev> Co-authored-by: Sébastien Chopin <seb@nuxt.com>
20 lines
537 B
TypeScript
20 lines
537 B
TypeScript
const useComponentsMetaState = () => useState('components-meta', () => ({}))
|
|
|
|
export async function fetchComponentMeta (name: string) {
|
|
const state = useComponentsMetaState()
|
|
|
|
if (state.value[name]?.then) {
|
|
await state.value[name]
|
|
return state.value[name]
|
|
}
|
|
if (state.value[name]) { return state.value[name] }
|
|
|
|
// Store promise to avoid multiple calls
|
|
state.value[name] = $fetch(`/api/component-meta/${name}`).then((meta) => {
|
|
state.value[name] = meta
|
|
})
|
|
|
|
await state.value[name]
|
|
return state.value[name]
|
|
}
|