Last active
June 28, 2021 17:14
-
-
Save aceslick911/1ad3e44128d3d7a0f71f5f66d8eddc9e 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
// Available variables: | |
// - Machine | |
// - interpret | |
// - assign | |
// - send | |
// - sendParent | |
// - spawn | |
// - raise | |
// - actions | |
// - XState (all XState exports) | |
const fetchMachine = Machine({ | |
id: 'fetch', | |
initial: 'newForm', | |
context: { | |
retries: 0, | |
fromAccount: null, | |
toAccount: null, | |
transferAmount: null, | |
hasFrom: false, | |
hasTo: false, | |
hasAmount: false, | |
}, | |
states: { | |
newForm: { | |
on: { | |
REQUEST_FROM_INFO: 'collect_transfer_details' | |
} | |
}, | |
collect_transfer_details: { | |
initial: 'collect_transfer_details.incomplete_form', | |
states: { | |
incomplete_form: { | |
on: { | |
initial:'incomplete_form.NEED_INFO', | |
SET_FROM: { | |
target: 'incomplete_form', | |
actions: assign({ | |
fromDetails: (context, event) => { | |
context.fromAccount = event.sender; | |
context.hasFrom = true; | |
} | |
}), | |
}, | |
SET_TO: { | |
target: 'incomplete_form', | |
actions: assign({ | |
toDetails: (context, event) => { | |
context.toAccount = event.reciever; | |
context.hasTo = true; | |
} | |
}), | |
}, | |
SET_AMOUNT: { | |
target: 'incomplete_form', | |
actions: assign({ | |
amountDetails: (context, event) => { | |
context.transferAmount = event.transferAmount; | |
context.hasAmount = true; | |
} | |
}), | |
}, | |
SEND_TRANSFER: { | |
target: '..success', | |
} | |
}, | |
states:{ | |
NEED_INFO:{ | |
target: 'incomplete_form', | |
}, | |
} | |
} | |
} | |
} | |
}, | |
success: { | |
type: 'final' | |
}, | |
failure: { | |
on: { | |
RETRY: { | |
target: 'newForm', | |
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