Skip to content

Instantly share code, notes, and snippets.

@pangratz
Last active January 24, 2021 19:34
Show Gist options
  • Save pangratz/6a81c3860b6292baab6e14da952744b0 to your computer and use it in GitHub Desktop.
Save pangratz/6a81c3860b6292baab6e14da952744b0 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 fetchMachine = Machine({
id: 'house-of-cards',
initial: 'overview',
context: {
cards: null,
currentCardIndex: null
},
states: {
overview: {
on: {
START_QUIZ: 'quiz'
}
},
quiz: {
initial: 'unstarted',
on: {
CANCEL_QUIZ: 'overview'
},
states: {
unstarted: {
on: {
START: {
target: 'started',
actions: ['resetCurrentCardIndex']
}
}
},
started: {
on: {
NEXT: [{
target: 'finished',
cond: 'isLast'
}, {
target: 'started',
actions: ['incrementCurrentCardIndex']
}],
PREV: [{
target: 'unstarted',
cond: 'isFirst'
}, {
target: 'started',
actions: ['decrementCurrentCardIndex']
}]
}
},
finished: {
on: {
RESTART: {
target: 'unstarted'
}
}
}
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment