Skip to content

Instantly share code, notes, and snippets.

@jkarsrud
Created October 23, 2020 15:04
Show Gist options
  • Save jkarsrud/aaaec1f635fb59b9b49878481f6bae8b to your computer and use it in GitHub Desktop.
Save jkarsrud/aaaec1f635fb59b9b49878481f6bae8b to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
// - XState (all XState exports)
const bankIdAuthenticateAndOrderMachine = Machine({
id: 'bankidauth',
initial: 'idle',
context: {
authenticated: false,
paymentMethod: null,
order: null
},
states: {
idle: {
on: {
AUTH: 'authenticating'
}
},
authenticating: {
on: {
SUCCESS: {
target: 'status',
actions: assign({
authenticated: () => true,
})
},
ERROR: 'authenticationFailure'
}
},
status: {
on: {
SUCCESS: 'addingPaymentMethod',
ERROR: 'error'
}
},
addingPaymentMethod: {
on: {
SUCCESS: {
target: 'addingOrder',
actions: assign({
paymentMethod: () => ({paymentMethod: 'visa'}),
})
}
}
},
addingOrder: {
on: {
SUCCESS: {
target: 'success',
actions: assign({
order: () => ({ order: '1' }),
})
}
}
},
success: {
type: 'final'
},
error: {
type: 'final'
},
authenticationFailure: {
on: {
RETRY: {
target: 'authenticating',
actions: assign({
authenticated: () => false,
})
}
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment