Skip to content

Instantly share code, notes, and snippets.

@austinsamsel
Created March 10, 2021 17:15
Show Gist options
  • Save austinsamsel/42d74d7df69260e7d9ed7d34909b93b8 to your computer and use it in GitHub Desktop.
Save austinsamsel/42d74d7df69260e7d9ed7d34909b93b8 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 fetchMachine = Machine({
id: 'p2p-listing-purchase',
initial: 'idle',
context: {},
states: {
idle: {
id: 'idle',
on: {
SELECT: '#select',
},
},
select: {
id: 'select',
initial: 'fetch',
on: {
CANCEL: '#idle',
REFETCH: '#select.fetch',
},
states: {
fetch: {
invoke: {
src: 'getListings',
onDone: [
{
target: '#select.idle',
cond: 'listingHasMoments',
actions: ['assignGetListings'],
},
{
target: '#select.empty',
},
],
onError: '#select.error',
},
},
idle: {
on: {
BUY: [
{
cond: 'isCooldownEnabled',
target: '#cooldown',
actions: ['assignSelectedMoment'],
},
{
target: '#buyingMoment',
actions: ['assignSelectedMoment'],
},
],
},
},
empty: {
},
error: {
},
},
},
cooldown: {
id: 'cooldown',
on: {
CONFIRM: '#buyingMoment',
DISMISS: '#idle',
},
},
buyingMoment: {
id: 'buyingMoment',
invoke: {
id: 'buyMoment',
src: 'buyMoment',
onDone: '#success',
onError: '#error',
},
},
error: {
id: 'error',
on: {
RETRY: '#select',
},
},
success: {
id: 'success',
type: 'final',
},
},
}, {
actions: {
assignGetListings: () => {},
},
guards: {
listingHasMoments: () => true,
isCooldownEnabled: () => true,
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment