From 2767d13fcb9fb05ebe9077a30a4b3a6880a4c80b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20Tsnobiladz=C3=A9?= Date: Fri, 24 May 2024 16:16:02 +0200 Subject: [PATCH 01/10] render react --- src/ConsolePanel.res | 19 +---- src/Playground.res | 127 ++++++----------------------- src/RenderPanel.res | 33 ++++++++ src/common/EvalIFrame.res | 13 ++- src/common/RenderOutputManager.res | 21 ----- 5 files changed, 66 insertions(+), 147 deletions(-) create mode 100644 src/RenderPanel.res delete mode 100644 src/common/RenderOutputManager.res diff --git a/src/ConsolePanel.res b/src/ConsolePanel.res index 2777aea2b..04833c5ff 100644 --- a/src/ConsolePanel.res +++ b/src/ConsolePanel.res @@ -5,9 +5,7 @@ type logLevel = [ ] @react.component -let make = (~compilerState, ~runOutput) => { - let (logs, setLogs) = React.useState(_ => []) - +let make = (~logs, ~setLogs) => { React.useEffect(() => { let cb = e => { let data = e["data"] @@ -22,20 +20,6 @@ let make = (~compilerState, ~runOutput) => { Some(() => Webapi.Window.removeEventListener("message", cb)) }, []) - React.useEffect(() => { - if runOutput { - switch compilerState { - | CompilerManagerHook.Ready({result: Comp(Success({js_code}))}) => - setLogs(_ => []) - let ast = AcornParse.parse(js_code) - let transpiled = AcornParse.removeImportsAndExports(ast) - EvalIFrame.sendOutput(transpiled) - | _ => () - } - } - None - }, (compilerState, runOutput)) -
{switch logs { | [] => React.null @@ -58,6 +42,5 @@ let make = (~compilerState, ~runOutput) => {
content
}} -
} diff --git a/src/Playground.res b/src/Playground.res index c42eb3be5..817fdf800 100644 --- a/src/Playground.res +++ b/src/Playground.res @@ -22,7 +22,7 @@ open CompilerManagerHook module Api = RescriptCompilerApi type layout = Column | Row -type tab = JavaScript | Problems | Settings | Console +type tab = JavaScript | RenderOutput | Console | Problems | Settings let breakingPoint = 1024 module DropdownSelect = { @@ -1204,67 +1204,6 @@ let locMsgToCmError = (~kind: CodeMirror.Error.kind, locMsg: Api.LocMsg.t): Code } } -// module RenderOutput = { -// @react.component -// let make = (~compilerState: CompilerManagerHook.state) => { -// React.useEffect(() => { -// let code = switch compilerState { -// | Ready(ready) => -// switch ready.result { -// | Comp(Success(_)) => ControlPanel.codeFromResult(ready.result)->Some -// | _ => None -// } -// | _ => None -// } - -// let _valid = switch code { -// | Some(code) => -// switch RenderOutputManager.renderOutput(code) { -// | Ok(_) => true -// | Error(_) => false -// } -// | None => false -// } -// None -// }, [compilerState]) - -//
-//