Skip to content

Instantly share code, notes, and snippets.

@farskid
Created November 2, 2019 08:48
Show Gist options
  • Select an option

  • Save farskid/050ab4d12f5df996a3f278b9a9ca6acb to your computer and use it in GitHub Desktop.

Select an option

Save farskid/050ab4d12f5df996a3f278b9a9ca6acb to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz, single input model
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