Skip to content

Instantly share code, notes, and snippets.

@DaveWelling
Last active May 23, 2020 20:00
Show Gist options
  • Save DaveWelling/0b41ea1f1a6609ed65425c2c7fab1648 to your computer and use it in GitHub Desktop.
Save DaveWelling/0b41ea1f1a6609ed65425c2c7fab1648 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 step1 = {
checkConditions: ()=>raise('CONDITIONS_PASSED')
}
const testMachine = Machine({
id: 'test',
initial: 'ready',
context: {
stepNumber: 0,
steps: [step1,'step2']
},
states: {
ready: {
on: {
STATE_CHANGE: 'checkingConditions'
}
},
checkingConditions: {
entry: (context, event)=>context.steps[context.stepNumber].checkConditions(),
on: {
CONDITIONS_PASSED: 'doStep',
CONDITIONS_FAILED: 'ready'
}
},
doStep: {
on: {
FINISHED: [{
target: 'ready',
actions: assign({
stepNumber: (context, event)=> context.stepNumber+1
}),
cond: (context, event)=>
(context.stepNumber+1) <= context.steps.length
}, {
target: 'success',
}],
FAILED: 'failure'
}
},
success: {
type: 'final'
},
failure: {
type: 'final'
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment