Skip to content

Instantly share code, notes, and snippets.

@pavankataria
Last active February 5, 2021 06:27
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 pavankataria/44400f0d8a60d3058892f8fd13e02cea to your computer and use it in GitHub Desktop.
Save pavankataria/44400f0d8a60d3058892f8fd13e02cea to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const lightMachine = Machine({
// not a parallel machine
id: 'parallel',
// initial: 'green',
// states: {
// green: {
// on: { TIMER: 'yellow' }
// },
// yellow: {
// on: { TIMER: 'red' }
// },
// // nested parallel machine
// red: {
type: 'parallel',
states: {
walkSign: {
initial: 'solid',
states: {
solid: {
on: { COUNTDOWN: 'flashing' }
},
flashing: {
on: { STOP_COUNTDOWN: 'solid' }
}
}
},
pedestrian: {
initial: 'walk',
states: {
walk: {
on: { COUNTDOWN: 'wait' }
},
wait: {
on: { STOP_COUNTDOWN: 'stop' }
},
stop: {
type: 'final'
}
}
},
beepSound: {
initial: 'noSound',
states: {
noSound: {
on: { COUNTDOWN: 'sound' }
},
sound: {
on: { STOP_COUNTDOWN: 'noSound' }
}
}
}
}
// }
// }
});
// const lightMachine = Machine({
// // not a parallel machine
// id: 'light',
// // initial: 'green',
// // states: {
// // green: {
// // on: { TIMER: 'yellow' }
// // },
// // yellow: {
// // on: { TIMER: 'red' }
// // },
// // // nested parallel machine
// // red: {
// type: 'parallel',
// states: {
// walkSign: {
// initial: 'solid',
// states: {
// solid: {
// on: { COUNTDOWN: 'flashing' }
// },
// flashing: {
// on: { STOP_COUNTDOWN: 'solid' }
// }
// }
// },
// pedestrianComponent: {
// type: 'parallel',
// states: {
// pedestrian: {
// initial: 'walk',
// states: {
// walk: {
// on: { COUNTDOWN: 'wait' }
// },
// wait: {
// on: { STOP_COUNTDOWN: 'stop' }
// },
// stop: {
// type: 'final'
// }
// }
// },
// beepSound: {
// initial: 'noSound',
// states: {
// noSound: {
// on: { COUNTDOWN: 'sound' }
// },
// sound: {
// on: { STOP_COUNTDOWN: 'noSound' }
// }
// }
// }
// }
// }
// }
// // }
// // }
// });
// console.log(lightMachine.transition('yellow', 'TIMER').value);
// {
// red: {
// walkSign: 'solid',
// pedestrian: 'walk'
// }
// }
// const lightMachine = Machine({
// // not a parallel machine
// id: 'light',
// initial: 'green',
// states: {
// green: {
// on: { TIMER: 'yellow' }
// },
// yellow: {
// on: { TIMER: 'red' }
// },
// // nested parallel machine
// red: {
// initial: 'green',
// states: {
// green: {
// on: { TIMER: 'yellow' }
// },
// yellow: {
// on: { TIMER: 'red' }
// },
// // nested parallel machine
// red: {
// type: 'parallel',
// states: {
// walkSign: {
// initial: 'solid',
// states: {
// solid: {
// on: { COUNTDOWN: 'flashing' }
// },
// flashing: {
// on: { STOP_COUNTDOWN: 'solid' }
// }
// }
// },
// pedestrian: {
// initial: 'walk',
// states: {
// walk: {
// on: { COUNTDOWN: 'wait' }
// },
// wait: {
// on: { STOP_COUNTDOWN: 'stop' }
// },
// stop: {
// type: 'final'
// }
// }
// }
// }
// }
// }
// }
// }
// });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment