mirror of
https://github.com/ArthurDanjou/trpc-nuxt.git
synced 2026-01-14 12:14:40 +01:00
feat: add reactive inputs
This commit is contained in:
@@ -4,7 +4,7 @@ import { createFlatProxy, createRecursiveProxy } from '@trpc/server/shared'
|
||||
import { hash } from 'ohash'
|
||||
import { type DecoratedProcedureRecord } from './types'
|
||||
// @ts-expect-error: Nuxt auto-imports
|
||||
import { getCurrentInstance, onScopeDispose, useAsyncData } from '#imports'
|
||||
import { getCurrentInstance, onScopeDispose, useAsyncData, unref } from '#imports'
|
||||
|
||||
/**
|
||||
* Calculates the key used for `useAsyncData` call.
|
||||
@@ -54,8 +54,8 @@ export function createNuxtProxyDecoration<TRouter extends AnyRouter> (name: stri
|
||||
controller = typeof AbortController !== 'undefined' ? new AbortController() : {} as AbortController
|
||||
}
|
||||
|
||||
const queryKey = getQueryKey(path, input)
|
||||
return useAsyncData(queryKey, () => (client as any)[path].query(input, {
|
||||
const queryKey = getQueryKey(path, unref(input))
|
||||
return useAsyncData(queryKey, () => (client as any)[path].query(unref(input), {
|
||||
signal: controller?.signal,
|
||||
...trpc
|
||||
}), asyncDataOptions)
|
||||
|
||||
@@ -19,6 +19,7 @@ import type {
|
||||
KeysOf,
|
||||
PickFrom,
|
||||
} from 'nuxt/dist/app/composables/asyncData'
|
||||
import type { Ref } from 'vue'
|
||||
|
||||
interface TRPCRequestOptions extends _TRPCRequestOptions {
|
||||
abortOnUnmount?: boolean
|
||||
@@ -44,6 +45,8 @@ type SubscriptionResolver<
|
||||
]
|
||||
) => Unsubscribable
|
||||
|
||||
type MaybeRef<T> = T | Ref<T>
|
||||
|
||||
type DecorateProcedure<
|
||||
TProcedure extends AnyProcedure,
|
||||
TRouter extends AnyRouter,
|
||||
@@ -55,7 +58,7 @@ type DecorateProcedure<
|
||||
DataT = ResT,
|
||||
PickKeys extends KeysOf<DataT> = KeysOf<DataT>,
|
||||
>(
|
||||
input: inferProcedureInput<TProcedure>,
|
||||
input: MaybeRef<inferProcedureInput<TProcedure>>,
|
||||
opts?: AsyncDataOptions<ResT, DataT, PickKeys> & { trpc?: TRPCRequestOptions },
|
||||
) => AsyncData<PickFrom<DataT, PickKeys>, DataE>,
|
||||
query: Resolver<TProcedure>
|
||||
|
||||
Reference in New Issue
Block a user