Last active
July 25, 2019 08:51
-
-
Save wzulfikar/123811feb3917e6d718d99c58a8ebae7 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains hidden or 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 (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