Skip to content

Instantly share code, notes, and snippets.

@anthonyshort
Last active September 25, 2020 22:16
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 anthonyshort/b611f384cab85701781a04093b8a7148 to your computer and use it in GitHub Desktop.
Save anthonyshort/b611f384cab85701781a04093b8a7148 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: 'Add Carrier Response',
initial: 'logResponse',
context: {
retries: 0,
status: '',
carrier: '',
writingCompany: '',
wholesaler: '',
},
states: {
logResponse: {
on: {
ACCEPTED: {
target: 'addMarketAccessInfo',
actions: assign({
status: (context) => context.status = 'ACCEPTED'
})
},
DECLINED: {
target: 'addMarketAccessInfo',
actions: assign({
status: (context) => context.status = 'DECLINED'
})
}
}
},
addMarketAccessInfo: {
on: {
NEXT: {
target: 'loading',
actions: assign({
update: (context, event) => {
context.carrier = event.carrier;
context.writingCompany = event.writingCompany;
context.wholesaler = event.wholeSaler
},
})
},
BACK: 'loading'
}
},
loading: {
on: {
RESOLVE: 'success',
REJECT: 'failure'
}
},
success: {
type: 'final'
},
failure: {
on: {
RETRY: {
target: 'loading',
actions: assign({
retries: (context, event) => context.retries + 1
})
}
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment