MCPcopy Create free account
hub / github.com/effect-app/libs / useClient

Function useClient

packages/vue/test/stubs.ts:275–310  ·  view source on GitHub ↗
(
  options?: { messages?: Record<string, string> | Record<string, MessageFormatElement[]>; toasts: any[] }
)

Source from the content-addressed store, hash-verified

273}
274
275export const useClient = (
276 options?: { messages?: Record<string, string> | Record<string, MessageFormatElement[]>; toasts: any[] }
277) => {
278 const FakeIntlLayer = fakeIntlLayer(options?.messages)
279 const FakeToastLayer = fakeToastLayer(options?.toasts)
280 const CommanderLayer = Commander.Default.pipe(Layer.provide([FakeIntlLayer, FakeToastLayer]))
281 const WithToastLayer = WithToast.Default.pipe(Layer.provide(FakeToastLayer))
282 const api = ApiClientFactory.layer({ url: "bogus", headers: Option.none() }).pipe(
283 Layer.provide(FetchHttpClient.layer)
284 )
285 const layers = Layer.mergeAll(CommanderLayer, WithToastLayer, FakeToastLayer, FakeIntlLayer, api)
286
287 const clientFor_ = ApiClientFactory.makeFor(Layer.empty)
288 const rawClient = makeClient(() => ManagedRuntime.make(layers), clientFor_, Layer.empty)
289
290 // Provide a Vue injection context so composition-API hooks called during client
291 // initialisation work outside a component setup() function.
292 const vueApp = createApp({})
293
294 const origClientFor = rawClient.clientFor
295 const clientFor: typeof origClientFor = function(m, ...args) {
296 const proxy = origClientFor(m, ...args)
297 // Warm up lazy mutation-hook initialisation inside the Vue injection context.
298 // After the first property access, useMutation() is cached and subsequent
299 // accesses outside the context succeed.
300 const firstPropertyName = Object.keys(m)[0]
301 if (firstPropertyName !== undefined) {
302 vueApp.runWithContext(() => {
303 void (proxy as Record<string, unknown>)[firstPropertyName]
304 })
305 }
306 return proxy
307 }
308
309 return { ...rawClient, clientFor }
310}

Callers 1

makeClient.test.tsFile · 0.85

Calls 6

fakeIntlLayerFunction · 0.85
fakeToastLayerFunction · 0.85
pipeMethod · 0.65
makeMethod · 0.65
makeClientFunction · 0.50
provideMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…