Skip to content

Instantly share code, notes, and snippets.

@headwinds
Last active April 22, 2020 15:44
Show Gist options
  • Save headwinds/ce519bd3f6d8ade247cb1b95ea3fba48 to your computer and use it in GitHub Desktop.
Save headwinds/ce519bd3f6d8ade247cb1b95ea3fba48 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 validate = (produceFn) => {};
const updateInputValue = (produceFn) => {};
const fetchMachine = Machine({
id: 'TextInputLabel',
initial: 'empty',
context: {
isValid: true,
inputValue: '',
},
states: {
empty: { on: { FOCUS: 'editing' } },
editing: {
onEntry: assign({ prevInputValue: context => context.inputValue }),
on: {
CHANGE: {
actions: assign({
inputValue: (context, e) => e.value,
}),
},
BLUR: {
target: 'validating',
actions: updateInputValue(action => ({
type: 'UPDATE_INPUT_VALUE',
action,
})),
},
},
},
validating: {
onEntry: assign({ prevInputValue: context => context.inputValue }),
on: {
CHANGE: {
actions: assign({
inputValue: (context, e) => e.value,
}),
},
BLUR: {
target: 'validation_result',
actions: validate(action => ({ type: 'UPDATE_VALUE', action })),
},
},
},
validation_result: {
on: {
VALID: 'valid',
INVALID: 'invalid',
},
},
valid: {
on: {
RETRY: {
target: 'editing',
},
},
},
invalid: {
on: {
RETRY: {
target: 'editing',
},
},
},
default: {
on: {
RETRY: {
target: 'editing',
},
},
},
success: {
on: {
RETRY: {
target: 'editing',
},
},
},
error: {
on: {
RETRY: {
target: 'editing',
},
},
},
warning: {
on: {
RETRY: {
target: 'editing',
},
},
},
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment