Skip to content

Instantly share code, notes, and snippets.

@azs06
Created March 30, 2023 10:22
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 azs06/ec4027cf2c2dca9177fda6d3eba4429c to your computer and use it in GitHub Desktop.
Save azs06/ec4027cf2c2dca9177fda6d3eba4429c to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
// Define the state machine configuration for the first machine
const firstMachine = Machine({
id: 'firstMachine',
initial: 'start',
states: {
start: {
on: {
NEXT: 'transitionToSecondMachine',
},
},
transitionToSecondMachine: {
invoke: {
src: 'secondMachine',
onDone: {
target: 'end',
actions: (context, event) => {
console.log(`Done with secondMachine, result: ${event.data}`);
},
},
},
},
end: {},
},
});
// Define the state machine configuration for the second machine
const secondMachine = Machine({
id: 'secondMachine',
initial: 'start',
states: {
start: {
entry: () => {
console.log('Entering start state of secondMachine');
},
on: {
NEXT: {
target: 'end',
actions: () => {
console.log('Transitioning to end state of secondMachine');
},
},
},
},
end: {
entry: () => {
console.log('Entering end state of secondMachine');
},
},
},
});
// Create a new instance of the first machine
const firstInstance = interpret(firstMachine.withContext({})).start()
// Send an event to the first machine to trigger a transition to the second machine
//firstInstance.send({type: 'NEXT'})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment