Skip to content

Playground output result #420

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

Conversation

diogomqbm
Copy link
Contributor

@diogomqbm diogomqbm commented Aug 7, 2021

Description

I've been doing this for a while and forgot to upload it here. After I saw #415, I thought that we can join forces to finish this task.

🚨 Attention 🚨

In order to merge this, we should create an official bundle where we make the standard library available globally. Then, we should change it here.

Closes #414

cc @tom-sherman @ryyppy

@diogomqbm
Copy link
Contributor Author

diogomqbm commented Aug 7, 2021

I've also created a constraint that the module App should always exist because it is the one being called inside the iframe. If you have a better solution, please let me know.

@tom-sherman
Copy link

tom-sherman commented Aug 8, 2021

Nice, would be interested to hear about the trade offs between iframe vs worker execution!

Now I need to figure out how to eval the code as the user types it

I don't know if you would want to execute the code as you type - I haven't used a REPL/playground that works like this.

I was basing the UX in my PR off of the TypeScript playground. Added a "Run" button next to format and was planning to allow Ctrl+Return for running too.

image

@diogomqbm
Copy link
Contributor Author

diogomqbm commented Aug 8, 2021

...would be interested to hear about the trade-offs between iframe vs worker execution!

I followed the svelte-repl approach which uses both background workers and iframe. The thing is that the background worker should be used to compile and bundle. After that, you send the code to be evaluated inside the iframe as I did.

Since we're not bundling multiple files as in Svelte's and the compiler is already handled, I focused on the logic to evaluate code and make sure it executes.

Thanks for the suggestion @tom-sherman. Indeed executing as the user types may not be a good approach.

Comment on lines +1176 to +1189
let codeFromResult = (result: FinalResult.t): string => {
open Api
switch result {
| FinalResult.Comp(comp) =>
switch comp {
| CompilationResult.Success({js_code}) => js_code
| UnexpectedError(_)
| Unknown(_, _)
| Fail(_) => "/* No JS code generated */"
}
| Nothing
| Conv(_) => "/* No JS code generated */"
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved this from the Output Panel in order to re-use it here.

@diogomqbm diogomqbm marked this pull request as ready for review August 11, 2021 21:02
@ryyppy
Copy link
Member

ryyppy commented Sep 7, 2021

Thanks for the effort!

just tried it and it broke with the following error after i ran the program, edit some code, and re-ran it:

framework-23118dcc1b886e5b49be.js:1 Uncaught TypeError: Cannot read properties of null (reading 'type')
    at Object.enter (4602.36ad9f9b40402bfe8083.js:1)
    at n.visit (72050.fb3ef5607642e26cc14f.js:1)
    at n.visit (72050.fb3ef5607642e26cc14f.js:1)
    at n.visit (72050.fb3ef5607642e26cc14f.js:1)
    at n.visit (72050.fb3ef5607642e26cc14f.js:1)
    at r (72050.fb3ef5607642e26cc14f.js:1)
    at Ee (4602.36ad9f9b40402bfe8083.js:1)
    at onClick (4602.36ad9f9b40402bfe8083.js:1)
    at Object.We (framework-23118dcc1b886e5b49be.js:1)
    at Ye (framework-23118dcc1b886e5b49be.js:1)
enter @ 4602.36ad9f9b40402bfe8083.js:1
visit @ 72050.fb3ef5607642e26cc14f.js:1
visit @ 72050.fb3ef5607642e26cc14f.js:1
visit @ 72050.fb3ef5607642e26cc14f.js:1
visit @ 72050.fb3ef5607642e26cc14f.js:1
r @ 72050.fb3ef5607642e26cc14f.js:1
Ee @ 4602.36ad9f9b40402bfe8083.js:1
onClick @ 4602.36ad9f9b40402bfe8083.js:1
We @ framework-23118dcc1b886e5b49be.js:1
Ye @ framework-23118dcc1b886e5b49be.js:1
(anonymous) @ framework-23118dcc1b886e5b49be.js:1
_r @ framework-23118dcc1b886e5b49be.js:1
Cr @ framework-23118dcc1b886e5b49be.js:1
(anonymous) @ framework-23118dcc1b886e5b49be.js:1
Fe @ framework-23118dcc1b886e5b49be.js:1
(anonymous) @ framework-23118dcc1b886e5b49be.js:1
Or @ framework-23118dcc1b886e5b49be.js:1
Jt @ framework-23118dcc1b886e5b49be.js:1
Zt @ framework-23118dcc1b886e5b49be.js:1
t.unstable_runWithPriority @ framework-23118dcc1b886e5b49be.js:1
Wl @ framework-23118dcc1b886e5b49be.js:1
Re @ framework-23118dcc1b886e5b49be.js:1
Xt @ framework-23118dcc1b886e5b49be.js:1

I'd need some more time to play around with the code and verify a few things. I am mostly interested in the maintainability / bundle size / UI UX aspect. My original vision was to go with @tom-sherman's approach of just executing the code without any rendering, just to keep things simple. The HTML / React rendering would have probably been the next step I guess.

Let's see

@diogomqbm
Copy link
Contributor Author

diogomqbm commented Sep 7, 2021

@ryyppy thank you for the answer! Can you send me the code you used to break the app?

@ryyppy
Copy link
Member

ryyppy commented Sep 8, 2021

Literally the example that loads in the beginning.
Run it once, then add another match case to the switch count and run it again and check the console.

@diogomqbm
Copy link
Contributor Author

diogomqbm commented Sep 25, 2021

@ryyppy sorry for the delay, it's been a busy month.

I've managed to fix the error and would appreciate it if you could play around with it. I see it as a next step moving some parts to separate workers. Also did some renaming trying to make things clearer.

@davesnx
Copy link
Contributor

davesnx commented Aug 11, 2022

Hey @ryyppy, this PR seems like it got abandoned and was a good improvement over the current status.

Is there anything we could help in merging this?

Creating a bundle with Stdlib exposed into window sounds doable inside the rescript-lang.org repo, should it live here or have another repo for it?

cc @diogomqbm

@diogomqbm
Copy link
Contributor Author

Hey @ryyppy, this PR seems like it got abandoned and was a good improvement over the current status.

Hey @davesnx, I've been meaning to get back to this.

Is there anything we could help in merging this?

I'll do a little clean up here and I think we'll need an official bundle of the std lib. Besides that, we'll be good to go once the UI/UX is approved.

@diogomqbm
Copy link
Contributor Author

@davesnx @ryyppy I did a few adjustments both to the code and UI/UX adding the default background color to the render output pane. Please play with it and let me know what you think.

@ryyppy
Copy link
Member

ryyppy commented May 26, 2023

@diogomqbm I just gave this another look and I feel more comfortable pushing this forward. Any chance you could rebase onto latest master (maybe together with @aspeddro)?

Regarding usability there are a few things:

  1. When a compiler version > 11 is loaded, the iframe should load React@18 (due to its newest rescript-react bindings)
  2. Also version > 11 comes with rescript-core ... not sure how we should load the runtime dependencies there?
  3. If I don't have an App module, the code doesn't run and fails silently. Would be good to explain how the Render panel works before I even start running anything
  4. When doing Js.log, it literally logs to my browser console. Wondering if we could make this a little bit more visual?

@fhammerschmidt
Copy link
Member

this got merged in #875 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Evaluate code in playground
5 participants