Skip to content

Commit bf2572f

Browse files
committed
WIP output console log
1 parent 124c474 commit bf2572f

File tree

2 files changed

+45
-56
lines changed

2 files changed

+45
-56
lines changed

src/Playground.res

Lines changed: 42 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,7 +1220,7 @@ module RenderOutput = {
12201220
| _ => None
12211221
}
12221222

1223-
let valid = switch code {
1223+
let _valid = switch code {
12241224
| Some(code) =>
12251225
switch RenderOutputManager.renderOutput(code) {
12261226
| Ok(_) => true
@@ -1229,43 +1229,40 @@ module RenderOutput = {
12291229
| None => false
12301230
}
12311231

1232-
let a =
1233-
<div className={""}>
1234-
<iframe
1235-
width="100%"
1236-
id="iframe-eval"
1237-
className="relative w-full text-gray-20"
1238-
srcDoc=RenderOutputManager.Frame.srcdoc
1239-
/>
1240-
</div>
1232+
<div className={""}>
1233+
<iframe
1234+
width="100%"
1235+
id="iframe-eval"
1236+
className="relative w-full text-gray-20"
1237+
srcDoc=RenderOutputManager.Frame.srcdoc
1238+
/>
1239+
</div>
12411240

1242-
a
1243-
1244-
// switch code {
1245-
// | Some(code) =>
1246-
// switch RenderOutputManager.renderOutput(code) {
1247-
// | Ok() =>
1248-
// <iframe
1249-
// width="100%"
1250-
// id="iframe-eval"
1251-
// className="relative w-full text-gray-20"
1252-
// srcDoc=RenderOutputManager.Frame.srcdoc
1253-
// />
1254-
// | Error() =>
1255-
// let code = `module App = {
1256-
// @react.component
1257-
// let make = () => {
1258-
// <ModuleName />
1259-
// }
1260-
// }`
1261-
// <div className={"whitespace-pre-wrap p-4 block"}>
1262-
// <p className={"mb-2"}> {React.string("To render element create a module App")} </p>
1263-
// <pre> {HighlightJs.renderHLJS(~code, ~darkmode=true, ~lang="rescript", ())} </pre>
1264-
// </div>
1265-
// }
1266-
1267-
// | _ => React.null
1268-
// }
1241+
// switch code {
1242+
// | Some(code) =>
1243+
// switch RenderOutputManager.renderOutput(code) {
1244+
// | Ok() =>
1245+
// <iframe
1246+
// width="100%"
1247+
// id="iframe-eval"
1248+
// className="relative w-full text-gray-20"
1249+
// srcDoc=RenderOutputManager.Frame.srcdoc
1250+
// />
1251+
// | Error() =>
1252+
// let code = `module App = {
1253+
// @react.component
1254+
// let make = () => {
1255+
// <ModuleName />
1256+
// }
1257+
// }`
1258+
// <div className={"whitespace-pre-wrap p-4 block"}>
1259+
// <p className={"mb-2"}> {React.string("To render element create a module App")} </p>
1260+
// <pre> {HighlightJs.renderHLJS(~code, ~darkmode=true, ~lang="rescript", ())} </pre>
1261+
// </div>
1262+
// }
1263+
1264+
// | _ => React.null
1265+
// }
12691266
}
12701267
}
12711268

@@ -1287,7 +1284,7 @@ module OutputPanel = {
12871284
*/
12881285
let prevState = React.useRef(None)
12891286

1290-
let (logs, setLogs) = React.useState(_ => None)
1287+
let (logs, setLogs) = React.useState(_ => [])
12911288

12921289
React.useEffect(() => {
12931290
Webapi.Window.addEventListener("message", e => {
@@ -1297,13 +1294,7 @@ module OutputPanel = {
12971294
if type_ === "log" {
12981295
let args: array<string> = data["args"]
12991296

1300-
// setLogs(
1301-
// previousLogs =>
1302-
// logs
1303-
// ->Belt.Option.getWithDefault([])
1304-
// ->Js.Array2.concat([args])
1305-
// ->Some,
1306-
// )
1297+
setLogs(_ => logs->Belt.Array.concat([args]))
13071298
}
13081299
})
13091300
None
@@ -1361,21 +1352,17 @@ module OutputPanel = {
13611352
</pre>
13621353

13631354
let consolePanel = switch logs {
1364-
| Some(logs) =>
1355+
| [] => React.null
1356+
| logs =>
13651357
let content =
13661358
logs
1367-
->Js.Array2.map(log =>
1368-
<pre>
1369-
{log
1370-
->Js.Array2.map(item => <span> {`${item} `->React.string} </span>)
1371-
->React.array}
1372-
</pre>
1373-
)
1359+
->Belt.Array.mapWithIndex((i, log) => {
1360+
let log = Js.Array2.joinWith(log, " ")
1361+
<pre key={Js.Int.toString(i)}> {React.string(log)} </pre>
1362+
})
13741363
->React.array
13751364

13761365
<div className="whitespace-pre-wrap p-4 block"> content </div>
1377-
1378-
| None => React.null
13791366
}
13801367

13811368
let output =

src/common/RenderOutputManager.res

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ let renderOutput = code => {
8989
| true =>
9090
Transpiler.run(transpiled)->Frame.sendOutput
9191
Ok()
92-
| false => Error()
92+
| false =>
93+
Frame.sendOutput(transpiled)
94+
Error()
9395
}
9496
}

0 commit comments

Comments
 (0)