From fa0223bdafee570a436aa192a78808b384c1aa60 Mon Sep 17 00:00:00 2001 From: vishalbalaji Date: Sat, 3 Aug 2024 19:22:18 +0530 Subject: [PATCH] docs: fix tabs in readme [skip ci] --- @lib/README.md | 96 +++++++++++++++++++++++++------------------------- 1 file changed, 48 insertions(+), 48 deletions(-) diff --git a/@lib/README.md b/@lib/README.md index cd2365f..e350281 100644 --- a/@lib/README.md +++ b/@lib/README.md @@ -53,15 +53,15 @@ The following instructions assume the `tRPC` router to have the following proced ```typescript export const router = t.router({ - greeting: t.procedure - .input((name: unknown) => { - if (typeof name === 'string') return name; - - throw new Error(`Invalid input: ${typeof name}`); - }) - .query(async ({ input }) => { - return `Hello, ${input} from tRPC v10 @ ${new Date().toLocaleTimeString()}`; - }), + greeting: t.procedure + .input((name: unknown) => { + if (typeof name === 'string') return name; + + throw new Error(`Invalid input: ${typeof name}`); + }) + .query(async ({ input }) => { + return `Hello, ${input} from tRPC v10 @ ${new Date().toLocaleTimeString()}`; + }), }); export type Router = typeof router; @@ -81,12 +81,12 @@ import { createTRPCProxyClient, httpBatchLink } from '@trpc/client'; import { svelteQueryWrapper } from 'trpc-svelte-query-adapter'; const client = createTRPCProxyClient({ - links: [ - httpBatchLink({ - // Replace this URL with that of your tRPC server - url: 'http://localhost:5000/api/v1/trpc/', - }), - ], + links: [ + httpBatchLink({ + // Replace this URL with that of your tRPC server + url: 'http://localhost:5000/api/v1/trpc/', + }), + ], }); export const trpc = svelteQueryWrapper({ client }); @@ -122,19 +122,19 @@ Here is an example of what that might look like: import type { QueryClient } from '@tanstack/svelte-query'; const client = createTRPCProxyClient({ - links: [ - httpBatchLink({ - // Replace this URL with that of your tRPC server - url: 'http://localhost:5000/api/v1/trpc/', - }), - ], + links: [ + httpBatchLink({ + // Replace this URL with that of your tRPC server + url: 'http://localhost:5000/api/v1/trpc/', + }), + ], }); export function trpc(queryClient?: QueryClient) { - return svelteQueryWrapper({ - client, - queryClient, - }); + return svelteQueryWrapper({ + client, + queryClient, + }); } ``` @@ -166,11 +166,11 @@ The main thing that needs to passed in to `svelteQueryWrapper` is the `tRPC` cli let browserClient: ReturnType>; export function trpc(init?: TRPCClientInit) { - const isBrowser = typeof window !== 'undefined'; - if (isBrowser && browserClient) return browserClient; - const client = createTRPCClient({ init }); - if (isBrowser) browserClient = client; - return client; + const isBrowser = typeof window !== 'undefined'; + if (isBrowser && browserClient) return browserClient; + const client = createTRPCClient({ init }); + if (isBrowser) browserClient = client; + return client; } ``` @@ -183,14 +183,14 @@ import type { QueryClient } from '@tanstack/svelte-query'; let browserClient: ReturnType>; export function trpc(init?: TRPCClientInit, queryClient?: QueryClient) { - const isBrowser = typeof window !== 'undefined'; - if (isBrowser && browserClient) return browserClient; - const client = svelteQueryWrapper({ - client: createTRPCClient({ init }), - queryClient, - }); - if (isBrowser) browserClient = client; - return client; + const isBrowser = typeof window !== 'undefined'; + if (isBrowser && browserClient) return browserClient; + const client = svelteQueryWrapper({ + client: createTRPCClient({ init }), + queryClient, + }); + if (isBrowser) browserClient = client; + return client; } ``` @@ -214,16 +214,16 @@ import { trpc } from '$lib/trpc/client'; import type { PageLoad } from './$types'; export const load = (async (event) => { - const { queryClient } = await event.parent(); - const client = trpc(event, queryClient); - - return { - foo: await client.greeting.createServerQuery('foo'), - queries: await client.createServerQueries( - (t) => - ['bar', 'baz'].map((name) => t.greeting(name, { ssr: name !== 'baz' })) // pre-fetching disabled for the `baz` query. - ), - }; + const { queryClient } = await event.parent(); + const client = trpc(event, queryClient); + + return { + foo: await client.greeting.createServerQuery('foo'), + queries: await client.createServerQueries( + (t) => + ['bar', 'baz'].map((name) => t.greeting(name, { ssr: name !== 'baz' })) // pre-fetching disabled for the `baz` query. + ), + }; }) satisfies PageLoad; ```