Skip to content

Commit

Permalink
fix: missing resolve import
Browse files Browse the repository at this point in the history
  • Loading branch information
johannschopplich committed Oct 7, 2022
1 parent 71c05c6 commit b8bef1f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
12 changes: 2 additions & 10 deletions src/runtime/composables/useApiData.ts
@@ -1,13 +1,11 @@
import { computed } from 'vue'
import { hash } from 'ohash'
import type { ComputedRef, Ref } from 'vue'
import type { FetchError } from 'ohmyfetch'
import type { AsyncData, AsyncDataOptions, UseFetchOptions } from 'nuxt/app'
import { apiServerRoute, headersToObject } from '../utils'
import { apiServerRoute, headersToObject, resolveUnref } from '../utils'
import type { MaybeComputedRef } from '../utils'
import { useAsyncData } from '#imports'

export type MaybeComputedRef<T> = (() => T) | ComputedRef<T> | Ref<T> | T

export type UseApiDataOptions<T> = Pick<
UseFetchOptions<T>,
// Pick from `AsyncDataOptions`
Expand Down Expand Up @@ -65,9 +63,3 @@ export function useApiData<T = any>(
asyncDataOptions,
) as AsyncData<T, FetchError | null | true>
}

function resolveUnref<T>(r: MaybeComputedRef<T>): T {
return typeof r === 'function'
? (r as any)()
: unref(r)
}
11 changes: 11 additions & 0 deletions src/runtime/utils.ts
@@ -1,5 +1,16 @@
import { unref } from 'vue'
import type { ComputedRef, Ref } from 'vue'

export type MaybeComputedRef<T> = (() => T) | ComputedRef<T> | Ref<T> | T

export const apiServerRoute = '/api/__api_party__'

export function resolveUnref<T>(r: MaybeComputedRef<T>): T {
return typeof r === 'function'
? (r as any)()
: unref(r)
}

export function headersToObject(headers: HeadersInit = {}): Record<string, string> {
// SSR compatibility for `Headers` prototype
if (typeof Headers !== 'undefined' && headers instanceof Headers)
Expand Down

0 comments on commit b8bef1f

Please sign in to comment.