Last active
May 4, 2021 07:09
-
-
Save believer/a88e78242c7112439f98c61f9b0113a7 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains hidden or 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
const fetchSeller = () => Promise.resolve({ streetAddress: 'Test street' }) | |
const sellerInformationValid = (ctx, event) => !!ctx.seller.streetAddress | |
const validId = () => false | |
const fetchMachine = Machine( | |
{ | |
id: 'kp-form', | |
initial: 'seller', | |
context: { | |
listingId: 1, | |
seller: {}, | |
sellerError: null, | |
}, | |
states: { | |
seller: { | |
on: { | |
NEXT: [ | |
{ target: 'payment', cond: { type: 'validId' } }, | |
{ target: 'fetch_information' }, | |
], | |
}, | |
}, | |
payment: { | |
on: { | |
NEXT: { | |
target: 'recommendation', | |
cond: { type: 'sellerInformationValid' }, | |
}, | |
PREVIOUS: 'seller', | |
}, | |
}, | |
fetch_information: { | |
invoke: { | |
id: 'getInvoiceInformation', | |
src: (ctx, event) => fetchSeller(), | |
onDone: { | |
target: 'payment', | |
actions: assign({ seller: (ctx, event) => event.data }), | |
}, | |
onError: { | |
target: 'payment', | |
actions: assign({ sellerError: (ctx, event) => event.data }), | |
}, | |
}, | |
}, | |
recommendation: { | |
on: { | |
NEXT: 'review', | |
PREVIOUS: 'payment', | |
}, | |
}, | |
review: { | |
type: 'final', | |
}, | |
}, | |
}, | |
{ | |
guards: { | |
sellerInformationValid, | |
validId, | |
}, | |
} | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment