-
-
Notifications
You must be signed in to change notification settings - Fork 251
Evaluate code in playground #415
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 6 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
df28d39
WIP
tom-sherman b7969a2
WIP
tom-sherman 3d98b18
WIP
tom-sherman 55b666b
WIP
tom-sherman a62ef73
Set target to es2020
tom-sherman ce9b1c6
WIP
tom-sherman e7a77fe
WIP
tom-sherman f598cd4
Add provide plugin back in
tom-sherman 4b58ab8
Track logs in state machine
tom-sherman 451bc44
Temporary next config workaround
tom-sherman 6d8e3f5
WIP
tom-sherman 481072e
WIP
tom-sherman c41ed98
Working logs pane
tom-sherman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,166 @@ | ||
// Generated by ReScript, PLEASE EDIT WITH CARE | ||
|
||
import * as Curry from "rescript/lib/es6/curry.js"; | ||
import * as React from "react"; | ||
import * as $$Worker from "../bindings/Worker.mjs"; | ||
import * as Belt_Option from "rescript/lib/es6/belt_Option.js"; | ||
import * as Caml_option from "rescript/lib/es6/caml_option.js"; | ||
|
||
var source = "EvalSource"; | ||
|
||
function make(param) { | ||
return $$Worker.make(new URL("./EvalWorker.mjs", import.meta.url).toString()); | ||
} | ||
|
||
var Config = { | ||
make: make | ||
}; | ||
|
||
var EvalWorker = $$Worker.Make(Config); | ||
|
||
function workerMessageToAction(message) { | ||
var message$1 = message.result; | ||
var forCode = message.forCode; | ||
if (message$1.TAG === /* Ok */0) { | ||
return { | ||
TAG: 1, | ||
forCode: forCode, | ||
message: message$1._0, | ||
[Symbol.for("name")]: "Success" | ||
}; | ||
} else { | ||
return { | ||
TAG: 2, | ||
forCode: forCode, | ||
message: message$1._0, | ||
[Symbol.for("name")]: "Fail" | ||
}; | ||
} | ||
} | ||
|
||
function reducer(state, action) { | ||
if (typeof state === "number") { | ||
switch (action.TAG | 0) { | ||
case /* Evaluate */0 : | ||
return { | ||
TAG: 0, | ||
_0: action._0, | ||
[Symbol.for("name")]: "Evaluating" | ||
}; | ||
case /* Success */1 : | ||
case /* Fail */2 : | ||
return state; | ||
|
||
} | ||
} else { | ||
switch (state.TAG | 0) { | ||
case /* Evaluating */0 : | ||
var code = state._0; | ||
switch (action.TAG | 0) { | ||
case /* Evaluate */0 : | ||
return state; | ||
case /* Success */1 : | ||
if (action.forCode === code) { | ||
return { | ||
TAG: 1, | ||
_0: action.message, | ||
[Symbol.for("name")]: "Evaluated" | ||
}; | ||
} else { | ||
return state; | ||
} | ||
case /* Fail */2 : | ||
if (action.forCode === code) { | ||
return { | ||
TAG: 2, | ||
_0: action.message, | ||
[Symbol.for("name")]: "Error" | ||
}; | ||
} else { | ||
return state; | ||
} | ||
|
||
} | ||
case /* Evaluated */1 : | ||
switch (action.TAG | 0) { | ||
case /* Evaluate */0 : | ||
return { | ||
TAG: 0, | ||
_0: action._0, | ||
[Symbol.for("name")]: "Evaluating" | ||
}; | ||
case /* Success */1 : | ||
case /* Fail */2 : | ||
return state; | ||
|
||
} | ||
case /* Error */2 : | ||
switch (action.TAG | 0) { | ||
case /* Evaluate */0 : | ||
return { | ||
TAG: 0, | ||
_0: action._0, | ||
[Symbol.for("name")]: "Evaluating" | ||
}; | ||
case /* Success */1 : | ||
case /* Fail */2 : | ||
return state; | ||
|
||
} | ||
|
||
} | ||
} | ||
} | ||
|
||
function useEval(param) { | ||
var match = React.useReducer(reducer, /* Idle */0); | ||
var dispatch = match[1]; | ||
var state = match[0]; | ||
var workerRef = React.useRef(undefined); | ||
React.useEffect((function () { | ||
workerRef.current = Caml_option.some(Curry._1(EvalWorker.make, undefined)); | ||
return (function (param) { | ||
Belt_Option.map(workerRef.current, (function (worker) { | ||
return Curry._1(EvalWorker.App.terminate, worker); | ||
})); | ||
|
||
}); | ||
}), []); | ||
React.useEffect((function () { | ||
var maybeWorker = workerRef.current; | ||
if (typeof state !== "number" && state.TAG === /* Evaluating */0) { | ||
var code = state._0; | ||
Belt_Option.map(maybeWorker, (function (worker) { | ||
return Curry._2(EvalWorker.App.postMessage, worker, { | ||
source: source, | ||
payload: { | ||
_0: code, | ||
[Symbol.for("name")]: "EvalMessage" | ||
} | ||
}); | ||
})); | ||
} | ||
|
||
}), [state]); | ||
return [ | ||
state, | ||
(function (code) { | ||
return Curry._1(dispatch, { | ||
TAG: 0, | ||
_0: code, | ||
[Symbol.for("name")]: "Evaluate" | ||
}); | ||
}) | ||
]; | ||
} | ||
|
||
export { | ||
source , | ||
Config , | ||
EvalWorker , | ||
workerMessageToAction , | ||
reducer , | ||
useEval , | ||
|
||
} | ||
/* EvalWorker Not a pure module */ |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without these changes I was getting type errors. I posted about it on the forum: https://forum.rescript-lang.org/t/regarding-src-bindings-worker-res-in-the-rescript-lang-org-repo/2004/2