One of our most-requested features has just landed in the Stately Studio; you can now import your machines from code!
Watch import from code in action in our latest video.
Importing from code is handy if you’ve already built machines while working with XState, or have created a machine using our older Stately Viz and haven’t yet tried the Stately visual editor.
How to import from code
You can import an existing machine from JavaScript and TypeScript using the code panel in the right tool menu or from the Machines list in the left drawer.
Your code should be formatted as a createMachine()
factory function before import. The importer has basic validation in case your machine has basic errors, including reminding you if the createMachine
definition is missing.
And please import your code into an existing machine with caution! Importing code from the code panel will overwrite the current machine in the editor. You may have multiple createMachine
s included in the code you insert in the text area, but the Studio will currently only import the first machine found in the code. We plan to support importing multiple machines in the future, if that’s a feature you’d love, please upvote the multiple machine import feature request on our board.
Export code
What about exporting your machines as code? You might have missed this feature as we released it as part of the Stately Studio 1.0 release. You can export your machine as JSON, JavaScript, and TypeScript using the code panel in the right tool menu.
Using the export icon button in the editor’s top bar, you can also export as code from the Export machine dialog. Check out Laura’s demo utilizing this feature to go from modeling your machine to code.
Please give us your feedback!
Have you used the import and export features yet? We’d love to hear your thoughts! The team loves hearing your feedback on our Stately Discord or during our next office hours live stream. If you have any feature requests, please add them to our feature request board, and we’ll keep you updated if it’s planned, in progress, or complete!