Last active
May 11, 2020 09:19
-
-
Save lifedraft/f60d576b92358aed56e937cabb249c78 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 fetchMachine = Machine({ | |
id: 'shipping', | |
initial: 'deliveryAddress', | |
context: { | |
errors: null, | |
loading: false | |
}, | |
states: { | |
deliveryAddress: { | |
initial: 'fetchDeliveryAddresses', | |
states: { | |
fetchDeliveryAddresses: { | |
invoke: { | |
src: 'fetchDeliveryAddresses', | |
onDone: { | |
target: 'idle' | |
}, | |
onError: { | |
target: 'idle' | |
} | |
} | |
}, | |
idle: { | |
on: { | |
'SUBMIT': { | |
target: 'updateDeliveryAddresses', | |
actions: assign({ | |
loading: true, | |
errors: null | |
}) | |
} | |
} | |
}, | |
updateDeliveryAddresses: { | |
invoke: { | |
src: 'updateDeliveryAddresses', | |
onDone: { | |
target: 'success' | |
}, | |
onError: { | |
target: 'success' | |
} | |
}, | |
}, | |
success: { | |
type: 'final' | |
} | |
}, | |
onDone: { | |
target: '#shippingOptions' | |
} | |
}, | |
shippingOptions: { | |
id: 'shippingOptions', | |
initial: 'fetchShippingOptions', | |
states: { | |
fetchShippingOptions: { | |
invoke: { | |
src: 'fetchShippingOptions', | |
onDone: { | |
target: 'idle' | |
}, | |
onDone: { | |
target: 'idle' | |
} | |
} | |
}, | |
idle: { | |
on: { | |
'SUBMIT': 'submit' | |
} | |
}, | |
submit: { | |
on: {} | |
} | |
} | |
} | |
}, | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment