Created
October 30, 2019 04:07
-
-
Save parties/e5e13490c500712362e61a76b420fb60 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 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