Pārlūkot izejas kodu

fix(tui): allow callers without log sink

Dax Raad 1 mēnesi atpakaļ
vecāks
revīzija
88925ec6e6
1 mainītis faili ar 4 papildinājumiem un 3 dzēšanām
  1. 4 3
      packages/tui/src/app.tsx

+ 4 - 3
packages/tui/src/app.tsx

@@ -150,7 +150,7 @@ export type TuiInput = {
   config: TuiConfig.Resolved
   onSnapshot?: () => Promise<string[]>
   pluginHost: TuiPluginHost
-  log: LogSink
+  log?: LogSink
 }
 
 function errorMessage(error: unknown) {
@@ -186,6 +186,7 @@ function isVersionGreater(left: string, right: string) {
 }
 
 export const run = Effect.fn("Tui.run")(function* (input: TuiInput) {
+  const log = input.log ?? (() => {})
   const global = yield* Global.Service
   const exit = { epilogue: undefined as string | undefined, reason: undefined as unknown }
   const result = yield* Effect.scoped(
@@ -232,7 +233,7 @@ export const run = Effect.fn("Tui.run")(function* (input: TuiInput) {
           try {
             await input.pluginHost.dispose()
           } catch (error) {
-            input.log("error", "Failed to dispose TUI plugins", { error })
+            log("error", "Failed to dispose TUI plugins", { error })
           }
         }),
       )
@@ -254,7 +255,7 @@ export const run = Effect.fn("Tui.run")(function* (input: TuiInput) {
 
         await render(() => {
           return (
-            <LogProvider log={input.log}>
+            <LogProvider log={log}>
               <ExitProvider
                 exit={(reason) => {
                   if (renderer.isDestroyed) return