Created
November 2, 2019 08:48
-
-
Save farskid/050ab4d12f5df996a3f278b9a9ca6acb to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz, single input model
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
| Machine({ | |
| initial: "ready", | |
| context: { | |
| value: "" | |
| }, | |
| states: { | |
| updating: { | |
| entry: "updateInputValue", | |
| on: { | |
| '': [ | |
| { target: "ready.valid", cond: "isInputValid" }, | |
| { target: "ready.invalid" } | |
| ] | |
| } | |
| }, | |
| ready: { | |
| initial: "empty", | |
| on: { | |
| TYPE: "updating" | |
| }, | |
| states: { | |
| empty: {}, | |
| valid: {}, | |
| invalid: {} | |
| } | |
| } | |
| } | |
| }, { | |
| guards: { | |
| isInputValid: ctx => ctx.value.length > 0 && validateEmail(ctx.value.length) | |
| }, | |
| actions: { | |
| updateInputValue: assign({ | |
| value: (_, e) => e.data | |
| }) | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment