Last active
April 22, 2020 15:44
-
-
Save headwinds/ce519bd3f6d8ade247cb1b95ea3fba48 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 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