Skip to content

Instantly share code, notes, and snippets.

@franz101
Last active February 26, 2020 14:44
Show Gist options
  • Save franz101/c58d381ae9a1dd6c37d93f96da382705 to your computer and use it in GitHub Desktop.
Save franz101/c58d381ae9a1dd6c37d93f96da382705 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const orderMachine = Machine({
id: 'order',
initial: 'start',
context:
{},
states: {
start: {
on: {BUSINESS:'business.idle',
CONSUMER:'consumer.idle'
}
},
business:{
states: {
idle: {
on: {
FETCH: 'loadingQuote'
}
},
loadingQuote: {
on: {
RESOLVE: 'quote',
REJECT: 'failure'
}
},
quote: {
type: 'final'
},
failure: {
on: {
RETRY: {
target: 'loadingQuote',
actions: assign({
retries: (context, event) => context.retries + 1
})
}
}
}
}
},
consumer:{
states: {
idle: {
on: {
FETCH: 'loading'
}
},
loading: {
on: {
RESOLVE: 'quote',
REJECT: 'failure'
}
},
quote: {
type:'final'
},
failure: {
on: {
RETRY: {
target: 'loading',
actions: assign({
retries: (context, event) => context.retries + 1
})
}
}
}
}},
business_quoting :{
states:{
start_quoting:{
on:{"START":"parse_order"}},
parse_order:{on:{
RESOLVE: 'order_validation',
REJECT: 'error_response'}},
order_validation:{on:{
RESOLVE: 'parse_weight',
REJECT: 'error_response'}},
parse_weight: {on:{
RESOLVE: 'lookup_zips_and_tarif_by_weight',
REJECT: 'error_response'}},
lookup_zips_and_tarif_by_weight: {on:{
RESOLVE: 'get_global_discount',
REJECT: 'error_response'}},
get_global_discount: {on:{
RESOLVE: 'get_shipper_discount',
REJECT: 'error_response'}},
get_shipper_discount: {on:{
RESOLVE: 'resolve_response',
REJECT: 'error_response'}},
get_global_discount: {on:{
RESOLVE: 'parse_extras',
REJECT: 'error_response'}},
parse_extras: {on:{
RESOLVE: 'get_quoting_for_extras',
REJECT: 'error_response'}},
get_quoting_for_extras: {on:{
RESOLVE: 'clean_order',
REJECT: 'error_response'}},
clean_order: {on:{
RESOLVE: 'resolve_response',
REJECT: 'error_response'}},
error_response:{ type:'final'},
resolve_response:{ type:'final'}
}
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment