Last active
May 5, 2021 17:32
-
-
Save wlee221/9e18e5c3e8388620e67ebda52fa8be39 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: "signIn", | |
initial: "edit", | |
states: { | |
edit: { | |
type: "parallel", | |
states: { | |
inputError: { | |
initial: "none", | |
states: { none: {}, error: {} } | |
}, | |
submitError: { | |
initial: "none", | |
states: { none: {}, error: {} } | |
} | |
}, | |
on: { | |
SUBMIT: "validate", | |
INPUT: { | |
actions: "onInput" | |
}, | |
ERROR: [ | |
{ | |
target: ".inputError.error", | |
actions: "setInputError", | |
cond: "hasInputError" | |
}, | |
{ | |
target: ".inputError.none" | |
} | |
], | |
} | |
}, | |
validate: { | |
on: { | |
SIGN_IN: "signIn", | |
ERROR: { | |
target: "edit.submitError.error", | |
actions: "setValidationError" | |
} | |
} | |
}, | |
signIn: { | |
invoke: { | |
src: "signIn", | |
onDone: { | |
actions: "setUser", | |
target: "resolved" | |
}, | |
onError: { | |
target: "edit.submitError.error", | |
actions: assign({ | |
error: (_, event) => { | |
const message = event.data?.message || event.data; | |
return { cross_field: [message] }; | |
} | |
}) | |
} | |
} | |
}, | |
resolved: { | |
type: "final" | |
} | |
}, | |
}, { | |
guards: { | |
hasInputError: (context, event) => { | |
return Math.random() < 0.5; | |
} | |
}}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment