Created
October 23, 2020 15:04
-
-
Save jkarsrud/aaaec1f635fb59b9b49878481f6bae8b to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains 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
// 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