Skip to content

Instantly share code, notes, and snippets.

@FFKL
Last active April 4, 2021 21:32
Show Gist options
  • Save FFKL/aeb4582ee8db534b6b23ad5dc93e9450 to your computer and use it in GitHub Desktop.
Save FFKL/aeb4582ee8db534b6b23ad5dc93e9450 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const inputMachine = Machine(
{
id: 'input',
initial: 'pristine',
context: {
message: '',
},
states: {
pristine: {},
editing: {},
validating: {
on: {
RESOLVE: 'valid',
REJECT: 'invalid.pending',
}
},
valid: {},
invalid: {
initial: 'empty',
states: {
empty: {},
pending: {},
}
}
},
on: {
SET_MESSAGE: {
target: 'editing',
actions: assign((_, { msg }) => ({ message: msg}))
},
LEAVE: [
{
target: 'invalid.empty',
cond: ctx => ctx.message.length === 0
},
{
target: 'validating'
}
]
}
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment