Nasr galal
Nasr galal
NNuxt
Created by Nasr galal on 4/24/2024 in #❓・help
Trying to dynamically provide an API services composable
Hey ninjas, I came through creating an API service that loads firebase or restful API. I made it as a composable and it might be my fault because it is not working properly in the root of composables directory, here is the setup:
import { useApiServiceStore } from '~/store/api-service'
import { initFirebaseApi } from '~/composables/firebase'
import { initRestApi } from '~/composables/rest'

export function useApiServices() {
const { isFirebase, isRest } = useApiServiceStore()
const firebaseApi = () => initFirebaseApi()
const restApi = () => initRestApi()

return isFirebase ? firebaseApi : restApi
}
import { useApiServiceStore } from '~/store/api-service'
import { initFirebaseApi } from '~/composables/firebase'
import { initRestApi } from '~/composables/rest'

export function useApiServices() {
const { isFirebase, isRest } = useApiServiceStore()
const firebaseApi = () => initFirebaseApi()
const restApi = () => initRestApi()

return isFirebase ? firebaseApi : restApi
}
The idea I came up with is to use store parameters enabling the admin to choose the desired API service, what I've noticed is that it is not loading all the composable, or the IDE cannot see the definitions since I am using typescript. any insights will be appreciated 🙂
19 replies