Skip to content

Instantly share code, notes, and snippets.

@sawtell
Created November 19, 2020 11:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sawtell/b6f5a108f230bc9146ca054c7769df12 to your computer and use it in GitHub Desktop.
Save sawtell/b6f5a108f230bc9146ca054c7769df12 to your computer and use it in GitHub Desktop.
Visualise xState with plantUML
import { Machine } from "xstate";
import visualize from "xstate-plantuml";
import plantumlEncoder from "plantuml-encoder";
const promiseMachine = Machine({
id: "promise",
initial: "pending",
states: {
pending: {
on: {
START: "in_progress",
},
},
in_progress: {
on: {
SUBMIT: "under_review",
},
},
under_review: {
on: {
ACCEPT: "accepted",
REJECT: "rejected",
},
},
accepted: {
type: "final",
},
rejected: {
type: "final",
},
},
});
const plantUML = visualize(promiseMachine);
<img src={`http://www.plantuml.com/plantuml/img/${plantumlEncoder.encode(plantUML)}`} />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment