Skip to content

Instantly share code, notes, and snippets.

@pavankataria
Last active January 3, 2021 04:41
Show Gist options
  • Save pavankataria/bfeaef41bb4cd136e690e872add26c61 to your computer and use it in GitHub Desktop.
Save pavankataria/bfeaef41bb4cd136e690e872add26c61 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
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