Created
April 3, 2020 23:06
-
-
Save KyleAMathews/3a8bf931a247905b0d4c49f9b0928f99 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 recipeMachine = Machine({ | |
id: 'recipe', | |
initial: 'init', | |
context: { | |
currentStep: 0, | |
steps: [1,2,3] | |
}, | |
states: { | |
init: { | |
on: { | |
CONTINUE: 'present plan' | |
} | |
}, | |
"present plan": { | |
entry: ['incrementStep'], | |
on: { | |
APPLY: 'applying step', | |
} | |
}, | |
"applying step": { | |
on: { | |
FINISH: [ | |
{ | |
target: 'present plan', | |
// The 'searchValid' guard implementation details are | |
// specified in the machine config | |
cond: 'hasNextStep' | |
}, | |
{ | |
target: 'done', | |
// The 'searchValid' guard implementation details are | |
// specified in the machine config | |
cond: 'atLastStep' | |
}, | |
], | |
} | |
}, | |
"done": { | |
type: 'final' | |
}, | |
}, | |
},{ | |
actions: { | |
incrementStep: assign((context, event) => { | |
return { | |
currentStep: context.currentStep + 1 | |
} | |
}), | |
}, | |
guards: { | |
hasNextStep: (context, event) => { | |
return context.currentStep < context.steps.length | |
}, | |
atLastStep: (context, event) => { | |
return context.currentStep === context.steps.length | |
} | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment