Open coodoo opened 5 years ago
I was thinking about a less intrusive option. The option is using a hook that collects metadata in development mode of all statecharts in your app and automatically shows a debugger window (with a button or with a keyboard shortcut). It'll allow you to navigate over all your statecharts and if possible change the state. All this would be done with a global config. Maybe implementing it as an experimental file on the use-machine
package.
import { useMachine, configViz } from 'use-machine/experimental'
configViz({ withButton: true }) // one global call that enable the viz
const App = () => {
const [current, send] = useMachine(MainMachine)
return (
<div>
{JSON.stringify(current.value)}
</div>
)
}
What do you think?
Sounds good to me! 👍👍
I recently got the visualizer working locally on my React + TS codebase by a similar approach. Following a discussion with @davidkpiano, I'm working on a small CLI to be able to open visualizer for any machine the same way tools like webpack-bundle-analyzer work. Therefore, anyone would be able to visualize all the machines in their codebase using es modules and file path references.
{
"visualize": "xstate-viz --file path_to_the_file_with_default_export_machine --open"
}
Will submit a WIP PR soon. Stay tuned!
Also if you're looking for a sneak peek into how it works for my project right now, here are two files from the project.
https://github.com/farskid/hslzone/blob/master/src/components/App/AppWithMachine.tsx https://github.com/farskid/hslzone/blob/master/src/components/Viz.tsx
Great, @farskid!
I would much prefer a visualization tool that generates SVG from state machine objects. This way it would be framework-agnostic and potentially usable from command line.
@sesm, are you aware of https://github.com/lucmartens/xstate-plantuml?
@farskid, I am very interested in your work. As I'm working much in Vue codebases these day, there might also be a change to use the visualizer components via https://github.com/akxcv/vuera ... Are you still on it?
@riddla Thanks for sharing plantuml project and the kind words :) we're working on the a vscode extension for the visualization. stay tuned.
Also if you're looking for a sneak peek into how it works for my project right now, here are two files from the project.
https://github.com/farskid/hslzone/blob/master/src/components/App/AppWithMachine.tsx https://github.com/farskid/hslzone/blob/master/src/components/Viz.tsx
Hello @farskid, I tried running your code and I'm getting following error. Error: Can't resolve 'xstate/lib/graph' in 'node_modules\@statecharts\xstate-viz\lib'
Do you know how can I fix it?
@Indrajeetsing it's a dependency error, you probably need to install the dependencies again
@Indrajeetsing Seems that the 0.3.0
release of this package is expecting to find that file, which does not exist anymore in the latest xstate
package. The latest version of xstate
conforms to ^4.6.4
of 0.3.0
version requirement (^
matches 4.12.0
), but internally xstate
have moved the graph file, possibly to @xstate/graph
.
You'd need to lock your xstate
dependency to "xstate": "4.6.4"
in your app if you try to use the 0.3.0
version (latest at the moment of writing) of this package. It did not seem straightforward though, resulting into further type mismatches.
More feasibility talk in #67.
Need assistance on how to visualize xsate chart of my state machine on my native react app, without any need to visit - https://xstate.js.org/viz/. Have gone through the comments in this discussion , but could not find anything exactly for my requirement
@piku0709 it's possible to do on web with statechart-viz, but it will be static, without any live updates on state change, unless you pass a new state to visualiser every time it changes.
If you need it work in React Native, you have two options:
react-native-svg
and fixes for styles and HTML entitiesbut I wouldn't do anything of it and tried to patch @xstate/inspect
to make it opening iframe in WebView.
@serhiipalash - Thank you for your suggestions @xstate/inspect helps me to achieve my goal. Also adding a video which helped me using @xstate/inspect in my react app - https://www.youtube.com/watch?v=ChCJ7rz-ICE
@piku0709 great!
I just did a quick POC to make
xstate-viz
a drop-in visualizer in a react app so that it could be toggled on and off as needed, see it in action hereSample code below, basically the viz component lives with-in the real project and will be updated whenever the machine content was changed.
As a side note, it would be great to toggle show/hide of the sidebar by an argument.