Last active
October 18, 2023 10:33
-
-
Save pociej/9d4a47f77b9e71746c2228a4e02c8657 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
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
const machine = Machine({ | |
types: {}, | |
id: "simpleMachine", | |
initial: "initial", | |
context: { value: 0 }, | |
states: { | |
initial: { | |
on: { | |
NEXT: { target: "oracle" }, | |
}, | |
}, | |
oracle: { | |
on: { | |
John_blue: { | |
actions: assign({ value: 1 }), | |
target: "choose_your_name", | |
}, | |
Michael_red: { | |
actions: assign({ value: 0 }), | |
target: "choose_your_name", | |
}, | |
}, | |
}, | |
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