Created
October 18, 2023 07:22
-
-
Save pociej/070ad987f307e424013940441eb8a73b to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains hidden or 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
// Available variables: | |
// - Machine | |
// - interpret | |
// - assign | |
// - send | |
// - sendParent | |
// - spawn | |
// - raise | |
// - actions | |
// - XState (all XState exports) | |
const machine = Machine({ | |
types: {}, | |
id: "simpleMachine", | |
initial: "initial", | |
context: { value: 0 }, | |
states: { | |
initial: { | |
on: { | |
NEXT: { target: "oracle" }, | |
}, | |
}, | |
oracle: { | |
on: { | |
NEXT: { | |
target: "choose_your_name", | |
actions: assign({ value: () => Math.random() }), | |
}, | |
}, | |
}, | |
choose_your_name: { | |
on: { | |
NEXT: [ | |
{ | |
target: "john", | |
guard: ({ context }) => { | |
return context.value > 0.5; | |
}, | |
}, | |
{ | |
target: "michael", | |
guard: ({ context }) => { | |
return context.value < 0.5; | |
}, | |
}, | |
], | |
}, | |
}, | |
john: { | |
on: { | |
NEXT: "choose_your_color", | |
}, | |
}, | |
michael: { | |
on: { | |
NEXT: "choose_your_color", | |
}, | |
}, | |
choose_your_color: { | |
on: { | |
NEXT: [ | |
{ | |
target: "blue", | |
guard: ({ context }) => { | |
return context.value > 0.5; | |
}, | |
}, | |
{ | |
target: "red", | |
guard: ({ context }) => { | |
return context.value < 0.5; | |
}, | |
}, | |
], | |
}, | |
}, | |
blue: { | |
on: { | |
NEXT: "success", | |
}, | |
}, | |
red: { | |
on: { | |
NEXT: "success", | |
}, | |
}, | |
success: { | |
type: "final", | |
}, | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment