Skip to content

Instantly share code, notes, and snippets.

@wspringer
Last active March 29, 2020 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wspringer/087c0e467b62cae4b7969d5f251ff036 to your computer and use it in GitHub Desktop.
Save wspringer/087c0e467b62cae4b7969d5f251ff036 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 validConsumerTransfer = (cond, event) => true;
const invalidConsumerTransfer = (cond, event) => !validConsumerTransfer(cond, event);
const consumerTransferEvent = Machine({
key: 'consumerTransfer',
initial: 'started',
context: {},
states: {
started: {
on: {
ConsumerTransfer: [
{
target: 'accepted',
cond: 'validConsumerTransfer',
},
{
target: 'rejected',
cond: 'invalidConsumerTransfer',
},
],
},
},
accepted: {
entry: ['ValidationAcknowledgement','ChangePending'],
on: {
TerminationNotification: 'terminated',
TransactionAcknowledgement: [
{
target: 'expired',
cond: '!expired'
},
{ target: 'verified',
cond: 'expired'
}
]
}
},
rejected: {
entry: ['ValidationAcknowledgement'],
type: 'final'
},
verified: {
entry: ['DispatchData'],
on: {
TerminationNotification: 'terminated',
ValidationAcknowledgement: 'confirmed'
}
},
expired: {
entry: ['NewDateRequired'],
on: {
TerminationNotification: 'terminated',
'NewDate': [
{ target: 'verified', cond: '!exired' },
{target: 'expired', cond: '!expired' }
]
}
},
confirmed: {
entry: ['ChangeComplete'],
on: {
TransactionAcknowledgement: 'completed'
}
},
completed: {
type: 'final'
},
terminated: {
type: 'final'
}
},
},
{
guards: {
validConsumerTransfer: (context, event) => event.valid === true,
invalidConsumerTransfer: (context, event) => event.valid === false
}
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment