mirror of
https://github.com/ArthurDanjou/trpc-nuxt.git
synced 2026-01-30 19:57:54 +01:00
remove mutation composable
This commit is contained in:
@@ -28,7 +28,6 @@ export default defineNuxtModule<ModuleOptions>({
|
|||||||
imports.push(
|
imports.push(
|
||||||
{ name: 'useTrpcQuery', from: clientPath },
|
{ name: 'useTrpcQuery', from: clientPath },
|
||||||
{ name: 'useLazyTrpcQuery', from: clientPath },
|
{ name: 'useLazyTrpcQuery', from: clientPath },
|
||||||
{ name: 'useTrpcMutation', from: clientPath },
|
|
||||||
{ name: 'useClient', from: clientPath },
|
{ name: 'useClient', from: clientPath },
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
@@ -47,14 +46,12 @@ export default defineNuxtModule<ModuleOptions>({
|
|||||||
const {
|
const {
|
||||||
useTrpcQuery,
|
useTrpcQuery,
|
||||||
useLazyTrpcQuery,
|
useLazyTrpcQuery,
|
||||||
useTrpcMutation,
|
|
||||||
useClient
|
useClient
|
||||||
} = createTRPCComposables<typeof router>(client)
|
} = createTRPCComposables<typeof router>(client)
|
||||||
|
|
||||||
export {
|
export {
|
||||||
useTrpcQuery,
|
useTrpcQuery,
|
||||||
useLazyTrpcQuery,
|
useLazyTrpcQuery,
|
||||||
useTrpcMutation,
|
|
||||||
useClient
|
useClient
|
||||||
}
|
}
|
||||||
`)
|
`)
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ export function createTRPCComposables<
|
|||||||
Router extends AnyRouter,
|
Router extends AnyRouter,
|
||||||
Client extends TRPCClient<Router> = TRPCClient<Router>,
|
Client extends TRPCClient<Router> = TRPCClient<Router>,
|
||||||
TQuery extends keyof Router['_def']['queries'] = keyof Router['_def']['queries'],
|
TQuery extends keyof Router['_def']['queries'] = keyof Router['_def']['queries'],
|
||||||
TMutation extends keyof Router['_def']['mutations'] = keyof Router['_def']['mutations'],
|
|
||||||
>(
|
>(
|
||||||
client: Client
|
client: Client
|
||||||
): {
|
): {
|
||||||
@@ -41,28 +40,10 @@ export function createTRPCComposables<
|
|||||||
>,
|
>,
|
||||||
true | Error
|
true | Error
|
||||||
>
|
>
|
||||||
useTrpcMutation: <
|
|
||||||
TRouteKey extends TMutation,
|
|
||||||
ProcedureInput = inferProcedureInput<
|
|
||||||
Router['_def']['mutations'][TRouteKey]
|
|
||||||
>,
|
|
||||||
ProcedureOutput = inferProcedureOutput<
|
|
||||||
Router['_def']['mutations'][TRouteKey]
|
|
||||||
>,
|
|
||||||
>(
|
|
||||||
path: TRouteKey,
|
|
||||||
input: ProcedureInput
|
|
||||||
) => AsyncData<
|
|
||||||
PickFrom<
|
|
||||||
ProcedureOutput,
|
|
||||||
KeyOfRes<_Transform<ProcedureOutput, ProcedureOutput>>
|
|
||||||
>,
|
|
||||||
true | Error
|
|
||||||
>
|
|
||||||
useClient: () => Client
|
useClient: () => Client
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createTRPCComposables(client: any) {
|
export function createTRPCComposables(client) {
|
||||||
const useTrpcQuery = (...args) => {
|
const useTrpcQuery = (...args) => {
|
||||||
return useAsyncData(`trpc-${objectHash(args[0] + (args[1] ? JSON.stringify(args[1]) : ''))}`, () => client.query(...args))
|
return useAsyncData(`trpc-${objectHash(args[0] + (args[1] ? JSON.stringify(args[1]) : ''))}`, () => client.query(...args))
|
||||||
}
|
}
|
||||||
@@ -71,16 +52,11 @@ export function createTRPCComposables(client: any) {
|
|||||||
return useLazyAsyncData(`trpc-${objectHash(args[0] + (args[1] ? JSON.stringify(args[1]) : ''))}`, () => client.query(...args))
|
return useLazyAsyncData(`trpc-${objectHash(args[0] + (args[1] ? JSON.stringify(args[1]) : ''))}`, () => client.query(...args))
|
||||||
}
|
}
|
||||||
|
|
||||||
const useTrpcMutation = (...args) => {
|
|
||||||
return useAsyncData(`trpc-${objectHash(args[0] + (args[1] ? JSON.stringify(args[1]) : ''))}`, () => client.mutation(...args))
|
|
||||||
}
|
|
||||||
|
|
||||||
const useClient = () => client
|
const useClient = () => client
|
||||||
|
|
||||||
return {
|
return {
|
||||||
useTrpcQuery,
|
useTrpcQuery,
|
||||||
useLazyTrpcQuery,
|
useLazyTrpcQuery,
|
||||||
useTrpcMutation,
|
|
||||||
useClient,
|
useClient,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user