Skip to content

Instantly share code, notes, and snippets.

@filipemonteiroth
Last active January 28, 2020 12:50
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 filipemonteiroth/5ace81d3c401758af30e1a914d98bdbe to your computer and use it in GitHub Desktop.
Save filipemonteiroth/5ace81d3c401758af30e1a914d98bdbe 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: 'selectSearchMachine',
initial: 'closed',
states: {
closed: {
on: {
UI_REQUESTED_OPEN: {target: 'open'},
INITIAL_OPTIONS_CHANGED: {actions: 'assignOptions'},
INITIAL_VALUE_CHANGED: {
actions: 'assignSelectedValue',
},
INPUT_FOCUSED: {
target: 'open',
},
},
},
open: {
on: {
UI_REQUESTED_CLOSE: {target: 'closed'},
INITIAL_OPTIONS_CHANGED: {actions: 'assignOptions'},
INPUT_CHANGED: {
target: 'open',
actions: ['assignQuery', 'matchAvailableOptions'],
},
INPUT_CLEARED: {
actions: ['assignClearQuery', 'matchAvailableOptions'],
},
OPTION_SELECTED: [
{
target: 'closed',
actions: ['assignSelectedValue', 'notifyChange'],
cond: 'isValidOption',
},
],
},
},
},
}, {
guards: {
isValidOption: (ctx) => true
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment