Last active
July 31, 2020 20:39
-
-
Save davidkpiano/ca6a3f84f585c3e9cd6aadc3ae00b886 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 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