Last active
May 23, 2020 20:00
-
-
Save DaveWelling/0b41ea1f1a6609ed65425c2c7fab1648 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) | |
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