Created
January 29, 2021 06:48
-
-
Save pavankataria/3b863f088d17727443c6bdca37f2138d to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains hidden or 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
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