-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch to monaco editor for playground and put parser in worker
- Loading branch information
Showing
15 changed files
with
1,771 additions
and
1,564 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/bin/bash | ||
esy js-release | ||
yarn bs:build | ||
yarn fpack | ||
yarn fpack-worker |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"entryPoints": ["lib/js/src_js/Worker.bs.js"], | ||
"outputDir": "docs/worker", | ||
"outputFilename": "worker.js" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
{ | ||
"entryPoints": ["lib/js/src_js/Entry.bs.js"], | ||
"preprocess": [] | ||
"outputDir": "docs/index", | ||
"outputFilename": "index.js" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,34 @@ | ||
module Reason = { | ||
type a; | ||
[@bs.module "reason"] external printML: a => string = "printML"; | ||
[@bs.module "reason"] external printRE: a => string = "printRE"; | ||
[@bs.module "reason"] external parseML: string => a = "parseML"; | ||
}; | ||
let worker = WebWorkers.create_webworker("../worker/worker.js"); | ||
|
||
module Ansi = { | ||
type t = {ansi_to_html: (. string) => string}; | ||
[@bs.new] [@bs.module "ansi_up"] external ansi_up: unit => t = "default"; | ||
let instance = ansi_up(); | ||
}; | ||
let set_printed: ref(option(Belt.Result.t(string, string) => unit)) = | ||
ref(None); | ||
WebWorkers.onMessage( | ||
worker, | ||
(e: WebWorkers.MessageEvent.t) => { | ||
let data = WebWorkers.MessageEvent.data(e); | ||
|
||
[@bs.val] | ||
[@bs.module "./../../../_build/default/src/js/re_typescript_js.bc.js"] | ||
external run: string => string = "run"; | ||
let run = | ||
Debouncer.makeCancelable( | ||
((value, re, setPrinted: Belt.Result.t(string, string) => unit)) => | ||
setPrinted( | ||
try( | ||
Ok( | ||
(re ? Reason.printRE : Reason.printML)( | ||
Reason.parseML(run(value)), | ||
), | ||
) | ||
) { | ||
| e => | ||
Error( | ||
Ansi.instance.ansi_to_html(. | ||
Js.Exn.asJsExn(e) | ||
->Belt.Option.flatMap(Js.Exn.message) | ||
->Belt.Option.getWithDefault("ERROR"), | ||
), | ||
) | ||
}, | ||
) | ||
); | ||
switch (set_printed^) { | ||
| None => () | ||
| Some(set_printed) => | ||
set_printed( | ||
data##status === "success" ? Ok(data##data) : Error(data##data), | ||
) | ||
}; | ||
}, | ||
); | ||
|
||
let usePrintedValue = (~re=true, value: string) => { | ||
let (printed, setPrinted) = React.useReducer((_, v) => v, Ok("")); | ||
set_printed := Some(setPrinted); | ||
|
||
React.useEffect2( | ||
() => { | ||
run.schedule((value, re, setPrinted)); | ||
WebWorkers.postMessage(worker, {"value": value, "re": re}); | ||
|
||
Some(() => {run.cancel()}); | ||
None; | ||
}, | ||
(re, value), | ||
); | ||
|
||
printed; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
module Reason = { | ||
type a; | ||
[@bs.module "reason"] external printML: a => string = "printML"; | ||
[@bs.module "reason"] external printRE: a => string = "printRE"; | ||
[@bs.module "reason"] external parseML: string => a = "parseML"; | ||
}; | ||
|
||
module Ansi = { | ||
type t = {ansi_to_html: (. string) => string}; | ||
[@bs.new] [@bs.module "ansi_up"] external ansi_up: unit => t = "default"; | ||
let instance = ansi_up(); | ||
}; | ||
|
||
[@bs.val] | ||
[@bs.module "./../../../_build/default/src/js/re_typescript_js.bc.js"] | ||
external run: string => string = "run"; | ||
let run = (value, re) => | ||
try( | ||
Ok((re ? Reason.printRE : Reason.printML)(Reason.parseML(run(value)))) | ||
) { | ||
| e => | ||
Error( | ||
Ansi.instance.ansi_to_html(. | ||
Js.Exn.asJsExn(e) | ||
->Belt.Option.flatMap(Js.Exn.message) | ||
->Belt.Option.getWithDefault("ERROR"), | ||
), | ||
) | ||
}; | ||
|
||
WebWorkers.setWorkerOnMessage( | ||
WebWorkers.self, | ||
(e: WebWorkers.MessageEvent.t) => { | ||
let data = WebWorkers.MessageEvent.data(e); | ||
( | ||
switch (run(data##value, data##re)) { | ||
| Ok(data) => {"status": "success", "data": data} | ||
| Error(data) => {"status": "error", "data": data} | ||
} | ||
) | ||
|> WebWorkers.postMessageFromWorker; | ||
}, | ||
); |
Oops, something went wrong.