Skip to content

Instantly share code, notes, and snippets.

@jjenzz
Last active September 29, 2019 16:19
Show Gist options
  • Save jjenzz/def73de387567a95709c5c83bafa67ec to your computer and use it in GitHub Desktop.
Save jjenzz/def73de387567a95709c5c83bafa67ec 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 dismissReasonMachine = Machine({
id: 'dismissReasonMachine',
initial: 'load',
context: {
actions: [],
reason: undefined,
action: undefined,
},
states: {
load: {
invoke: {
id: 'onLoad',
src: 'onLoad',
onDone: [
{
cond: 'hasActions',
target: 'input',
actions: ['setActions'],
},
{
target: 'error.emptyActions'
}
],
onError: 'error.serverError',
},
on: {
CANCEL: 'close',
},
},
input: {
on: {
SELECT_ACTION: {
actions: ['setAction'],
},
ENTER_REASON: {
actions: ['setReason']
},
CANCEL: 'close',
SUBMIT: 'save',
}
},
save: {
invoke: {
id: 'onSave',
src: 'onSave',
onDone: 'success',
onError: 'error.saveFailed'
},
},
success: {
on: {
TIMER: 'close',
},
},
error: {
states: {
emptyActions: {},
serverError: {},
saveFailed: {},
}
},
close: {
type: 'final',
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment