Last active
January 3, 2021 04:41
-
-
Save pavankataria/bfeaef41bb4cd136e690e872add26c61 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 promiseMachine = Machine({ | |
id: 'promise', | |
initial: 'pending', | |
states: { | |
pending: { | |
on: { | |
// state transition (shorthand) | |
// this is equivalent to { target: 'resolved' } | |
RESOLVE: 'resolved', | |
// state transition (object) | |
REJECT: { | |
target: 'rejected' | |
} | |
} | |
}, | |
resolved: { | |
type: 'final' | |
}, | |
rejected: { | |
type: 'final' | |
} | |
} | |
}); | |
const { initialState } = promiseMachine; | |
console.log(initialState.value); | |
// => 'pending' | |
const nextState = promiseMachine.transition(initialState, 'RESOLVE'); | |
console.log(nextState.value); | |
// => 'resolved' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment