Skip to content

Instantly share code, notes, and snippets.

@wzulfikar
Last active July 25, 2019 08:51
Show Gist options
  • Save wzulfikar/123811feb3917e6d718d99c58a8ebae7 to your computer and use it in GitHub Desktop.
Save wzulfikar/123811feb3917e6d718d99c58a8ebae7 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// Machine (machine factory function)
// assign (action)
// XState (all XState exports)
const fetchMachine = Machine({
id: 'Point of Sale',
context: { attempts: 0 },
initial: 'idle',
states: {
idle: {
on: { 'place order': 'unpack qr code'}
},
pending: {
on: {
RESOLVE: 'unpack qr code',
REJECT: 'rejected'
}
},
'unpack qr code': {
initial: 'dealer scan',
states: {
'dealer scan': {
on: {
NEXT: 'pending'
}
},
'customer scan': {
on: {
NEXT: 'pending'
}
}
}
},
rejected: {
initial: 'can retry',
states: {
'can retry': {
on: {
'': {
target: 'failure',
cond: 'maxAttempts'
}
}
},
failure: {
on: {
RETRY: undefined,
},
type: 'final'
}
},
on: {
RETRY: 'pending'
}
}
}
}, {
guards: {
maxAttempts: ctx => ctx.attempts >= 5
},
delays: {
TIMEOUT: 2000
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment