Last active
April 2, 2021 10:59
-
-
Save blaadje/a87e68cca3195fedff790d726e4f27d6 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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