Last active
April 4, 2021 21:32
-
-
Save FFKL/aeb4582ee8db534b6b23ad5dc93e9450 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 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