Skip to content

Commit

Permalink
Allow useClient to wrap around a custom JsonServiceClient
Browse files Browse the repository at this point in the history
  • Loading branch information
mythz committed May 20, 2024
1 parent b5e4fb8 commit dcdc1e5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/components/AutoQueryGrid.vue
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ import { useConfig } from '@/use/config'
const { config, autoQueryGridDefaults } = useConfig()
const aqd = autoQueryGridDefaults
const client = inject<JsonServiceClient>('client')!
const storage = config.value.storage!
const props = withDefaults(defineProps<{
Expand Down Expand Up @@ -240,6 +239,8 @@ const emit = defineEmits<{
(e: "rowSelected", item:any, ev:Event): void
}>()
const client = inject<JsonServiceClient>('client')!
const allAllow = 'filtering,queryString,queryFilters'.split(',') as GridAllowOptions[]
const allShow = 'copyApiUrl,downloadCsv,filtersView,newItem,pagingInfo,pagingNav,preferences,refresh,resetPreferences,toolbar'.split(',') as GridShowOptions[]
Expand Down
4 changes: 2 additions & 2 deletions src/use/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import { inject, provide, ref, watchEffect } from "vue"
import { ResponseError, ResponseStatus, ApiResult } from "@servicestack/client"
import { unRefs, setRef, swrApi, fromCache, swrCacheKey, createDebounce } from "./utils"

export function useClient() {
export function useClient(use?:JsonServiceClient) {
/** Maintain loading state whilst API Request is in transit */
const loading = ref(false)
/** Maintain API Error in reactive Ref<ResponseStatus> */
const error = ref()
const response = ref()
const client = inject<JsonServiceClient>('client')!
const client = use ?? inject<JsonServiceClient>('client')!

/** Set error state with summary or field validation error */
function setError({ message, errorCode, fieldName, errors }: IResponseStatus) {
Expand Down

0 comments on commit dcdc1e5

Please sign in to comment.