Skip to content
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

Add typescript support in visualizer #429

Closed
gewoonwoutje opened this issue Apr 19, 2019 · 15 comments
Closed

Add typescript support in visualizer #429

gewoonwoutje opened this issue Apr 19, 2019 · 15 comments

Comments

@gewoonwoutje
Copy link

Feature request

As mentioned in Issue 122, support for typescript in the visualizer would be great during development

Potential implementation:

Before showing the state machine, add a tsc step to compile the visualization. Flow could be one of the following:

  • Add a toggle button on top of the visualizer that toggles between typescript and javascript.
  • Configure typescript to allow javascript without strict checking, so that javascript and typescript are both supported.
@davidkpiano
Copy link
Member

It has to be run-time. Do you know of any run-time TSC compilers? Or possibly a tool that strips out types?

@gewoonwoutje
Copy link
Author

I don't know of any directly, but it has to exist somewhere.
A quick googling gave me:
https://stackoverflow.com/questions/14283737/typescript-web-based-ide/52991184#52991184

Also, typescript had it in their playground for quite a long time:
https://www.typescriptlang.org/play/

@gewoonwoutje
Copy link
Author

That monaco editor looks great. It would be awesome if you could pull that in somehow!

@kolohelios
Copy link

kolohelios commented Apr 20, 2019

I added TypeScript support to a visualizer I was working on (based on David's work) and unfortunately had to abandon it because of work demands. There isn't much required to get the runtime transpilation working (using the typescript module itself).

This approach doesn't require the user to do anything (that is to say, no toggle between languages) as it just means the compiler doesn't do anything.

https://github.com/kolohelios/xstate-cartographer/blob/6a173463c23a1db3b98e35c2df16c1e8ee875b31/src/lib/utils/toMachine/index.ts

@alizbazar
Copy link
Contributor

alizbazar commented May 4, 2019

Tejas Kumar presented at React Finland how to use Monaco editor from VSCode to use Typescript in the browser textarea view.

@TejasQ
Slides: https://slides.react-finland.fi/2019/tejas-kumar.pdf
Twitter: https://twitter.com/TejasKumar_

@TejasQ
Copy link

TejasQ commented May 6, 2019

What's up, my friends?! I am down to help with this in any way I can.

@RainerAtSpirit
Copy link

Inspired by your talk I was looking into this one as well. I ran into some challenges as https://github.com/statecharts/xstate-viz is using rollup as bundler, while most examples I found in the wild are using webpack with a plugin to create the workers.
So the editor is working, but intellisense and highlighting is not.

@TejasQ
Copy link

TejasQ commented May 6, 2019

Do you have a PR I can reference?

@RainerAtSpirit
Copy link

@TejasQ See https://github.com/RainerAtSpirit/xstate-viz/tree/react-monaco-editor. You need to symlink by running sudo npm link in root and npm link @statecharts/xstate-viz in public.
While viewing your presentation at React Finland I was thinking that we could use something similar for the documentation by adding a show visualizer and an edit code button to the documentation e.g. at https://xstate.js.org/docs/guides/typescript.html#using-typescript.

@RainerAtSpirit
Copy link

@davidkpiano @TejasQ Here's a different approach that uses codesandbox for code editing and a slightly modified local version of StateChart https://codesandbox.io/s/j4yjjyr85.
By convention the exported machine from machine.ts should be exported as export const myMachine

@abierbaum
Copy link
Contributor

@RainerAtSpirit any chance to get this integrated. I love the visualization tool but I also love typescript safety. would be great if we could use both. 😄

@RainerAtSpirit
Copy link

@abierbaum I doubt that this can be easily integrated. CodeSandbox has to run though a lot of hurdles to enable TypeScript support. I don't think that this should become the visualizer's responsibility.
But you never know @davidkpiano is full of surprises.

@gunn4r
Copy link

gunn4r commented Sep 18, 2020

Is this just dead? How are people using the visualizer with all your machines / code written in typescript? Seems like it would make the visualizer impossible to realistically use since you'd have to go through and strip all your types out? Just wondering what the workflow looks like that yall are using in this case.

@davidkpiano
Copy link
Member

How are people using the visualizer with all your machines / code written in typescript?

Like this: https://codesandbox.io/s/xstate-ts-viz-template-qzdvv 😉

Docs here: https://xstate.js.org/docs/packages/xstate-inspect/

@gunn4r
Copy link

gunn4r commented Sep 18, 2020

@davidkpiano Tight! Thanks for sharing!

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

No branches or pull requests

8 participants