Skip to content

Instantly share code, notes, and snippets.

@parties
Created October 30, 2019 04:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parties/e5e13490c500712362e61a76b420fb60 to your computer and use it in GitHub Desktop.
Save parties/e5e13490c500712362e61a76b420fb60 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
// - XState (all XState exports)
const formMachine = Machine({
id: 'form',
initial: 'idle',
context: {
input: "",
type: "mobile",
error: "",
retries: 0,
},
states: {
idle: {
on: {
SUBMIT: [
{
target: "loading",
actions: "saveContext",
cond: (context, event) => event.data !== null,
},
{
target: "failure"
}
]
}
},
loading: {
invoke: {
id: "searchForCustomer",
src: "searchForCustomer",
onDone: {
target: "success",
},
onError: {
target: "failure",
}
}
},
success: {
type: 'final'
},
failure: {
on: {
RETRY: {
target: 'loading',
cond: (context, event) => event.data !== null,
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