Skip to content

Instantly share code, notes, and snippets.

@entorenee
Created July 21, 2020 22:16
Show Gist options
  • Save entorenee/3394bd7746d07cf7a0007189aec2c992 to your computer and use it in GitHub Desktop.
Save entorenee/3394bd7746d07cf7a0007189aec2c992 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
// - XState (all XState exports)
const libraryContemplationMachine = Machine(
{
initial: 'idle',
context: {
numberOfTimesMentioned: 0,
opinion: '',
},
states: {
idle: {
on: {
TECHNOLOGY_MENTIONED: [
{
target: 'investigating',
cond: 'hasReceivedEnoughHype',
},
{
actions: 'hearAboutTechnology',
}
],
},
},
investigating: {
on: {
INVEST: {
target: 'invest',
actions: 'formOpinion',
},
NOT_INTERESTED: {
target: 'notInterested',
actions: 'formOpinion',
},
},
},
invest: {
on: {
RECONSIDER: 'investigating',
},
},
notInterested: {
on: {
INSISTENT_COLLEAGUE: 'investigating',
},
},
},
},
{
actions: {
formOpinion: assign({
opinion: (context, event) => event.opinion,
}),
hearAboutTechnology: assign({
numberOfTimesMentioned: (context) =>
context.numberOfTimesMentioned + 1,
}),
},
guards: {
hasReceivedEnoughHype: (context) => context.numberOfTimesMentioned >= 2,
},
},
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment