Skip to content

Instantly share code, notes, and snippets.

@bfunc
Last active April 10, 2021 00:12
Show Gist options
  • Save bfunc/2304aa449fed4cdc8d90224ae19731b2 to your computer and use it in GitHub Desktop.
Save bfunc/2304aa449fed4cdc8d90224ae19731b2 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const redditMachine = Machine(
{
id: 'reddit',
initial: 'idle',
context: {
question: 'em',
},
states: {
idle: {
on: {
LOAD: {
target: 'loading',
actions: assign({
question: (context, event) => context.question += '?'
})
}
},
},
loading: {
on: {
ANSWER_RIGHT: 'success',
ANSWER_WRONG: 'failure'
}
},
failure: {
on: {
RETRY: {
target: 'loading',
actions: assign({
question: (context, event) => context.question += '!'
})
}
}
},
success: {
type: 'final'
},
},
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment