Created
January 19, 2021 17:25
-
-
Save alavkx/724fd42665e2ce52fa460d65e577f6fc 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
// XState Brain Teaser 2 - Async Validation | |
// https://www.youtube.com/watch?v=nUKA0xhkZc8 | |
const fetchValidateUserCanSendAmount = () => fetch("/validate-user-can-send-amount") | |
const fetchValidateBankDetails = () => fetch("/validate-bank-details") | |
const validationMachine = Machine({ | |
id: 'validation', | |
initial: 'idle', | |
context: {}, | |
states: { | |
idle: { | |
on: { | |
START: 'active', | |
} | |
}, | |
active: { | |
on: { | |
AMOUNT_CHANGED: { | |
src: "validateUserCanSendAmount", | |
onDone: "active", | |
onError: { | |
target: "active", | |
actions: "notifyValidateUserCanSendAmountFailed" | |
} | |
}, | |
CURRENCY_CHANGED: { | |
src: "validateUserCanSendAmount", | |
onDone: "active", | |
onError: { | |
target: "active", | |
actions: "notifyValidateUserCanSendAmountFailed" | |
} | |
}, | |
SORT_CODE_CHANGED: { | |
src: "validateBankDetails", | |
onDone: "active", | |
onError: { | |
target: "active", | |
actions: "notifyValidateBankDetailsFailed" | |
} | |
}, | |
ACCOUNT_NUMBER_CHANGED: { | |
src: "validateBankDetails", | |
onDone: "active", | |
onError: { | |
target: "active", | |
actions: "notifyValidateBankDetailsFailed" | |
} | |
}, | |
} | |
}, | |
valid: {}, | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment