xstate-viz icon indicating copy to clipboard operation
xstate-viz copied to clipboard

Usage of Visualizer in other places

Open ZempTime opened this issue 5 years ago • 6 comments

Description I'm trying to use <StateChart> to render out various machines in our system, so business folks and devs can peek their heads in and see what's going on.

What I'm running into is:

Screen Shot 2020-05-14 at 4 20 01 PM

whch appears to be referencing this: https://github.com/statecharts/xstate-viz/blob/master/src/StateChartVisualization.tsx#L3

Afaik, xstate/lib/graph has been moved into @xstate/graph.

Additional context I'm mounting it all inside a web component and then rendering this inside there (following altered to omit nonessential info so I can share publicly):

import { StateChart } from "@statecharts/xstate-viz";

const Visualizer: React.FC<any> = ({machine}) => {
  const onSave = (e) => {
    console.log(e)
  }
  return (
    <StateChart machine={machine} onSave={onSave}/>
  )
}
import React from "react";
import ReactDOM from "react-dom";
import Visualizer from "../components/visualizer";
import machine from "project/src/machine";

export default class PageProjectVisualizer extends HTMLElement {
  connectedCallback() {
    const mountPoint = document.createElement("span");
    this.attachShadow({ mode: "open" }).appendChild(mountPoint);

    ReactDOM.render(<Visualizer machine={machine} />, mountPoint);
  }
}
customElements.define("page-project-visualizer", PageProjectVisualizer);

Is this package intended to be used in this way? Is there another way of accomplishing this?

I'd be happy to help get this building and exporting esm's if you're open to it. This would go a long way towards xstate usage/adoption inside my company.

ZempTime avatar May 14 '20 21:05 ZempTime

There will be a ready-made component in the XState repository itself for this.

If you want to play around with it now, it's @xstate/viz 🕵️

It's not ready for release but if you're eager, you can look around and try to make it work locally!

davidkpiano avatar May 15 '20 13:05 davidkpiano

Tried starting @xstate/viz example. Use npm link, etc. No luck. No errors during build or start, but rendered blank page. @davidkpiano ^

bwalsh avatar May 20 '20 13:05 bwalsh

@bwalsh

It's not ready for release but if you're eager, you can look around and try to make it work locally!

It's up to you right now to figure out how to make it work. Or you can wait until it's publicly released.

davidkpiano avatar May 20 '20 13:05 davidkpiano

I think this visualization would be an awesome addition for the debug visualizer extension for VS Code.

Sadly, the xstate visualizer is broken currently, otherwise I could easily integrate it!

hediet avatar Aug 31 '20 17:08 hediet

@hediet Check out the Keyframers stream at 5 PM today. I'll be releasing the works-anywhere visualizer soon.

davidkpiano avatar Aug 31 '20 17:08 davidkpiano

It seems that https://statecharts.io/ has examples of using a visualizer.

martinklepsch avatar Apr 10 '21 13:04 martinklepsch