Skip to content

Instantly share code, notes, and snippets.

@zainfathoni
Last active January 25, 2020 00:56
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 zainfathoni/a3583755d1251d5888b59f84db5c396b to your computer and use it in GitHub Desktop.
Save zainfathoni/a3583755d1251d5888b59f84db5c396b 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 fetchSuccess = assign({
order: (context, event) => event.order
})
const fetchMachine = Machine({
id: 'dvt',
initial: 'loading',
context: {
uuid: '1234-5678-8901-2345',
order: {}
},
states: {
loading: {
on: {
PENDING: {
target: 'confirmOrder',
actions: 'fetchSuccess'
},
VERIFIED: 'verified',
CANCELLED: 'cancelled',
EXPIRED: 'expired'
}
},
verified: {
type: 'final'
},
cancelled: {
type: 'final'
},
expired: {
type: 'final'
},
confirmOrder: {
on: {
CONFIRM: 'geocoding',
CANCEL: 'cancelled'
}
},
geocoding: {
on: {
SUCCESS: 'confirmAddress',
FAILURE: 'confirmOrder'
}
},
confirmAddress: {
on: {
EDIT: 'editAddressMap',
CONFIRM: 'confirming'
}
},
confirming: {
on: {
SUCCESS: 'verified',
FAILURE: 'confirmAddress'
}
},
editAddressMap: {
on: {
CONFIRM: 'reverseGeocoding',
CANCEL: 'cancelled'
}
},
reverseGeocoding: {
on: {
SUCCESS: 'editAddressDetails',
FAILURE: 'editAddressMap'
}
},
editAddressDetails: {
on: {
SUBMIT: 'updating',
CANCEL: 'cancelled'
}
},
updating: {
on: {
SUCCESS: 'verified',
FAILURE: 'editAddressDetails'
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment