Skip to content

Instantly share code, notes, and snippets.

@davidkpiano
Last active July 31, 2020 20:39
Show Gist options
  • Save davidkpiano/ca6a3f84f585c3e9cd6aadc3ae00b886 to your computer and use it in GitHub Desktop.
Save davidkpiano/ca6a3f84f585c3e9cd6aadc3ae00b886 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const timeOfDayMachine = Machine({
id: 'timeOfDay',
initial: 'unknown',
context: {
time: new Date(Date.now())
},
states: {
// Transient state
unknown: {
on: {
'': [
{ target: 'morning', cond: 'isBeforeNoon' },
{ target: 'afternoon', cond: 'isBeforeSix' },
{ target: 'evening' }
]
}
},
morning: {},
afternoon: {},
evening: {}
}
}, {
guards: {
isBeforeNoon: (context) => {
return context.time.getHours() < 12
},
isBeforeSix: (context) => {
return context.time.getHours() < 18
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment