Last active
January 6, 2020 21:16
-
-
Save lozandier/8d3c460c7bc870faebd54c7ddba30c91 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
// 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