Last active
December 28, 2020 10:11
-
-
Save samihult/d06a24f7c931a7eec934080e73ef6093 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
| const machine = Machine({ | |
| id: 'field', | |
| context: { | |
| value: '', | |
| output: '' | |
| }, | |
| type: 'parallel', | |
| states: { | |
| value: { | |
| initial: 'empty', | |
| states: { | |
| empty: { | |
| on: { | |
| change: { | |
| target: 'not empty', | |
| cond: 'value is not empty' | |
| } | |
| } | |
| }, | |
| 'not empty': { | |
| on: { | |
| change: { | |
| target: 'empty', | |
| cond: 'value is empty' | |
| } | |
| } | |
| } | |
| } | |
| }, | |
| phase: { | |
| initial: 'untouched', | |
| states: { | |
| untouched: { | |
| on: { | |
| change: { | |
| target: 'dirty', | |
| actions: assign({ | |
| value: (context, event) => | |
| event.value | |
| }) | |
| } | |
| } | |
| }, | |
| dirty: { | |
| initial: 'debouncing', | |
| states: { | |
| debouncing: { | |
| after: { | |
| 500: 'validating' | |
| } | |
| }, | |
| validating: { | |
| entry: 'start validation', | |
| on: { | |
| invalid: { | |
| target: 'invalid', | |
| actions: assign({ | |
| output: '' | |
| }) | |
| }, | |
| valid: { | |
| target: 'valid', | |
| actions: assign({ | |
| output: (context, event) => | |
| event.value | |
| }) | |
| } | |
| } | |
| }, | |
| invalid: {}, | |
| valid: {} | |
| }, | |
| on: { | |
| unfocus: { | |
| target: '.validating', | |
| internal: true, | |
| actions: 'cancel validation' | |
| }, | |
| change: { | |
| target: '.debouncing', | |
| internal: false, | |
| actions: [ | |
| assign({ | |
| value: (context, event) => | |
| event.value | |
| }), | |
| 'cancel validation' | |
| ] | |
| } | |
| } | |
| } | |
| } | |
| } | |
| } | |
| }, { | |
| guards: { | |
| 'value is empty': (context, event) => | |
| context.value === '', | |
| 'value is not empty': (context, event) => | |
| context.value !== '' | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment