Skip to content

Instantly share code, notes, and snippets.

@lozandier
Last active January 6, 2020 21:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lozandier/8d3c460c7bc870faebd54c7ddba30c91 to your computer and use it in GitHub Desktop.
Save lozandier/8d3c460c7bc870faebd54c7ddba30c91 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)
// Following example originally created by Isaac Mann
const fetchMachine = Machine(
{
id: 'matching',
initial: 'answering',
context: {
topSelectedItem: undefined,
bottomSelectedItem: undefined
},
states: {
answering: {
type: 'parallel',
onDone: 'submitted',
states: {
topList: {
initial: 'unselected',
states: {
unselected: {
on: {
SELECT_TOP: {
target: 'selected',
actions: ['setTopSelectedItem']
}
}
},
selected: {
type: 'final'
}
}
},
bottomList: {
initial: 'unselected',
states: {
unselected: {
on: {
SELECT_BOTTOM: {
target: 'selected',
actions: ['setBottomSelectedItem']
}
}
},
selected: {
type: 'final'
}
}
}
}
},
submitted: {
initial: 'evaluating',
states: {
evaluating: {
on: {
'': [
{ target: 'correct', cond: 'isCorrect' },
{ target: 'incorrect' }
]
}
},
correct: {},
incorrect: {}
}
}
}
},
{
actions: {
setTopSelectedItem: assign((ctx, event) => ({
topSelectedItem: event.selectedItem
})),
setBottomSelectedItem: assign((ctx, event) => ({
bottomSelectedItem: event.selectedItem
}))
}
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment