Skip to content

Instantly share code, notes, and snippets.

@devstojko
Last active February 9, 2020 06:03
Show Gist options
  • Save devstojko/4e39d82fb96eece652f720319c4f6210 to your computer and use it in GitHub Desktop.
Save devstojko/4e39d82fb96eece652f720319c4f6210 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 states = {
IDLE: 'IDLE',
LOADING: 'LOADING',
READY: 'READY',
ERROR: 'ERROR'
}
const events = {
SELECT: 'SELECT',
SUBMIT: 'SUBMIT',
}
const resultsMachine = Machine({
id: 'resultsMachine',
initial: [states.IDLE],
context: {
origin: null,
destination: null,
},
states: {
[states.IDLE]: {
on: {
[events.SELECT]: {
actions: assign((ctx, e) => ({
...ctx,
[e.payload.property]: e.payload.data
}))
},
[events.SUBMIT]: {
cond: (ctx, e) => ctx.origin && ctx.destination,
target: states.LOADING,
}
}
},
[states.LOADING]: {
invoke: {
}
},
[states.READY]: {
},
[states.ERROR]: {
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment