Skip to content

Instantly share code, notes, and snippets.

@pavankataria
Created January 29, 2021 06:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pavankataria/3b863f088d17727443c6bdca37f2138d to your computer and use it in GitHub Desktop.
Save pavankataria/3b863f088d17727443c6bdca37f2138d to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const wizardMachine = Machine({
id: 'wizard',
initial: 'open',
states: {
open: {
initial: 'step1',
states: {
step1: {
on: { NEXT: 'step2' }
},
step2: {
on: { NEXT: 'step3' }
},
step3: {
/* ... */
}
},
on: {
NEXT: 'goodbye',
CLOSE: 'closed'
}
},
goodbye: {
on: { CLOSE: 'closed' }
},
closed: {}//{ type: 'final' }
}
});
// { open: 'step1' }
const { initialState } = wizardMachine;
// the NEXT transition defined on 'open.step1'
// supersedes the NEXT transition defined
// on the parent 'open' state
const nextStepState = wizardMachine.transition(initialState, 'NEXT');
console.log(nextStepState.value);
// => { open: 'step2' }
// there is no CLOSE transition on 'open.step1'
// so the event is passed up to the parent
// 'open' state, where it is defined
const closedState = wizardMachine.transition(initialState, 'CLOSE');
console.log(closedState.value);
// => 'closed'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment