Created
November 19, 2020 11:49
-
-
Save sawtell/b6f5a108f230bc9146ca054c7769df12 to your computer and use it in GitHub Desktop.
Visualise xState with plantUML
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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