Skip to content

Instantly share code, notes, and snippets.

@blaadje
Last active April 2, 2021 10:59
Show Gist options
  • Save blaadje/a87e68cca3195fedff790d726e4f27d6 to your computer and use it in GitHub Desktop.
Save blaadje/a87e68cca3195fedff790d726e4f27d6 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 submitService = () => Promise.resolve()
const assignCustomer = assign({
customer: (_, { customer }) => customer,
})
const service = {
src: submitService,
onDone: {
target: 'success',
},
onError: {
target: 'error',
},
}
const fetchMachine = Machine({
id: 'fetch',
initial: 'idle',
customer: null,
states: {
idle: {
on: {
SUBMIT_IDENTITY: {
actions: assignCustomer,
target: 'SUBMIT.identity',
},
SUBMIT_ADDRESS: {
actions: assignCustomer,
target: 'SUBMIT.address',
},
}
},
SUBMIT: {
states: {
identity: {
initial: 'loading',
states: {
loading: {
invoke: service
},
success: {},
error: {},
}
},
address: {
initial: 'loading',
states: {
loading: {
invoke: service
},
success: {},
error: {},
}
},
}
},
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment