Skip to content

Instantly share code, notes, and snippets.

@leosuncin
Last active February 4, 2020 03:40
Show Gist options
  • Save leosuncin/2d2c6d317f946c64882bd5fc8871c1fe to your computer and use it in GitHub Desktop.
Save leosuncin/2d2c6d317f946c64882bd5fc8871c1fe to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
// - XState (all XState exports)
const fetchMachine = Machine({
id: 'input-number',
initial: 'idle',
context: {
selectedNumber: -1,
enteredValue: '',
},
states: {
idle: {
initial: 'empty',
states: {
empty: {},
invalid: {},
valid: {},
},
on: {
CHANGE_ENTERED_VALUE: [
{
actions: assign((context, event) => ({
enteredValue: event.text,
})),
},
{
target: '.empty',
cond(context) {
return !context.enteredValue;
},
},
{
target: '.invalid',
cond(context) {
return !/\d+/.test(context.enteredValue);
},
},
'.valid',
],
},
},
confirm: {
initial: 'ask',
states: {
ask: {},
revert: {},
confirm: {},
},
},
done: {},
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment